【问题标题】:Keras open images and create a batch with themKeras 打开图像并使用它们创建批处理
【发布时间】:2018-07-06 19:19:03
【问题描述】:

我有以下从 SO 读取图像的功能:

from keras.preprocessing import image as kimage
from keras.applications.vgg16 import preprocess_input

def read_image(path):
    img = kimage.load_img(path, target_size=(224, 224))
    tmp = kimage.img_to_array(img)
    tmp = np.expand_dims(tmp, axis=0)
    tmp = preprocess_input(tmp)
    return tmp

然后我创建了以下数据生成器,它基本上迭代我的路径字符串并调用前面的函数。我想调用读取图像函数并将其输出堆叠到一个可以输入到 keras fit 函数的 numpy 数组中。我正在使用此代码:

batch_holder = np.zeros((batch_size, 224, 244, 3))
for j, row in batch.iterrows():
    batch_holder[j, :] = read_image(row['path'])[0]

但这不起作用,我收到以下我认为无法解释的错误:

文件“train.py”,第 71 行,在 data_generator 中 batch_holder[j, :] = read_image(row['path'])[0] ValueError: could not broadcast input array from shape (224,224,3) into shape (224,244,3)

我做错了什么?

【问题讨论】:

  • 它是一个 keras 模块,我编辑了我的问题以添加它
  • 能否发一个完整的例子,包括 preprocess_input 等。
  • 对不起,这是另一个 keras 函数我忘了添加导入

标签: python numpy keras


【解决方案1】:

你是不是写错了 244 而不是 224?

batch_holder = np.zeros((batch_size, 224, 244, 3))

【讨论】:

  • 很容易看到......在这里花了很多时间!好收获!
猜你喜欢
  • 2016-04-08
  • 1970-01-01
  • 2022-08-16
  • 2013-09-01
  • 1970-01-01
  • 2019-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多