【问题标题】:Error when checking input with keras model使用 keras 模型检查输入时出错
【发布时间】:2019-03-04 12:55:12
【问题描述】:

我是训练模型,将模型保存在磁盘上,使用模型时出错。

Error when checking input: expected conv2d_input to have 4 dimensions, but got array with shape (150, 150, 3)

火车模型:

model = Sequential()

model.add(Conv2D(32, (3, 3), input_shape=(150, 150, 3))

使用模型:

model = load_model(os.path.join('models', 'myModel.h5'))
model.predict(img) # img - OpenCV image

【问题讨论】:

    标签: keras model python-3.6


    【解决方案1】:

    使用这个:

    import numpy as np
    model.predict(img[np.newaxis, :, :, :])
    

    【讨论】:

      猜你喜欢
      • 2020-02-29
      • 2020-09-09
      • 1970-01-01
      • 2019-06-16
      • 1970-01-01
      • 1970-01-01
      • 2017-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多