Closed humzaiqbal closed 3 years ago
Hi @humzaiqbal thanks for raising this! I will look into it, will probably require a quick update to the library. For now your fix sounds like the appropriate way to deal with it.
Actually, can you provide the code that you are running and what error you get?
Sure here is a snippet. The densenet_l2_eps0.ckpt
that I reference is this from this repository
OUT_DIR = '/tmp/'
NUM_WORKERS = 16
BATCH_SIZE = 512
from robustness import model_utils, datasets, train, defaults
from robustness.datasets import CIFAR, ImageNet
import torch
from cox.utils import Parameters
import cox.store
from torchvision import transforms
imagenet_ds = ImageNet('/tmp/')
densenet , _ = model_utils.make_and_restore_model(arch='DenseNet', dataset=imagenet_ds,
resume_path='densenet_l2_eps0.ckpt', parallel=False)
And the error I get is
/usr/local/lib/python3.6/dist-packages/robustness/datasets.py in get_model(self, arch, pretrained)
208 """
209 return imagenet_models.__dict__[arch](num_classes=self.num_classes,
--> 210 pretrained=pretrained)
211
212 class Places365(DataSet):
TypeError: __init__() got an unexpected keyword argument 'pretrained'
Hey @humzaiqbal, the models from the robust-models-transfer repo are official PyTorch models and can be loaded using the following code:
OUT_DIR = '/tmp/'
NUM_WORKERS = 16
BATCH_SIZE = 512
from robustness import model_utils, datasets, train, defaults
from robustness.datasets import CIFAR, ImageNet
import torch
from cox.utils import Parameters
import cox.store
from torchvision import transforms
from torchvision import models
imagenet_ds = ImageNet('/tmp/')
densenet , _ = model_utils.make_and_restore_model(arch=models.densenet161(), dataset=imagenet_ds,
resume_path='densenet_l2_eps0.ckpt', parallel=False)
Hope this helps!
Thanks much @Hadisalman :) I think I was confused because in the example notebook I saw the model being loaded by passing a string name for the architecture and assumed thats how it always worked
Hi, I'm trying to load some of the pretrained DenseNet models from this repository using the
make_and_restore_model
utility, but when I do I notice the following errorafter looking at the
densenet.py
file I notice something, for theDenseNet
option that would actually point to the baseDenseNet
class which isn't configured as the other classes likedensenet121
as an example. Looking further at the code it seems there is a simple solution which is to use_densenet
instead as that seems to load a baseDenseNet
model using the proper arguments. What are your thoughts on this? Thanks much am a big fan of the library!