I had a setup a yolo4 pytorch framework in google colab by cloning git clone https://github.com/roboflow-ai/pytorch-YOLOv4.git.

I generated checkpoints by giving training. As we need more robust training model, I given training again with assigning pretrained checkpoints but it seems loss started with high value as like first time training.

Code is for training !python train.py -b 2 -s 1 -l 0.001 -g 0 -pretrained ./Yolov4_epoch100_latest.pth -classes 1 -dir ./train -epochs 100.

Not sure if my pretrained checkpoint is used in 2end training? If it is used then why second time in starting training loss value seems high like first time training? Please share your thought if you have any


1 Answer 1


Apparently, only the lower layers weights of the pretrained model are being updated. to change it open models.py and scroll down to the class definition of Yolov4. As one can see, only down1-down5 and neck layers are being updated by the pretrained model weights while the head is starting fresh. you should change this code section to something similar to:

if yolov4conv137weight:
        self.neck = Neck()
        **self.head = Yolov4Head(output_ch)**
        _model = nn.Sequential(self.down1, self.down2, self.down3, self.down4, self.down5, self.neck, **self.head**)
        pretrained_dict = torch.load(yolov4conv137weight)

        model_dict = _model.state_dict()
        # 1. filter out unnecessary keys
        pretrained_dict = {k1: v for (k, v), k1 in zip(pretrained_dict.items(), model_dict)}
        # 2. overwrite entries in the existing state dict
        #print("update weights")
    # head
        self.head = Yolov4Head(output_ch)**

Run again and observe the expected loss (hopefully). Good luck!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.