RangiLyu / nanodet

NanoDet-Plusāš”Super fast and lightweight anchor-free object detection model. šŸ”„Only 980 KB(int8) / 1.8MB (fp16) and run 97FPS on cellphonešŸ”„
Apache License 2.0
5.71k stars 1.04k forks source link

pth-file size much larger than pre-trained coco file #557

Closed alexander-sony closed 5 months ago

alexander-sony commented 6 months ago

Have trained 5 classes on a custom dataset starting from config https://github.com/RangiLyu/nanodet/blob/main/config/nanodet-plus-m-1.5x_416.yml (adjusted num_classes) and https://github.com/RangiLyu/nanodet/blob/main/tools/train.py. Training went just fine and reached mAP 0.8 after 300 epochs. Resulting model_best.ckpt is 125MB and nanodet_model_best.pth is 31MB.

Here is my question:

It seems that my pth file includes stuff only required for training. Anyone knows if this is the case and if it can be removed? Have tried torch.save(model.state_dict(), PATH) but the resulting file is still 30MB

model was created as in main() in https://github.com/RangiLyu/nanodet/blob/main/tools/export_onnx.py

Interestingly, the onnx model size is 10MB.

alexander-sony commented 5 months ago

iterate over the state_dict and remove items starting with "aux" - those are only requires during traing as remarked in the config file