【发布时间】:2020-05-29 07:30:57
【问题描述】:
错误:
return K.categorical_crossentropy(y_true, y_pred, from_logits=from_logits)
C:\Users\selvaa\miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\backend.py:4619 categorical_crossentropy
target.shape.assert_is_compatible_with(output.shape)
C:\Users\selvaa\miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\tensor_shape.py:1128 assert_is_compatible_with
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (None, 1) and (None, 151) are incompatible
我的模特:
x = np.array(x)
y = np.array(y)
x = x/255.0
model = Sequential()
model.add(Conv2D(3, (3,3), input_shape=(128,128,3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Flatten())
model.add(Dense(302, activation='relu'))
model.add(Dense(151, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(x, y, batch_size=32, epochs=5, verbose=1, validation_split=0.1)
我正在尝试训练一个模型来识别不同的口袋妖怪,我的数据集有两张图片,每个 151 个口袋妖怪(正确标记和所有)。不知道我做错了什么。
当我打印 x.shape 和 y.shape 时会发生以下情况:
(301, 128, 128, 3) (301,)
【问题讨论】:
标签: python tensorflow keras