我正在尝试从书中学习 Pytorch,但这对我来说似乎不是一条直线。我复制了下面的代码并粘贴到我的 jupyter 笔记本中。它给了我一个我无法解释的错误。
from torchvision import models
model = models.alexnet(pretrained=True)
# set the device
device = 'cuda' if torch.cuda.is_available() else 'cpu'
print(f'Device: {device}')
model.eval()
model.to(device)
y = model(batch.to(device))
print(y.shape)
Run Code Online (Sandbox Code Playgroud)
这是错误:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-50-03488007067c> in <module>
1 from torchvision import models
----> 2 model = models.alexnet(pretrained=True)
3
4 # set the device
5 device = 'cuda' if torch.cuda.is_available() else 'cpu'
~\anaconda3\lib\site-packages\torchvision\models\alexnet.py in alexnet(pretrained, progress, **kwargs)
61 model = AlexNet(**kwargs)
62 if pretrained:
---> 63 state_dict …Run Code Online (Sandbox Code Playgroud)