-
Notifications
You must be signed in to change notification settings - Fork 85
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
TypeError: __call__() got an unexpected keyword argument 'pretrained' #21
Comments
I had a similar issue. I tried this: import torch
import torchvision.models as models
MODEL_LIST = {
models.resnet: models.resnet.__all__[1:],
}
for model_type in MODEL_LIST.keys():
for model_name in MODEL_LIST[model_type]:
print(model_name)
model = getattr(model_type, model_name)(pretrained=False) and then $ python3 mytest.py
ResNet18_Weights
Traceback (most recent call last):
File "mytest.py", line 16, in <module>
model = getattr(model_type, model_name)(pretrained=False)
TypeError: __call__() got an unexpected keyword argument 'pretrained' I think the problem is the list of names that ['ResNet18_Weights', 'ResNet34_Weights', 'ResNet50_Weights', 'ResNet101_Weights', 'ResNet152_Weights', 'ResNeXt50_32X4D_Weights', 'ResNeXt101_32X8D_Weights', 'ResNeXt101_64X4D_Weights', 'Wide_ResNet50_2_Weights', 'Wide_ResNet101_2_Weights', 'resnet18', 'resnet34', 'resnet50', 'resnet101', 'resnet152', 'resnext50_32x4d', 'resnext101_32x8d', 'resnext101_64x4d', 'wide_resnet50_2', 'wide_resnet101_2'] that includes stuff that I think are not models (e.g. import torch
import torchvision.models as models
model_names = sorted(name for name in models.__dict__
if name.islower() and not name.startswith("__")
and callable(models.__dict__[name]))
MODEL_LIST = {
models.resnet: [ name for name in model_names if 'resnet' in name],
}
for model_type in MODEL_LIST.keys():
for model_name in MODEL_LIST[model_type]:
print(model_name)
model = getattr(model_type, model_name)(pretrained=False) and then I get: $ python3 mytest.py
resnet101
/scratch/c.c1045890/dl.examples/pytorch-gpu-benchmark/venv/lib/python3.7/site-packages/torchvision/models/_utils.py:209: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and will be removed in 0.15, please use 'weights' instead.
f"The parameter '{pretrained_param}' is deprecated since 0.13 and will be removed in 0.15, "
/scratch/c.c1045890/dl.examples/pytorch-gpu-benchmark/venv/lib/python3.7/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and will be removed in 0.15. The current behavior is equivalent to passing `weights=None`.
warnings.warn(msg)
resnet152
resnet18
resnet34
resnet50
wide_resnet101_2
wide_resnet50_2 there are still a couple of warnings but at least no crash. |
Switch to torchvision-0.12.0 and problem will disappear. Full list of dependencies versions:
|
Yeah, but we want to benchmark using newest torch and torchvision versions. Please fix! |
i changed code due to the reply of @josemunozc, in MODEL_LIST = {
models.mnasnet: models.mnasnet.__all__[1:],
models.resnet: models.resnet.__all__[1:],
models.densenet: models.densenet.__all__[1:],
models.squeezenet: models.squeezenet.__all__[1:],
models.vgg: models.vgg.__all__[1:],
models.mobilenet: models.mobilenet.mv2_all[1:],
models.mobilenet: models.mobilenet.mv3_all[1:],
models.shufflenetv2: models.shufflenetv2.__all__[1:],
}
for k, m_list in MODEL_LIST.items():
MODEL_LIST[k] = [name for name in m_list if name.islower()] |
Running env:
docker in wsl2 20.10.16
nvidia pytorch image:
nvcr.io/nvidia/pytorch:22.05-py3
Here is the error code
The text was updated successfully, but these errors were encountered: