0
$\begingroup$

I am working on image classification with 400 class , during training , I am getting good training and validation accuracy , but test accuracy is approximate 0-1% .My input image is 1 scale , with size 100*100 , Here is my train and validation data generator:

batch_size = 32
#img_size = numpydata.shape
img_size = (numpydata.shape[0],numpydata.shape[1])
channels = 3
img_shape = (img_size[0], img_size[1], channels)

tr_gen = ImageDataGenerator()

train_gen = tr_gen.flow_from_dataframe( train_df, x_col= 'Name', y_col= 'Class', target_size= img_size, class_mode= 'categorical',
                                    color_mode='grayscale', shuffle= True, batch_size= batch_size,split="training")
valid_gen = tr_gen.flow_from_dataframe( train_df, x_col= 'Name', y_col= 'Class', target_size= img_size, class_mode= 'categorical',
                                    color_mode= 'grayscale', shuffle= True, batch_size= batch_size,split="validation")

Here is my model train code:

base_model = tf.keras.applications.efficientnet.EfficientNetB0(include_top= False, weights= "imagenet", input_shape= img_shape, pooling= 'max')
base_model.summary()
# base_model.trainable = False
model = Sequential([
    base_model,
    BatchNormalization(axis= -1, momentum= 0.99, epsilon= 0.001),
    Dense(256, kernel_regularizer= regularizers.l2(l= 0.016), activity_regularizer= regularizers.l1(0.006),
                bias_regularizer= regularizers.l1(0.006), activation= 'relu'),
    Dropout(rate= 0.3, seed= 126),
    Dense(class_count, activation= 'softmax')
])

model.compile(Adamax(learning_rate= 0.001), loss= 'categorical_crossentropy', metrics= ['accuracy'])

model.summary()

enter image description here

enter image description here

$\endgroup$
2
  • $\begingroup$ This could be just a version difference thing but the parameter "split" you are using to declare train and valiadtion datasets is not present in tf documentation (tensorflow.org/api_docs/python/tf/keras/preprocessing/image/…). It seems to use the "subset" parameter instead. $\endgroup$ Nov 8, 2023 at 14:27
  • $\begingroup$ Even after using subset , getting same behaviour $\endgroup$
    – NeelPatwa
    Nov 16, 2023 at 8:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.