Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use local .pth file, not to use model_urls like https://s3... to load weight file to train network #219

Open
pistachio0812 opened this issue Nov 19, 2022 · 0 comments

Comments

@pistachio0812
Copy link

when i run train.py to train network, i meet this error:
Downloading: "F:\ssd-v13\model_data\ssd_weights.pth" to C:\Users\zzh/.torch\models\ssd_weights.pth
Traceback (most recent call last):
File "train.py", line 128, in
main()
File "train.py", line 119, in main
model = train(cfg, args)
File "train.py", line 25, in train
model = build_detection_model(cfg)
File "F:\ssd-v13\ssd\modeling\detector_init_.py", line 10, in build_detection_model
return meta_arch(cfg)
File "F:\ssd-v13\ssd\modeling\detector\ssd_detector.py", line 12, in init
self.backbone = build_backbone(cfg)
File "F:\ssd-v13\ssd\modeling\backbone_init_.py", line 13, in build_backbone
return registry.BACKBONES[cfg.MODEL.BACKBONE.NAME](cfg, cfg.MODEL.BACKBONE.PRETRAINED)
File "F:\ssd-v13\ssd\modeling\backbone\frassd_net\frassd_net.py", line 160, in frassd_net
model.init_from_pretrain(load_state_dict_from_url(model_urls['ssdv1']))
File "F:\ssd-v13\ssd\utils\model_zoo.py", line 61, in load_state_dict_from_url
cached_file = cache_url(url)
File "F:\ssd-v13\ssd\utils\model_zoo.py", line 55, in cache_url
download_url_to_file(url, cached_file, hash_prefix, progress=progress)
File "D:\anaconda\envs\pytorch-gpu\lib\site-packages\torch\hub.py", line 437, in download_url_to_file
u = urlopen(req)
File "D:\anaconda\envs\pytorch-gpu\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "D:\anaconda\envs\pytorch-gpu\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "D:\anaconda\envs\pytorch-gpu\lib\urllib\request.py", line 547, in _open
return self._call_chain(self.handle_open, 'unknown',
File "D:\anaconda\envs\pytorch-gpu\lib\urllib\request.py", line 502, in _call_chain
result = func(*args)
File "D:\anaconda\envs\pytorch-gpu\lib\urllib\request.py", line 1425, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib.error.URLError:

train.py:
model_urls ={
'vgg': 'https://s3.amazonaws.com/amdegroot-models/vgg16_reducedfc.pth',
'ssdv1': 'F:\ssd-v13\model_data\ssd_weights.pth',
'ssd300_voc0712': '../model_data/vgg_ssd300_voc0712.pth',
'ssd300_coco2014': '../model_data/vgg_ssd300_coco_trainval35k.pth',
'ssd512_voc0712': '../model_data/vgg_ssd512_voc0712.pth',
'ssd512_coco2014': '../model_data/vgg_ssd512_coco_trainval35k.pth',
}

@registry.BACKBONES.register('my_net')
def my_net(cfg, pretrained=True):
model = MY_NET(cfg)
if pretrained:
model.init_from_pretrain(load_state_dict_from_url(model_urls['ssdv1']))
return model

how to solove it, thanks!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant