Image Classification 100 percent training and validation problem

I’m training images for classification but training and validation accuracy is always 100 percent.
I’ve used pretrained models, Custom models also techniques like data augmentation, resizing scaling.
But every time results same.
At testing model predicting same class for all new images.

1 Like

@Noman_Ahmad,

Welcome to the Tensorflow Team!

I’ve used pretrained models, Custom models also techniques like data augmentation, resizing scaling.

Can you elaborate a bit more on your model architecture and data set? Please share the standalone code to troubleshoot the problem reported above.

2 Likes

I’ve used tflite-model-maker with efficient-lite also with mobilenet, custom models also transfer learning on a person classification.
Problem I want to solve is attendance system through image classification. I’ve dataset of 100 images of each person.

1 Like

How is the data is split into training and validation? What is the cardinality of the dataset in training and validation? also, i would like to confirm that validation data has not been exposed to the model during training?

2 Likes

Can you please answer the above queries? and if possible please share colab gist to debug issue.

2 Likes

You could check the train_model() function in my colab sheet

1 Like

training & validation data split was variable like 80/20-70/30 also cardinality was also variable I was testing different scenarios. For the question “i would like to confirm that validation data has not been exposed to the model” you could check my sheet

1 Like

Usually model will be trained with both negative and positive classes. But from your code i observed only positive sample.

e.g: If the task is to identify x person then x will be the positive sample and every other sample will be labelled as a negative sample. Thank you!

2 Likes

I also trained with multiple classes but for every testing class, it gives the same output like the 386 user class for every test class

1 Like

Can you try to increase the sample count for every class and let us know?

2 Likes

Like an increase in the number of images?

1 Like

Like an increase in the number of images?

Yes.

1 Like

Ok let me try that. and thanks for the help

1 Like

By the way how much data i should increase? At this time I have about 105 images per class

One more thing if I train the model with multiple classes it predicts very well for the test accuracy.
but when I introduce new data like some new images of the same person it predicts wrong
or when I introduces new images like shoe or tree it predict that with present no of classes.
I don’t know what could be the problem

1 Like

By the way how much data i should increase?

There is no hard and fast rule. Usually more the data, better the results for generalization.

2 Likes

if I train the model with multiple classes it predicts very well for the test accuracy.

Since the model is trained on different classes, it is able to classify test images well

when I introduce new data like some new images of the same person it predicts wrong

We should make sure to feed all types of images of a person during training

when I introduces new images like shoe or tree it predict that with present no of classes

Yes, this is due to the classification labels given during the training.

1 Like

I increased the dataset to 450 images per class but didn’t make any changes.
Actually, I want to make a facial attendance system of a person through images.
Should I change my problem from image classification to object detection?

Yes, this is due to the classification labels given during the training.
But I didn’t introduce labels for trees or shoes but it’s giving a class of a person against them.

From your colab gist, you are training the model using one class(i.e 386). In that case the model learns only images belong to that class, which constitutes class imbalance (i.e that is why 100% training and validation). Please refer screenshot below

For the model to learn better we need to train using images from all the classes.

To debug your issue, we required following details

  1. How are you labeling?
  2. How many classes?
  3. Folder structure of user_training
  4. How is the data used for training?
1 Like
  1. I’m not labeling, I’m following directory hierarchy as per documentation. It assigns a folder name as the image’s label like the 386 folder name for all images inside the 386 folder.
  • data = DataLoader.from_folder("/content/usertraining")
  1. I’m using 2 classes with exactly 100 images.

  2. I’m following this pattern from docs. Under user training all user folders
    user_training
    44
    55

  3. I’ve used 80/10/10 for training.