tensorflow – Why is the Accuracy Different in my PC From Kaggle When Using the Same Code

I am writing a watermark detection algorithm, and I’ve tried a code from Kaggle which fine-tunes a ResNet, but when I run the same code in Jupyter notebook, I get 50% accuracy when the sample code in Kaggle has around 97% accuracy. I don’t have a GPU installed on my PC, and I changed the batch size to 32. Do you know why I get 40% lower accuracy?

My Code:

import tensorflow as tf
import numpy as numpy
import os
from pathlib import Path
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import RMSprop
from PIL import Image

basedir = "/home/mahsa/Kaggle/archive/wm-nowm"

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

traindir = os.path.join(basedir,'train') # root for training
validdir = os.path.join(basedir,'valid') # root for testing

traingenerator = ImageDataGenerator(rescale=1./255)
validgenerator = ImageDataGenerator(rescale=1./255)

train_data = traingenerator.flow_from_directory(traindir,target_size=(150,150),batch_size=100,class_mode="binary")
valid_data = validgenerator.flow_from_directory(validdir,target_size=(150,150),batch_size=100,class_mode="binary")

existing = tf.keras.applications.InceptionResNetV2 (input_shape=(150, 150, 3),include_top=False, pooling='max', weights="imagenet")
#for layer in existing.layers:
#  layer.trainable = False
#existing.summary()
last = existing.get_layer("mixed_7a")
last_output = last.output

# Flatten the output layer to 1 dimension
x = tf.keras.layers.Flatten()(last_output)
x = tf.keras.layers.Dropout(0.25)(x) 
# Add a fully connected layer with 1,024 hidden units and ReLU activation
x = tf.keras.layers.Dense(128, activation='relu')(x)


x = tf.keras.layers.Dense(64, activation='relu')(x)
# Add a final sigmoid layer for classification
x = tf.keras.layers.Dense  (1, activation='sigmoid')(x)           

model = tf.keras.Model( existing.input, x) 

model.compile(optimizer=RMSprop(lr=0.001),
              loss="binary_crossentropy",
              metrics = ['accuracy'])

history = model.fit(train_data,
                          validation_data=valid_data,
                          steps_per_epoch=150,
                          epochs=60,
                          validation_steps=50,
                          verbose=2)

Read more here: Source link