-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Model Training Tutorial not training #15
Comments
Hello, ImageAI supports training models for 2 or more classes. Instead of having only vehicles, I will advice you structure your dataset as below: train-> car ->images test-> car ->images |
Works perfectly, thanks! |
You are welcome. |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. I created a dataset folder just as you described. I have one class, "vehicles," and so I have the train -> vehicle -> images and test -> vehicle -> images setup.
When I run
from imageai.Prediction.Custom import ModelTraining
model_trainer = ModelTraining()
model_trainer.setModelTypeAsResNet()
model_trainer.setDataDirectory("vehicles")
model_trainer.trainModel(num_objects=1, num_experiments=100, enhance_data=True, batch_size=32, show_network_summary=True)
I get the following error after Epoch 1 begins
Epoch 1/100
Traceback (most recent call last):
File "trainer.py", line 14, in
model_trainer.trainModel(num_objects=1, num_experiments=100, enhance_data=False, batch_size=32, show_network_summary=False)
File "C:\Users\RDITLDTS\anaconda3\lib\site-packages\imageai\Prediction\Custom_init_.py", line 240, in trainModel
validation_steps=int(num_test / batch_size), callbacks=[checkpoint, lr_scheduler])
File "C:\Users\RDITLDTS\anaconda3\lib\site-packages\tensorflow\python\keras_impl\keras\engine\training.py", line 2172, in fit_generator
x, y, sample_weight=sample_weight, class_weight=class_weight)
File "C:\Users\RDITLDTS\anaconda3\lib\site-packages\tensorflow\python\keras_impl\keras\engine\training.py", line 1855, in train_on_batch
check_batch_axis=True)
File "C:\Users\RDITLDTS\anaconda3\lib\site-packages\tensorflow\python\keras_impl\keras\engine\training.py", line 1449, in _standardize_user_data
self._feed_output_shapes)
File "C:\Users\RDITLDTS\anaconda3\lib\site-packages\tensorflow\python\keras_impl\keras\engine\training.py", line 283, in _check_loss_and_target_compatibility
y.shape) + ' while using as loss
categorical_crossentropy
. 'ValueError: You are passing a target array of shape (32, 1) while using as loss
categorical_crossentropy
.categorical_crossentropy
expects targets to be binary matrices (1s and 0s) of shape (samples, classes). If your targets are integer classes, you can convert them to the expected format via:Alternatively, you can use the loss function
sparse_categorical_crossentropy
instead, which does expect integer targets.:How do I fix this?
The text was updated successfully, but these errors were encountered: