Lightning-AI / Lightning-AI/torchmetrics

Failed to import from `torchmetrics.image.lpip`

Open
#3,314 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug / fix help wanted
Dominant language
Python
Stars
2.5k
Forks
526
Avg merge
6d 11h
Merged PRs (30d)
5

Description

## 🐛 Bug

Even importing TM with the latest Torch and TorchVision on GPU fails, I just do it with kaggle

### To Reproduce

```py
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
```

Code sample

```
/usr/local/lib/python3.11/dist-packages/torchmetrics/__init__.py in
35 scipy.signal.hamming = scipy.signal.windows.hamming
36
---> 37 from torchmetrics import functional # noqa: E402
38 from torchmetrics.aggregation import ( # noqa: E402
39 CatMetric,

/usr/local/lib/python3.11/dist-packages/torchmetrics/functional/__init__.py in
54 )
55 from torchmetrics.functional.detection._deprecated import _panoptic_quality as panoptic_quality
---> 56 from torchmetrics.functional.image._deprecated import (
57 _error_relative_global_dimensionless_synthesis as error_relative_global_dimensionless_synthesis,
58 )

/usr/local/lib/python3.11/dist-packages/torchmetrics/functional/image/__init__.py in
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
---> 14 from torchmetrics.functional.image.arniqa import arniqa
15 from torchmetrics.functional.image.d_lambda import spectral_distortion_index
16 from torchmetrics.functional.image.d_s import spatial_distortion_index

/usr/local/lib/python3.11/dist-packages/torchmetrics/functional/image/arniqa.py in
29
30 if _TORCHVISION_AVAILABLE:
---> 31 from torchvision import transforms
32 from torchvision.models import resnet50
33

/usr/local/lib/python3.11/dist-packages/torchvision/__init__.py in
8 # .extensions) before entering _meta_registrations.
9 from .extension import _HAS_OPS # usort:skip
---> 10 from torchvision import _meta_registrations, datasets, io, models, ops, transforms, utils # usort:skip
11
12 try:

/usr/local/lib/python3.11/dist-packages/torchvision/_meta_registrations.py in
23
24
---> 25 @register_meta("roi_align")
26 def meta_roi_align(input, rois, spatial_scale, pooled_height, pooled_width, sampling_ratio, aligned):
27 torch._check(rois.size(1) == 5, lambda: "rois must have shape as Tensor[K, 5]")

/usr/local/lib/python3.11/dist-packages/torchvision/_meta_registrations.py in wrapper(fn)
16 def register_meta(op_name, overload_name="default"):
17 def wrapper(fn):
---> 18 if torchvision.extension._has_ops():
19 get_meta_lib().impl(getattr(getattr(torch.ops.torchvision, op_name), overload_name), fn)
20 return fn

AttributeError: partially initialized module 'torchvision' has no attribute 'extension' (most likely due to a circular import)
```

Environment

```
torch 2.9.1
torchao 0.10.0
torchaudio 2.6.0+cu124
torchdata 0.11.0
torchinfo 1.8.0
torchmetrics 1.8.2
torchsummary 1.5.1
torchtune 0.6.1
torchvision 0.24.1
```

### Additional context

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the import from torchmetrics.image.lpip with the reported Torch, TorchVision, and Python environment. Start by tracing the import path through torchmetrics/functional/image/arniqa.py and the torchvision initialization shown in the traceback. Done means LearnedPerceptualImagePatchSimilarity imports successfully without the reported AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.