问题
I am running the CNN example from Tensorflow Official website - (https://www.tensorflow.org/tutorials/images/cnn) I have run the notebook as it is without any modifications whatsoever.
My accuracy (training accuracy) is stuck at 10%. I tried to overfit by only using the first 10 (image, label) pairs, but the result is still the same. The network just does not learn.
Here is my model.summary() -
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d (Conv2D) (None, 30, 30, 32) 896
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 15, 15, 32) 0
_________________________________________________________________
conv2d_1 (Conv2D) (None, 13, 13, 64) 18496
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 6, 6, 64) 0
_________________________________________________________________
conv2d_2 (Conv2D) (None, 4, 4, 64) 36928
_________________________________________________________________
flatten (Flatten) (None, 1024) 0
_________________________________________________________________
dense (Dense) (None, 64) 65600
_________________________________________________________________
dense_1 (Dense) (None, 10) 650
=================================================================
Total params: 122,570
Trainable params: 122,570
Non-trainable params: 0
Here is my compile and fit code:-
model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
history = model.fit(train_images, train_labels, epochs=10,
validation_data=(test_images, test_labels))
The model training logs:-
Epoch 1/10
1563/1563 [==============================] - 14s 9ms/step - loss: 2.3072 - accuracy: 0.0993 - val_loss: 2.3026 - val_accuracy: 0.0994
Epoch 2/10
1563/1563 [==============================] - 3s 2ms/step - loss: 2.3028 - accuracy: 0.0996 - val_loss: 2.3047 - val_accuracy: 0.1001
Epoch 3/10
1563/1563 [==============================] - 3s 2ms/step - loss: 2.3029 - accuracy: 0.0998 - val_loss: 2.3027 - val_accuracy: 0.1000
Epoch 4/10
1563/1563 [==============================] - 3s 2ms/step - loss: 2.3038 - accuracy: 0.0986 - val_loss: 2.3054 - val_accuracy: 0.1007
Epoch 5/10
1563/1563 [==============================] - 3s 2ms/step - loss: 2.3031 - accuracy: 0.0988 - val_loss: 2.3026 - val_accuracy: 0.0999
Epoch 6/10
1563/1563 [==============================] - 3s 2ms/step - loss: 2.3031 - accuracy: 0.0985 - val_loss: 2.3159 - val_accuracy: 0.0999
Epoch 7/10
1563/1563 [==============================] - 3s 2ms/step - loss: 2.3221 - accuracy: 0.0995 - val_loss: 2.9215 - val_accuracy: 0.1003
Epoch 8/10
1563/1563 [==============================] - 3s 2ms/step - loss: 2.3035 - accuracy: 0.0973 - val_loss: 2.3270 - val_accuracy: 0.1001
Epoch 9/10
1563/1563 [==============================] - 3s 2ms/step - loss: 2.3028 - accuracy: 0.0999 - val_loss: 2.3399 - val_accuracy: 0.0984
Epoch 10/10
1563/1563 [==============================] - 3s 2ms/step - loss: 2.3054 - accuracy: 0.1001 - val_loss: 2.3116 - val_accuracy: 0.1002
I have checked the plotted data and it is not random. The labels are correct and there is no issue with the data that I can see.
I am running this code on Tensorflow 2.2 on an Nvidia RTX 3060 Ti
__CUDA Information__
CUDA Device Initialized : True
CUDA Driver Version : 11010
CUDA Detect Output:
Found 1 CUDA devices
cudnn 7.6.5 cuda10.1_0
Please help.
来源:https://stackoverflow.com/questions/65475010/why-is-tensorflow-official-cnn-example-stuck-at-10-percent-accuracy-random-pr