Why is this happening?

#1
by HuangTianDiLi - opened

from urllib.request import urlopen
from PIL import Image
import timm

img = Image.open(urlopen(
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))

model = timm.create_model(
'resnet18.a1_in1k',
pretrained=True,
features_only=True,
)
model = model.eval()

get model specific transforms (normalization, resize)

data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)

output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1

for o in output:
# print shape of each feature map in output
# e.g.:
# torch.Size([1, 64, 112, 112])
# torch.Size([1, 64, 56, 56])
# torch.Size([1, 128, 28, 28])
# torch.Size([1, 256, 14, 14])
# torch.Size([1, 512, 7, 7])

print(o.shape)

This code Why is this happening?
Traceback (most recent call last):
File "G:\Graduation_Project\Domain_Generalization_through_Distilling_CLIP\RISE-main\resnet18.py", line 12, in
features_only=True,
File "G:\Graduation_Project\Domain_Generalization_through_Distilling_CLIP\RISE-main\timm\models_factory.py", line 110, in create_model
raise RuntimeError('Unknown model (%s)' % model_name)
RuntimeError: Unknown model (resnet18)

PyTorch Image Models org

@HuangTianDiLi whatever project this is, their repackaging of timm, instead of using it as it's own module), is likely messing up the model registration... beyond my control.

Sign up or log in to comment