Input:
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
Neural Network :-
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'])
Error:-
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:
I tried my best to explain my problem if there is any confusion then my apologies, let me know and I will add it.
CodePudding user response:
As the error states, while your model outputs prediction over 10 classes per sample, you passed "true labels" in some non-compatible way, why are your labels three dimensional? You have a 11x2x2 tensor per sample, instead of a one-hot encoded class number.