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

CIFAR10-Adversarial-Perturbations.ipynb -- Load pretrained CIFAR-10 models not included and incorrectly named #66

Closed
miscpeeps opened this issue Jun 15, 2022 · 2 comments

Comments

@miscpeeps
Copy link
Contributor

CIFAR10-Adversarial-Perturbations.ipynb example jupyter notebook and tutorial reference mitll_cifar_l2_1_0.pt and mitll_cifar_nat.pt as pretrained CIFAR-10 models. These models are not included in the standard rai-toolbox[mushin] install (perhaps due to licensing or desire to have most up-to-date models?).

Models download from urls at robustness Github are named cifar_l2_1_0.pt and cifar_nat.pt and will cause the following error on In[10] of CIFAR10-Adversarial-Perturbations.ipynb:

FileNotFoundError                         Traceback (most recent call last)
Input In [8], in <cell line: 3>()
      1 # Load pretrained model that was trained using a robust approach (i.e., adversarial training)
      2 ckpt_robust = "mitll_cifar_l2_1_0.pt"
----> 3 model_robust = load_model(ckpt_robust)
      4 model_robust.eval();
      6 # Load pretrained model that was trained with standard approach

Input In [7], in load_model(ckpt)
      2 def load_model(ckpt):
----> 3     base_model = load_from_checkpoint(
      4         model = resnet50(),
      5         ckpt = ckpt,
      6         weights_key="state_dict",
      7     )
      9     normalizer = transforms.Normalize(
     10         mean=[0.4914, 0.4822, 0.4465],
     11         std=[0.2023, 0.1994, 0.2010],
     12     )
     14     model = nn.Sequential(normalizer, base_model)

File ~/dev/rai-toolbox-james/responsible-ai-toolbox/src/rai_toolbox/mushin/_utils.py:60, in load_from_checkpoint(model, ckpt, weights_key, weights_key_strip, model_attr)
     57     ckpt = Path.home() / ".torch" / "models" / ckpt
     58 log.info(f"Loading model checkpoint from {ckpt}")
---> 60 ckpt_data: Dict[str, Any] = torch.load(ckpt, map_location="cpu")
     62 if weights_key is not None:
     63     assert weights_key in ckpt_data

File ~/anaconda3/envs/rai-toolbox-james/lib/python3.9/site-packages/torch/serialization.py:699, in load(f, map_location, pickle_module, **pickle_load_args)
    696 if 'encoding' not in pickle_load_args.keys():
    697     pickle_load_args['encoding'] = 'utf-8'
--> 699 with _open_file_like(f, 'rb') as opened_file:
    700     if _is_zipfile(opened_file):
    701         # The zipfile reader is going to advance the current file position.
    702         # If we want to actually tail call to torch.jit.load, we need to
    703         # reset back to the original position.
    704         orig_position = opened_file.tell()

File ~/anaconda3/envs/rai-toolbox-james/lib/python3.9/site-packages/torch/serialization.py:231, in _open_file_like(name_or_buffer, mode)
    229 def _open_file_like(name_or_buffer, mode):
    230     if _is_path(name_or_buffer):
--> 231         return _open_file(name_or_buffer, mode)
    232     else:
    233         if 'w' in mode:

File ~/anaconda3/envs/rai-toolbox-james/lib/python3.9/site-packages/torch/serialization.py:212, in _open_file.__init__(self, name, mode)
    211 def __init__(self, name, mode):
--> 212     super(_open_file, self).__init__(open(name, mode))

FileNotFoundError: [Errno 2] No such file or directory: '/home/scott/.torch/models/mitll_cifar_l2_1_0.pt'

Models must be renamed and manually copied to /home/{$USER}/.torch/models to proceed with tutorial.

@miscpeeps miscpeeps changed the title CIFAR10-Adversarial-Perturbations.ipynb Load pretrained CIFAR-10 models not included and incorrectly named CIFAR10-Adversarial-Perturbations.ipynb -- Load pretrained CIFAR-10 models not included and incorrectly named Jun 15, 2022
@jgbos
Copy link
Contributor

jgbos commented Jun 16, 2022

This should be updated in our notebook. By default the loader will check in your home directory under .torch/models, but this notebook should be explicit with the location. You should actually just provide the full path to the model and name, e.g.,

ckpt_robust = "/home/scott/.torch/models/cifar_nat.pt"

@rsokl
Copy link
Contributor

rsokl commented Jun 29, 2022

Closed by #69 and #73

@rsokl rsokl closed this as completed Jun 29, 2022
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

3 participants