我正在使用 Keras ImageDataGenerator来处理我的 CNN 的输入。我想要进行基本的预处理,将图像像素缩放到从 -1 到 1 的值,就像在 Mobilenet 架构的论文中所做的那样。
我的数据生成器只定义了预处理函数:
train_datagen = ImageDataGenerator(
preprocessing_function=preprocess_input
)
我的 preprocess_input 函数:
def preprocess_input(img):
pix = np.asarray(img)
pix = pix.astype(np.float32)
pix = pix / 255.0
pix = pix * 2
return pix
这给了我以下错误:
Traceback (most recent call last): File "finetune_mobilenet.py",
line 206, in <module>
train(folder_train, folder_dev, './models/') File "finetune_mobilenet.py", line 150, in train
callbacks=callbacks_list) File "/usr/local/lib/python2.7/dist-packages/keras/legacy/interfaces.py",
line 91, in wrapper
return func(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py",
line 2192, in fit_generator
generator_output = next(output_generator) File "/usr/local/lib/python2.7/dist-packages/keras/utils/data_utils.py",
line 584, in get
six.raise_from(StopIteration(e), e) File "/usr/local/lib/python2.7/dist-packages/six.py", line 737, in
raise_from
raise value StopIteration: 'tuple' object cannot be interpreted as an index
我还尝试了可用于 Keras 中 Mobilenet 架构的原始预处理功能,但该功能也失败了。你能告诉我需要改变什么来零中心我的图像数据吗?