Skip to content

错误报告: ImportError: cannot import name '_new_empty_tensor' from 'torchvision.ops' #46

@Minh-begintolovecoding

Description

@Minh-begintolovecoding

我在 TransVG 目录中运行 eval.py 时遇到了 ImportError,错误似乎与 torchvision.ops 中的 utils.misc 相关。

环境信息
Python 版本: 3.11
PyTorch 版本: 0.20.1+cu124
Torchvision 版本: 0.20.1
操作系统: Google Colab
错误日志
python
Sao chép
Chỉnh sửa
Traceback (most recent call last):
File "/content/content/TransVG/eval.py", line 15, in
import datasets
File "/content/content/TransVG/datasets/init.py", line 6, in
import datasets.transforms as T
File "/content/content/TransVG/datasets/transforms.py", line 11, in
from utils.misc import interpolate
File "/content/content/TransVG/utils/misc.py", line 22, in
from torchvision.ops import _new_empty_tensor
ImportError: cannot import name '_new_empty_tensor' from 'torchvision.ops' (/usr/local/lib/python3.11/dist-packages/torchvision/ops/init.py)
复现步骤
克隆 TransVG 仓库。

安装依赖项。

运行以下命令:

bash
Sao chép
Chỉnh sửa
python eval.py
--batch_size 32 --num_workers 4 --bert_enc_num 12 --detr_enc_num 6
--backbone resnet50 --dataset referit --max_query_len 20
--eval_set test --eval_model ./checkpoints/detr-r50-referit.pth
--output_dir ./outputs/referit_r50
可能的原因
该错误可能是由于 torchvision 新版本发生了变化,导致 _new_empty_tensor 不再可用。

建议的解决方案
我尝试将 torchvision 降级到旧版本(如 0.10.0),但 pip 没有找到匹配的版本。

可能的解决方法是使用 torchvision.ops 中的替代 API,例如 torch.empty_like() 代替 _new_empty_tensor。

期待您的回复,谢谢!🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions