alankbi / detecto

Build fully-functioning computer vision models with PyTorch
https://detecto.readthedocs.io/
MIT License
613 stars 107 forks source link

Initialize core.Model() without download pretrained model. #23

Closed ktakanopy closed 4 years ago

ktakanopy commented 4 years ago

Is possible to initialize core.Model() without initialize pretrained model? I using this following code to load model weights:

    self.model = core.Model(self.labels, device = torch.device('cpu'))  

    self.model._model.load_state_dict(torch.load('weights/model_weights.pth', map_location=torch.device('cpu'))) 
alankbi commented 4 years ago

Do you mean without the pre-trained weights from PyTorch's model zoo or your own model_weights.pth file? If the former, then as of now no, as Detecto uses those weights for transfer learning on your custom dataset. If the latter, you can just not include the second line of code in your example (your model will not be accurate however until you train it again).

ktakanopy commented 4 years ago

Do you mean without the pre-trained weights from PyTorch's model zoo or your own model_weights.pth file? If the former, then as of now no, as Detecto uses those weights for transfer learning on your custom dataset. If the latter, you can just not include the second line of code in your example (your model will not be accurate however until you train it again).

From what I understand every time I initialize a core.Model () model of the detector, pytorch downloads pre-trained weights and for this reason this line appears in my output: Downloading: "https://download.pytorch.org/models/fasterrcnn_resnet50_fpn_coco-258fb6c6.pth" to /root/.cache/torch/checkpoints/fasterrcnn_resnet50_fpn_coco-258fb6c6.pth

What I would like to do is avoid this download.

alankbi commented 4 years ago

Unfortunately, there's no way to avoid this download, as Detecto is built specifically on top of PyTorch's Faster RCNN. In the future, I'm hoping to add more models including potentially allowing users to pass in custom models, but that might be a ways off. If this is something you feel strongly about though, I'm always open to pull requests for new features!