-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Transfer Learning with differing number of classes #152
Comments
Hi @hxy1051653358 ,
|
@gabrielloye Thanks for your guidance, I will try your approach |
@gabrielloye How can I define removekey? |
@hxy1051653358 Oh I forgot to include that part as well, my bad. Here:
|
make sure your cfg file end with 'yolov3.cfg', and it will load the darknet53 weight for transfer learning. |
@gabrielloye So with your method you use the old weights (randomly initialized or whatever) for layers 104, 116 and 128 whereas the rest of the network uses the new transferred weights, isn't it? Or does this remove any layer? |
@100330706 Nope, it doesn't remove any layer, what I did was to load the transferred weights and remove the yolo layers (104, 116, 128 in this case) first. I then load the old weights that fit the model (depends on the cfg you're using) and call the .update() method on it with the transferred weights. This will transfer all the layers of the transferred weights to the old weights except the ones we removed earlier. Finally, you can load the model with this "new" set of weights.
Remember to change the number in the below line according to your config as well since you're doing transfer learning:
Note: I'm using the latest version, and I had to comment out the scheduler to make this work. |
@gabrielloye getting this error following the changes you suggested :
Did this happen to you ? Edit, I commented out this and now its working :
|
@hxy1051653358 @gabrielloye @perry0418 @100330706 @Ownmarc the latest commit should handle transfer learning for various class sizes automatically using a new Transfer learning is performed only on YOLO layers of Here is a transfer learning example with a single class (18-length YOLO layers) using
|
When I tried transfer learning with yolov3-1cls.cfg and coco_1cls.data, I get the following error.
How should I go about fixing this? Thank you! |
@vivian-wong yolov3-1cls.cfg is a 1cls derivative of yolov3.cfg, but yolov3-spp.pt was loaded as the default, which is a better performing, newer variant of yolov3. I've changed the default back to yolov3.pt, so if you git pull and retry it will work. Personally, I would not use transfer learning though, it doesn't save you much time, and you will get better results training normally from darknet53. |
Thank you for modifying the default. I am using transfer learning because I would like to train on a smaller dataset which has just one class. I have configured my *.data file as indicated in the tutorial. Now I get:
I also read your comment that
So I tried doing |
Hi, Here are my error details. Questions : I have a pre-trained model on 80 classes , now I am using this model to retrain on 2 classes. I have made the necessary changes (classes and output) in the yolov3_train.prototxt , yolov3_test.prototxt , solver.prototxt. any suggestions to resolve this issue? |
@MuhammadAsadJaved your issue should be posted on the relevant repo, not this one. |
@glenn-jocher Thank you for your advice. I also posted there but there was no response. So I post here as well to find some help because the issue is similar. |
@MuhammadAsadJaved all transfer learning works correctly in this repo. See https://github.com/ultralytics/yolov3/wiki/Example:-Transfer-Learning |
I want to do face detection using YOLOv3 as the model and the Darknet object detection pre-trained weights, taken from |
What is the problem? Post your error
…On Thu, Oct 8, 2020 at 1:45 AM jayant3297 ***@***.***> wrote:
I want to do face detection using YOLOv3 as the model and the Darknet
object detection pre-trained weights, taken from
(https://pjreddie.com/darknet/yolo/)but I am unable to train it for
single class "face" Can anyone help me ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#152 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AG4GR5H6JKKZEOYIV6D32ULSJSSM5ANCNFSM4HATYJFQ>
.
|
Post your procedure and error
…On Thu, Oct 8, 2020 at 1:47 AM Asad Javed ***@***.***> wrote:
What is the problem? Post your error
On Thu, Oct 8, 2020 at 1:45 AM jayant3297 ***@***.***>
wrote:
> I want to do face detection using YOLOv3 as the model and the Darknet
> object detection pre-trained weights, taken from
> (https://pjreddie.com/darknet/yolo/)but I am unable to train it for
> single class "face" Can anyone help me ?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#152 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AG4GR5H6JKKZEOYIV6D32ULSJSSM5ANCNFSM4HATYJFQ>
> .
>
|
The bounding boxes I am getting are around the whole image and not around the face |
Is there any working example/code for adding additional classes (say in my case I want to add 4 classes) to a pretrained yolov4 model (which I had trained for 20 classes) with darknet framework and the weights are saved every 10000 steps, so in all I have 4 weights saved. I see bits and pieces of code, as to passing the number of layers to freeze (in my case 20). But after that what are the next steps - to add the new classes and train for may be 100 iterations, stop and save the weights. Then once that is done I guess, I have to unfreeze all the 20 layers and retrain on all the classes (24). If a working example is there or if someone can help me with mostly code and some pseudo code, that will be helpful. TIA |
@pankaja0285 for darknet training you probably want to head over to https://github.com/AlexeyAB/darknet |
I already checked there, not much help @glenn-jocher. Hence asking here if someone can shed some light. It's not that I need help with darknet. I need help with the transfer learning for additional classes. I can probably convert darknet trained yolov4 weights to say py format (pytorch) and then proceed. It's the proceed after that point, that I need help with. NOTE: FYI, I trained the 20 classes of a VOC dataset. |
@pankaja0285 VOC training is very simple with YOLOv5. All models and datasets download automatically: git clone https://github.com/ultralytics/yolov5 # clone
cd yolov5
pip install -r requirements.txt # install
python train.py --data VOC.yaml --weights yolov5s.pt |
@glenn-jocher I think there's a miscommunication. I already trained for 20 classes and have the yolov4 weights for it, now I how to add additional classes (in my 4 additional classes). From whatever I have read so far I need to provide the layers to freeze in --freeze parameter and then is what I am asking - is everything done behind the scenes? Or for e.g. in your ultralytics repo - train.py how does it go about doing the transfer learning? Again this is for my own additional dataset that contains the 4 classes. |
@pankaja0285 YOLOv5 automatically handles class differences. Starting a training from any other pretrained weights is the default workflow, no action is required on your part. i.e. the command below trains a 20-class model starting from 80-class COCO weights: python train.py --data VOC.yaml --weights yolov5s.pt |
Ok,
|
@pankaja0285 see https://docs.ultralytics.com/yolov5/tutorials/train_custom_data to get started |
Also, I have a NVIDIA GPU, Cuda and CUDNN setup done and all installed. How do I run the training on GPU I guess you have a specific flag setting for it that I have to pass in the |
But you are still not answering my question about the additional classes - how to add and how to further train with the existing weights. Doing the first training and I do see your repo that the best model is getting saved in .pt format. But how do I enhance the model for additional classes is my question. Also, an FYI even though CUDA is available on my laptop, while training the device is not getting recognized. Do I have to modify and configuration settings or where do I need to make any changes, please let me know. I just started to train and I am getting the message that says "... CUDA is not available".... I am running from Pycharm terminal. |
@pankaja0285 apologies for the confusion earlier. To clarify:
Here's a simplified example command for continuing training with additional classes: python train.py --data VOC_addnl_4.yaml --weights path/to/your/previous/best_model.pt The weights will be saved in
If you continue to have issues, please provide more details about your setup, including the versions of CUDA, cuDNN, and PyTorch you're using, and I'll do my best to assist you further. |
I trained the voc dataset by myself and wanted to train new dataset with my own weight. The categories are different and the following errors occur during recovery training:
How can I solve it?
The text was updated successfully, but these errors were encountered: