Skip to content

Bug Report: ImportError: cannot import name '_new_empty_tensor' from 'torchvision.ops' #45

@Minh-begintolovecoding

Description

@Minh-begintolovecoding

I am trying to run eval.py in the TransVG directory in google colab but encountered an ImportError related to torchvision.ops when importing utils.misc.

Environment
Python version: 3.11
PyTorch version: 0.20.1+cu124
Torchvision version: 0.20.1
OS: Google Colab
Error Log
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)
Steps to Reproduce
Clone the TransVG repository.

Install the dependencies.

Run the following command:

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
Possible Cause
The error may be caused by a change in newer versions of torchvision, where _new_empty_tensor is no longer available.

Proposed Solution
I attempted to downgrade torchvision to older versions (e.g., 0.10.0), but pip did not find a matching distribution.

A possible fix might be to replace _new_empty_tensor with an alternative API in torchvision.ops, such as torch.empty_like().

Looking forward to your response. Thank you! 🙏

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