fasterrcnn-pytorch-training-pipeline
fasterrcnn-pytorch-training-pipeline copied to clipboard
How to train with pretrained weights?
The train.py file accepts --model and --weights arguments and when I use the --model argument, training is from scratch. And when I use --weights and set the path to a pth file, I am getting this error:
Loading pretrained weights... Traceback (most recent call last): File "E:\fastercnn-pytorch-training-pipeline\train.py", line 547, in <module> main(args) File "E:\fastercnn-pytorch-training-pipeline\train.py", line 293, in main keys = list(checkpoint['model_state_dict'].keys()) KeyError: 'model_state_dict'
@edehino
The checkpoint will have to have a model_state_dict
key where the state dictionary should be saved. Else the script won't be able to load the pretrained weihts.
@sovit-123 I downloaded the pre-trained weight from this repository: https://github.com/open-mmlab/mmdetection/blob/main/docs/en/model_zoo.md
I am running this code:
python train.py --data data_configs/custom.yaml --epochs 2 --model fasterrcnn_resnet50_fpn_v2 --name test --weights weights/resnet50-19c8e357.pth --device cpu
output is:
`Not using distributed mode device cpu Creating data loaders Number of training samples: 896 Number of validation samples: 254
Loading pretrained weights...
Traceback (most recent call last):
File "E:\fastercnn-pytorch-training-pipeline\train.py", line 549, in
Do you have any pretrained models that I can test?
@edehino
You can directly use COCO pretrained weights just by using --model fasterrcnn_resnet50_fpn_v2
. It is one of the best models in the repository and directly uses the PyTorch pretrained model.
Can you also use the fasterrcnn_resnet50_fnp_v2 without pretrained weights? And do you know if there are any layers frozen? if yes, can you unfreeze them?
Hi. To train without pretrained weights, just go into models/fasterrcnn_resnet50_fnp_v2.py
and make weights=None
. Only a few hundred parameters are frozen when fine-tuning. Almost 99% of the model gets fine-tuned when using pretrained weights. I don't think any weights will be frozen when training from scratch.