运行predict.py文件时出现这个问题。
原因:我的unet模型是在colab上跑的,colab上的torch环境配置版本较高,而我自己anaconda中的pytorch环境配置的torch版本只有1.2.0,因此当试图在旧版pytorch(<1.6)环境中加载新版pytorch跑出来的模型时,就会出现不兼容的情况。因此我在anaconda中重新创建了一个pytorch_colab环境,配置和colab中的一致,安装命令如下:
1. 创建环境:
conda create -n pytorch_colab python=3.10
2. 安装torch环境
pip install torch==2.1.0+cu118 torchvision==0.16.0+cu118 -f https://download.pytorch.org/whl/torch_stable.html
在pycharm中python环境改成pytorch_colab,可以解决问题。