我正在尝试使用Keras进行语义分割,当尝试加载图像时,我使用flow_from_directory
方法遇到了此错误。
Found 0 images belonging to 0 classes.
Found 0 images belonging to 0 classes.
这是我的代码。
from tensorflow.keras.applications.resnet50 import preprocess_input
from tensorflow.keras.preprocessing.image import ImageDataGenerator
data_generator = ImageDataGenerator()
train_generator = data_generator.flow_from_directory(
directory="../input/Training_dataset/Images",
target_size=(IMG_SIZE, IMG_SIZE),
batch_size=16,
class_mode=None,
classes=None
)
mask_generator = data_generator.flow_from_directory(
directory="../input/Training_dataset/Masks/all",
class_mode=None,
classes=None,
batch_size = 1,
)
我已经阅读了此问题,但解决方案无效Keras for semantic segmentation, flow_from_directory() error
答案 0 :(得分:1)
您需要将图像保留在一个子文件夹中,例如在图像和遮罩目录中创建一个名为“ img”的文件夹。
-- image
-- img
-- 1.jpg
-- 2.jpg
-- mask
-- img
-- 1.png
-- 2.png
Datagenerator应该类似于:-
seed = 909 # (IMPORTANT) to transform image and corresponding mask with same augmentation parameter.
image_datagen = ImageDataGenerator(width_shift_range=0.1,
height_shift_range=0.1,
preprocessing_function = image_preprocessing) # custom fuction for each image you can use resnet one too.
mask_datagen = ImageDataGenerator(width_shift_range=0.1,
height_shift_range=0.1,
preprocessing_function = mask_preprocessing) # to make mask as feedable formate (256,256,1)
image_generator =image_datagen.flow_from_directory("dataset/image/",
class_mode=None, seed=seed)
mask_generator = mask_datagen.flow_from_directory("dataset/mask/",
class_mode=None, seed=seed)
train_generator = zip(image_generator, mask_generator)
如果您想为语义分割模型创建自己的自定义数据生成器,以更好地控制数据集,则可以检查我的kaggle内核,其中我曾使用camvid数据集训练UNET模型。
https://www.kaggle.com/mukulkr/camvid-segmentation-using-unet
如果您需要更好的扩充功能,可以查看此很棒的GitHub存储库- https://github.com/mdbloice/Augmentor