輸入:
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 raise e.ag_error_metadata.to_exception(e) 1130 else: 1131 raise
ValueError: in user code:
如果有任何混淆,我已盡力解釋我的問題,然后我道歉,讓我知道,我會添加它。
uj5u.com熱心網友回復:
正如錯誤所述,雖然您的模型輸出每個樣本超過 10 個類別的預測,但您以某種不兼容的方式傳遞了“真實標簽”,為什么您的標簽是三維的?每個樣本有一個 11x2x2 張量,而不是一個單熱編碼的類號。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/375428.html
