ValueError: `logits` and `labels` must have the same shape, received ((None, 10) vs (None, 11, 2, 2))
ValueError: `logits` and `labels` must have the same shape, received ((None, 10) vs (None, 11, 2, 2))
输入:
x_train shape: (6000, 16, 16, 1)
x_test shape: (5000, 16, 16, 1)
y_test shape: (5000, 11, 2)
y_test shape: (5000, 16, 16, 1)
6000 train samples
5000 test samples
神经网络:-
batch_size = 128
num_classes = 10
epochs = 10
model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3),activation='relu',input_shape=input_shape))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes, activation='softmax'))
model.compile(loss='categorical_crossentropy',
optimizer=tf.keras.optimizers.Adadelta(),metrics=['accuracy'])
错误:-
Epoch 1/10
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-47-628ddb8c3023> in <module>()
----> 1 hist = model.fit(x_train,
y_train,batch_size=batch_size,epochs=epochs,verbose=1,validation_data=(x_test,
y_test))
2 print("The model has successfully trained")
3 model.save('mnist.h5')
4 print("Saving the model as mnist.h5")
1 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py
in autograph_handler(*args, **kwargs)
1127 except Exception as e: # pylint:disable=broad-except
1128 if hasattr(e, "ag_error_metadata"):
-> 1129 提高 e.ag_error_metadata.to_exception(e)
1130 其他:
1131 提高
ValueError: in user code:
我尽力解释我的问题,如果有任何混淆,那么我的
抱歉,让我知道,我会添加它。
如错误所述,虽然您的模型每个样本输出超过 10 classes 的预测,但您以某种不兼容的方式传递了“真实标签”,为什么您的标签是三维的?每个样本有一个 11x2x2 张量,而不是单热编码的 class 数字。
输入:
x_train shape: (6000, 16, 16, 1)
x_test shape: (5000, 16, 16, 1)
y_test shape: (5000, 11, 2)
y_test shape: (5000, 16, 16, 1)
6000 train samples
5000 test samples
神经网络:-
batch_size = 128
num_classes = 10
epochs = 10
model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3),activation='relu',input_shape=input_shape))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes, activation='softmax'))
model.compile(loss='categorical_crossentropy',
optimizer=tf.keras.optimizers.Adadelta(),metrics=['accuracy'])
错误:-
Epoch 1/10
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-47-628ddb8c3023> in <module>()
----> 1 hist = model.fit(x_train,
y_train,batch_size=batch_size,epochs=epochs,verbose=1,validation_data=(x_test,
y_test))
2 print("The model has successfully trained")
3 model.save('mnist.h5')
4 print("Saving the model as mnist.h5")
1 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py
in autograph_handler(*args, **kwargs)
1127 except Exception as e: # pylint:disable=broad-except
1128 if hasattr(e, "ag_error_metadata"):
-> 1129 提高 e.ag_error_metadata.to_exception(e) 1130 其他: 1131 提高
ValueError: in user code:
我尽力解释我的问题,如果有任何混淆,那么我的 抱歉,让我知道,我会添加它。
如错误所述,虽然您的模型每个样本输出超过 10 classes 的预测,但您以某种不兼容的方式传递了“真实标签”,为什么您的标签是三维的?每个样本有一个 11x2x2 张量,而不是单热编码的 class 数字。