我正在尝试通过在 Keras 中采用经过训练的 YOLOv2 模型、删除最后一层并用新数据重新训练它来实现自定义对象检测。不过,我对如何将数据提供给 Keras 感到困惑。我使用 YOLO 注释用边界框注释了一堆图片,并将它们放在两个单独的文件夹中(images.jpgs 所在的位置和annots.txt 注释所在的位置)。
我还从模型中删除了最后一层并添加了一个自定义层(我正在尝试预测 2 个类的边界框)。
我正在尝试使用 ImageDataGenerator 传递我的数据,因为我的数据集非常小。
我有以下输入对象:
np.shape(train_images) # this contains RGB data from 79 pictures
(79, 1, 608, 608, 3)
np.shape(train_y)
(79,)
我正在尝试将这些传递给 ImageDataGenerator,但出现错误:
train_datagen = ImageDataGenerator(
rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True,
fill_mode='nearest')
train_generator = train_datagen.flow(
train_images,
train_y)
ValueError: `x` (images tensor) and `y` (labels) should have the same length. Found: x.shape = (1, 608, 608, 3), y.shape = (79,)
我不明白问题是什么。不知何故,我的图像数据的第一维完全消失了,因此不匹配......它有什么问题?