Reputation: 31
I want to train a few products for image classification in Yolo. Let's say I have trained with 10 products (means 10 classes) and saved the best file. Now I want to add some more data of other products (means some new class names and images). So, can I call the previous trained model and then train again with only the new class of images? If not then is there any way to retrain my model not from scratch but from the last trained file with new class of images. Please, reply.
I have tried this code:
!python train.py --workers 8 --batch-size 16 --data products/data.yaml --img 640 640 --cfg cfg/training/yolov7_custom.yaml --epochs 5 --weights 'runs/train/products/weights/last.pt' --name yolov7_custom_newClass --hyp data/hyp.scratch.custom.yaml --device 0
Here, "last.pt" is the previous trained file, and "data.yaml" is the new data yaml file, whose number of classes is different as new images with new class names, after running the code, it show me this error:
RuntimeError: Error(s) in loading state_dict for Model:
size mismatch for model.105.m.0.weight: copying a param with shape torch.Size([30, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([21, 256, 1, 1]).
size mismatch for model.105.m.0.bias: copying a param with shape torch.Size([30]) from checkpoint, the shape in current model is torch.Size([21]).
size mismatch for model.105.m.1.weight: copying a param with shape torch.Size([30, 512, 1, 1]) from checkpoint, the shape in current model is torch.Size([21, 512, 1, 1]).
size mismatch for model.105.m.1.bias: copying a param with shape torch.Size([30]) from checkpoint, the shape in current model is torch.Size([21]).
size mismatch for model.105.m.2.weight: copying a param with shape torch.Size([30, 1024, 1, 1]) from checkpoint, the shape in current model is torch.Size([21, 1024, 1, 1]).
size mismatch for model.105.m.2.bias: copying a param with shape torch.Size([30]) from checkpoint, the shape in current model is torch.Size([21]).
size mismatch for model.105.im.0.implicit: copying a param with shape torch.Size([1, 30, 1, 1]) from checkpoint, the shape in current model is torch.Size([1, 21, 1, 1]).
size mismatch for model.105.im.1.implicit: copying a param with shape torch.Size([1, 30, 1, 1]) from checkpoint, the shape in current model is torch.Size([1, 21, 1, 1]).
size mismatch for model.105.im.2.implicit: copying a param with shape torch.Size([1, 30, 1, 1]) from checkpoint, the shape in current model is torch.Size([1, 21, 1, 1]).
Looks like, as the new data.yaml file's number of classes are differnet from previous models, That's why this error occured.. Any solution.
Upvotes: 1
Views: 769
Reputation: 1
You can easily freeze your weight by passing --freeze argument, try different number from small to big to get best results
Upvotes: 0