我收到一个错误:“检查目标时出错:预期density_2具有2个维,但是数组的形状为(32,256,455,3)”。输入数据是具有三个通道的40,000个RGB图像(256像素x 455像素)。每批中有32张图像。输出是方向盘的角度,因此不是类别。如何解决此错误?
enter code here
datagen = ImageDataGenerator(rescale=1./255,validation_split=0.2)
train_generator = datagen.flow_from_dataframe(dataframe=data,
class_mode =
"input",directory="../input/driving_dataset/driving_dataset/",
x_col="files", y_col="results", batch_size=32,color_mode =
'rgb',target_size = (256,455),subset = 'training')
validation_generator = datagen.flow_from_dataframe(dataframe=data,
class_mode =
"input",directory="../input/driving_dataset/driving_dataset/",
x_col="files", y_col="results", batch_size=32,color_mode =
'rgb',target_size = (256,455),subset = 'validation')
model = Sequential()
model.add(Conv2D(24,(5,5),padding ="valid",input_shape = (256,455,3),
activation = 'relu'))
model.add(Conv2D(36,(5,5),padding = "valid", activation = "relu"))
model.add(Conv2D(48,(5,5),padding = "valid", activation = "relu"))
model.add(Flatten())
model.add(Dense(1164, activation = "relu"))
model.add(Dense(100, activation = "relu"))
model.add(Dense(10, activation = "relu")
model.add(Dense(1))
model.compile(optimizer = "Adam", loss="mse")
model.fit_generator(
train_generator,
steps_per_epoch = train_generator.samples // 32,
validation_data = validation_generator,
validation_steps = validation_generator.samples // 32,
epochs = 2)
答案 0 :(得分:1)
问题是您正在设置class_mode="input"
,这意味着生成器也将输入图像用作标签。您应该设置class_mode="other"
,以便将y_col
中的值用作标签。