@LOVELWY
ImportError: cannot import name ‘_new_empty_tensor’ from ‘torchvision.ops’
找到报错位置misc.py
import torchvision
if float(torchvision.__version__[:3]) < 0.7:
from torchvision.ops import _new_empty_tensor
from torchvision.ops.misc import _output_size
利用Print()函数(torchvision.version)查看Torchvision的版本
import torchvision
print(torchvision._version_)
结果显示:
0.14.0+cu117
float(torchvision.version[:3])代码只检查前3个字符,因此它认为我的版本是0.1,故出现报错。
查找资料可注释掉相关的代码即可,这样做需要仔细查看但代码比较麻烦,想到一个办法,即将代码改成:
import torchvision
if float(torchvision.__version__[2:4]) < 7:
from torchvision.ops import _new_empty_tensor
from torchvision.ops.misc import _output_size
ModuleNotFoundError: No module named ‘sklearn’
沒有安裝sklearn,安装完sklearn之后依然会报错
注意要裝的不是sklearn而是scikit-learn
pip install scikit-learn -i https://pypi.tuna.tsinghua.edu.cn/simple/
test.py: error: the following arguments are required: cfg_file
直接在编译器Pycharm运行报错,定位到报错位置:
parser = argparse.ArgumentParser(description="Test CornerNet")
parser.add_argument("cfg_file", help="config file", type=str)
查阅资料发现parser是命令行交互的端口,所以选择使用命令行运行,运行之前更改LSTR.json文件中data的位置为测试集存储的位置。
"E:\LSTR-main\config\LSTR.json"
"data_dir": "E:/LSTR-main/cache/",
默认为"data_dir": "../../",
命令行运行成功
输入命令行运行语句为:
python test.py LSTR --testiter 500000 --modality eval --split testing --debug --debugDec