【问题标题】:How to feed trained Python TensorFlow model with batches?如何批量输入训练有素的 Python TensorFlow 模型?
【发布时间】:2020-05-30 11:39:02
【问题描述】:

我创建了一个自己的模型,并使用来自 Keras 的 ImageTrainGenerator- 使用 flow_from_directory 对其进行了训练。

像这样:how to train model with batches。一切正常,我检查了生成的批次,图片就是它必须的样子。

我的问题是,我想在在线人脸检测中使用这个训练有素的模型。我以所需的宽度和高度裁剪面部,将其转换为数组,但预测结果很糟糕。

我认为实时流式传输的图像必须与 Imagetraingenerator 创建(批次)的图像相同。知道如何将cv2.imread(path) 图像转换成批处理来预测类别吗?

【问题讨论】:

    标签: python tensorflow batch-normalization


    【解决方案1】:

    您只需添加批次维度即可将其转换为具有 1 个样本的批次:np.expand_dims(img, axis=0)

    【讨论】:

    • 感谢您的帮助!它得到输入,但预测不好。知道我必须在哪里纠正吗? train_generator = train_datagen.flow_from_directory( FACES_DIR, batch_size=25, target_size=(224,224), color_mode='rgb', shuffle=True, class_mode='categorical' ) 精度为 0.98 loss: 0.2 valid_acc: 0.8 valid_loss: 0.4
    猜你喜欢
    • 1970-01-01
    • 2019-04-02
    • 1970-01-01
    • 2016-11-01
    • 2017-12-05
    • 1970-01-01
    • 2018-09-27
    • 2018-02-08
    • 2018-02-27
    相关资源
    最近更新 更多