我正在使用Keras ImageDataGenerator 来处理CNN的输入。我希望进行基本的预处理,将图像像素从-1扩展到1,就像在Mobilenet架构中所做的那样。
我的datagenerator只定义预处理功能:
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架构的原始预处理功能,但也失败了。你能告诉我需要将我的图像数据改为零中心吗?