报错为:Found 0 images belonging to 0 classes.
这个问题是由于文件夹路径设置错了,比如热狗数据集,数据集路径分别为:
hotdog\train\hotdog
hotdog\train\no-hotdog
hotdog\test\hotdog
hotdog\test\no-hotdog
import pathlib
import tensorflow as tf
file = r'F:\hotdog'
# 获取数据集
train_dir = file + r'\train'
test_dir = file + r'\test'
# 获取训练集数据
train_dir = pathlib.Path(train_dir)
train_count = len(list(train_dir.glob('*/*.png'))) # .glob查找文件个数
# 获取测试集数据
test_dir = pathlib.Path(test_dir)
test_count = len(list(test_dir.glob('*/*.png')))
train_data_gen = image_generator.flow_from_directory(directory=str(train_dir),
batch_size=BATCH_SIZE,
target_size=(IMG_HEIGHT, IMG_WIDTH),
shuffle=True)
要注意文件的路径只到train和test才对,如上代码所示
里面包含两个文件夹,分别对应为两个类,hotdog和no-hotdog
keras根据hotdog和no-hotdog这两个文件夹识别为两个类