首页 > 解决方案 > ImageDataGenerator 没有将实际输出保存到磁盘

问题描述

我有一组结构如下的图像训练:

path = /aug-dir/img_dir
             1.jpg
             2.jpg
             ...jpg

我正在尝试扩充图像并将它们保存到磁盘以供将来使用。我想实现以下代码:

## I want to do only mobilenet.preprocess_input and no other data augmentation

datagen = ImageDataGenerator(preprocessing_function=tensorflow.keras.applications.mobilenet.preprocess_input)
aug_datagen_test = datagen.flow_from_directory(path,
                                               save_to_dir=save_path, ### want to save the images to save_path
                                               save_format='jpg',
                                               target_size=(image_size,image_size),
                                               batch_size=1, 
                                               shuffle = False)

当我生成图像时,preprocessing_function(即mobilenet.preprocess_input)被正确应用并且我得到了正确的结果。

for i in range(11):
     imgs, labels = next(aug_datagen_test)

plt.figure(figsize=(10,5))
plt.subplot(1,2,1)
plt.imshow(orginal_image)
plt.title('Original_image')

plt.subplot(1,2,2)
plt.imshow(imgs[0])
plt.title('output from ImageDataGenerator')
plt.show()

原始图像和数据生成器图像的图

但是“ImageDataGenerator 的输出”(实际输出)图像未保存在 save_path 中。这就是数据增强后图像在 save_path 中的保存方式。

来自 save_path 的图像

难道我做错了什么?为什么正确的输出没有保存到磁盘?

如果需要任何进一步的细节,请告诉我。

注意:我从 datagen.flow 得到相同的输出,即图像未正确保存。

任何帮助或建议表示赞赏。

非常感谢

标签: pythontensorflow2.0data-augmentationimage-preprocessing

解决方案


推荐阅读