pytorch-deepdream
pytorch-deepdream copied to clipboard
Error with resnet in jupyter notebook
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
/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!
You need to import that function from torch.hub:
from torch.hub import download_url_to_file