#my model
model=Sequential([
Conv2D(input_shape=(200,360,3),kernel_size=(3,3),filters=64,padding='same'),
MaxPool2D(pool_size=(2,2)),
Dropout(rate=0.5),
Conv2D(kernel_size=(3,3),filters=128,padding='same',activation='relu'),
Conv2D(kernel_size=(3,3),filters=256,padding='valid',activation='relu'),
MaxPool2D(pool_size=(2,2)),
Dropout(rate=0.5),
Flatten(),
Dense(units=512,activation='relu'),
Dropout(rate=0.5),
Dense(units=256,activation='relu'),
Dropout(rate=0.5),
Dense(units=14,activation='softmax')
])
model.add(tf.keras.layers.Reshape((-1,)))
model.compile(optimizer=tf.keras.optimizers.Adam(),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
#fit function
model.fit(x_train,y_train,epochs=5)
#Error
InvalidArgumentError: logits and labels must have the same first dimension, got logits shape [1,14] and labels shape [14]
[[node sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits (defined at <ipython-input-11-0743e46bb17f>:1) ]] [Op:__inference_train_function_1933]
Function call stack:
train_function
输入图像形状为(400,720,3)
。它重塑为(200,360,3)
我将训练数据集放入模型中,编译器说一维的logit和标签形状不相同(logits形状为[1,14]
,label形状为[14]
)。
这些参数是内部变量,所以我无法更改
所以我添加了模型以重塑图层
(model.add(tf.keras.layer.Reshape((-1))))
但这不起作用。
如果您对我的计划有任何疑问,我会向您提供任何信息