需要加载CLIP预训练模型 RN50.pt
但是一直报错,可能是我环境中用的torch和torchvision与RN50.py用的版本不一样
在github上找到CLIP用的版本:
```python
conda install --yes -c pytorch pytorch=1.7.1 torchvision cudatoolkit=11.0
于是卸载当前环境的torch和torchvision
```python
pip uninstall torch
pip uninstall torchvision
安装和CLIP模型相同的版本:
pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
然后发现还是不行,于是在网上搜索一番,发现本项目中初始化CLIP模型的时候用的是torch.jit.load():
def init_weights(self, pretrained=None):
if isinstance(pretrained, str):
checkpoint = torch.jit.load(pretrained, map_location='cpu').float().state_dict()
改为:
checkpoint = torch.load(pretrained, map_location='cpu').float().state_dict()
ok,解决了,虽然继续报新的bug…
AttributeError: CLAMP: ‘collections.OrderedDict’ object has no attribute ‘float’
改成:
checkpoint = torch.load(pretrained, map_location='cpu')
终于跑起来了