Getting 99.7% accuracy on google colab but only 4% on my PC using same code

Question:

I am trying to train a CNN model to recognize 28 different classes.
Here’s my model:

model = Sequential()
    model.add(Conv2D(16, (2,2), input_shape=(image_x, image_y, 1), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2), padding='same'))
    model.add(Conv2D(32, (5,5), activation='relu'))
    model.add(MaxPooling2D(pool_size=(5, 5), strides=(5, 5), padding='same'))
    model.add(Conv2D(64, (5,5), activation='relu'))
    model.add(MaxPooling2D(pool_size=(5, 5), strides=(5, 5), padding='same'))
    model.add(Flatten())
    model.add(Dense(128, activation='relu'))
    model.add(Dropout(0.2))
    model.add(Dense(num_of_classes, activation='softmax'))
    sgd = optimizers.SGD(lr=1e-2)
    model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])

And here’s epoch and everything else:

model, callbacks_list = cnn_model()
    model.summary()
    model.fit(train_images, train_labels, validation_data=(test_images, test_labels), epochs=20, batch_size=500, callbacks=callbacks_list)
    scores = model.evaluate(test_images, test_labels, verbose=0)

The problem is when I train this model on my PC, I get accuracy of 3-5% approx. However, When trained on google colab, I get 99.57% accuracy.

My PC packages and stuff:

python 3.6.8
tensorflow 1.13.1
keras 2.2.4

All I did was upload everything on google colab and test for a surprising result.

Asked By: Divy

||

Answers:

I have found the root cause.

It was due to a version difference between the environments.
The local Keras version had a strange bug tracked by this issue – https://github.com/keras-team/keras/issues/11376, which wasn’t present in the version of Keras present in Google Colab.

Answered By: Divy