OlafenwaMoses / ImageAI

A python library built to empower developers to build applications and systems with self-contained Computer Vision capabilities
https://www.genxr.co/#products
MIT License
8.57k stars 2.19k forks source link

Issue with Number of Image Classes Counted vs Number Actually Present #551

Open cnmks opened 4 years ago

cnmks commented 4 years ago

Hello

I am new to coding and I ran into some problems when using Image AI to help run an Image Detection Project on Google Colab.

I have 6 different image sets in folders labeled 00, 01, 02, 03, 04 and 05 which have been split into a train and test folders using split_folders: https://pypi.org/project/split-folders/ (The datasets are rather large so I couldn't do it manually)

So when I ran the code:

from imageai.Prediction.Custom import ModelTraining

model_trainer = ModelTraining() model_trainer.setModelTypeAsResNet() model_trainer.setDataDirectory("/content/Training/Items") model_trainer.trainModel(num_objects=6, num_experiments=200, enhance_data=True, batch_size=32, show_network_summary=True)

It received an error:

ValueError: A target array with shape (32, 7) was passed for an output of shape (None, 6) while using as loss categorical_crossentropy. This loss expects targets to have the same shape as the output.

On closer look I found that it detected 7 image classes when I only had 6 image classes uploaded as seen below:

WARNING:tensorflow:period argument is deprecated. Please use save_freq to specify the frequency in number of samples seen. Using Enhanced Data Generation Found 11282 images belonging to 7 classes. Found 4838 images belonging to 6 classes. JSON Mapping for the model classes saved to /content/Training/Items/json/model_class.json Number of experiments (Epochs) : 200 Epoch 1/200

I am not sure where the error may have occurred so any help would be much appreciated!

OlafenwaMoses commented 3 years ago

There is a chance a file was automatically added to the train folder which shouldn't be there E.g system generated files