Tensorflow - I don't get the right shapes - `ValueError: Shapes (100, 10, 10) and (100, 10) are incompatible`
I am working on the mnist classification code. Such errors continue to occur in the code 코드 below.
import tensorflow as tf
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
print(x_train.shape) # (60000, 28, 28)
print(y_train.shape)
import matplotlib.pyplot as plt
print(Y[0] : , y_train[0])
plt.imshow(x_train[0], cmap=plt.cm.gray_r, interpolation = nearest)
x_train = x_train.reshape(-1,28*28)
x_test = x_train / 255.0
x_test / 255.0
y_train = tf.keras.utils.to_categorical(y_train, 10)
y_test = tf.keras.utils.to_categorical(y_test, 10)
This is the error occurrence code.
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(units=10, input_dim=784, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer=tf.optimizers.Adam(learning_rate=0.001), metrics=['accuracy'])
model.summary()
model.fit(x_train, y_train, batch_size=100, epochs=10, validation_data=(x_test, y_test))
ValueError: Shapes (100, 10, 10) and (100, 10) are incompatible
This is my error message.
Initially, a reshape error occurred, so x_trial.reshape (-1,28*28) was added to the code. Then, this error occurs. How should I change the shape?
Topic mnist tensorflow
Category Data Science