Search code examples
python-3.xtensorflowobject-detectiondarknetdarkflow

Darknet Yolov3 - Custom training on pre-trained model


Actually in darknet yolov3 model has coco.names file for labels which include 80 classes. Now if I want to train a custom model with two labels only, where one label is already there in coco.names and another is not there.

For example I want to train a model to detect for cell phone and dslr camera, so cell phone class already exist in coco.names whereas dslr camera is not there in its labels file.

So can I train custom model using two classes cell phone and dslr camera and give data of only dslr camera for training and it will predict for both dslr camera and cell phone or shall I train with both data of cell phone and dslr images or is there any other way out.

I am a bit new to ML, so any help would be great Thanks


Solution

  • So you want to fine tune a pre-trained model. You need to think of classes by just being a set of end nodes of a network, the labels (phone, camera) are just a naming convention for them, and to give us visual guidance.

    These nodes are fully connected (with associated weights) to the previous layer of the network, the total number of these intermediate connections varies depending on the number of end nodes (classes) you have.

    With the fully trained model, you can't just select the nodes you want, and take out the rest, and add a few more. Because the previous layer (and full network) was trained to give estimates/predictions taking into account a certain number of final nodes.

    So basically you need to give a full reset on the last layer (the head), and restart it with the desired number of classes. The idea here, is that you take advantage of the previous training effort on a broader dataset, and fine tune it to your desired data.

    Short answer, you need data for both, and need to change the model to accept 2 classes only.

    To configure that specific model for the new number of classes and data, I believe you can find some guidance and instructions here