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

Error with resnet in jupyter notebook #7

Open
reillydonovan opened this issue Sep 5, 2021 · 1 comment
Open

Error with resnet in jupyter notebook #7

reillydonovan opened this issue Sep 5, 2021 · 1 comment

Comments

@reillydonovan
Copy link

Hi, when I try to run section 21 of the jupyter notebook I am returned the follow error:
Downloading resnet50_places365.pth.tar from http://places2.csail.mit.edu/models_places365/resnet50_places365.pth.tar it may take some time.


NameError Traceback (most recent call last)
/tmp/ipykernel_212303/229011906.py in
10 config['spatial_shift_size'] = 40
11
---> 12 img = deep_dream_static_image(config)
13 dump_path = save_and_maybe_display_image(config, img)
14 print(f'Saved DeepDream static image to: {os.path.relpath(dump_path)}\n')

/tmp/ipykernel_212303/1103483755.py in deep_dream_static_image(config, img)
1 def deep_dream_static_image(config, img=None):
----> 2 model = fetch_and_prepare_model(config['model_name'], config['pretrained_weights'])
3
4 try:
5 layer_ids_to_use = [model.layer_names.index(layer_name) for layer_name in config['layers_to_use']]

/tmp/ipykernel_212303/3540351205.py in fetch_and_prepare_model(model_type, pretrained_weights)
128 elif model_type == SupportedModels.RESNET50.name:
129 # We'll define the ResNet50 later
--> 130 model = ResNet50(pretrained_weights, requires_grad=False, show_progress=True).to(DEVICE)
131 else:
132 raise Exception('Model not yet supported.')

/tmp/ipykernel_212303/2427502766.py in init(self, pretrained_weights, requires_grad, show_progress)
17 binary_url = r'http://places2.csail.mit.edu/models_places365/resnet50_places365.pth.tar'
18 print(f'Downloading {binary_name} from {binary_url} it may take some time.')
---> 19 download_url_to_file(binary_url, resnet50_places365_binary_path)
20 print('Done downloading.')
21 state_dict = torch.load(resnet50_places365_binary_path)['state_dict']

NameError: name 'download_url_to_file' is not defined

Any idea how to fix this? Thanks!

@afruehstueck
Copy link

You need to import that function from torch.hub:
from torch.hub import download_url_to_file

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

2 participants