Reputation: 144
I trained one custom object detection model for my use case using darknet and yolov4. I mentioned 3 classes in the obj.name file as mentioned below:
# data/obj.names
no_helmet
helmet
vest
The training was completed and detection was also working with good results.
Now, I wanted to add 2 new classes to the model, so I updated the class file with 2 new class names:
# data/obj.names
no_helmet
helmet
vest
fire
smoke
I made changes to the config file and updated classes=3
to classes=5
and filter=24
to filter=30
for all the [yolo]
layers and preceding [convolutional]
layers.
For the dataset, I only provided images and annotations for the 2 new classes (fire
and smoke
).
Then I started the darknet training and for the weights parameter, I provided my old yolov4 trained weights. After it was completed, I ran tests and it didn't detect anything in the image. Not even the old classes.
Where did I go wrong?
What I feel is that since I didn't provide a dataset for older classes, the model forgot those. But, then it should have at least detected new classes, right? or am I wrong here?
NEW EDIT:
I trained again with the combined dataset(old 3 classes and 2 new classes) on the pre-trained custom weights (trained for the first 3 classes) and when I ran it for the test, still no output is there.
Could somebody explain to me what's going on here? I'm thinking there is some mathematics behind it which I don't know about.
Do I have to train from scratch every time?
Upvotes: 5
Views: 7197
Reputation: 3744
From the procedure that YOLO follows in training, any further training will enhance and modify the currently layers, so if you added new classes and retrained, you will enhance the exiting one and create new classes from scratch, which means not all classes will be the same during detection. I think the safest way is to train all from scratch.
Upvotes: 1
Reputation: 340
You can't insert new classes in a trained model. When you trained using only the fire and smoke dataset, your config were not configured for 2 classes, but for 5 instead. Probably it's why you didn't get anything in your second test.
The model does not forget, but uses that weight as a head start for your new model. Just train again with a dataset containing all categories labelled.
Upvotes: 2