pytorch-deepdream icon indicating copy to clipboard operation
pytorch-deepdream copied to clipboard

Error with resnet in jupyter notebook

Open reillydonovan opened this issue 3 years ago • 1 comments

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!

reillydonovan avatar Sep 05 '21 19:09 reillydonovan

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

afruehstueck avatar Sep 19 '21 11:09 afruehstueck