facebookresearch / pytorchvideo

A deep learning library for video understanding research.
https://pytorchvideo.org/
Apache License 2.0
3.33k stars 411 forks source link

Error importing libraries (Python 3.12.1) #261

Open dinihanafi opened 6 months ago

dinihanafi commented 6 months ago

🐛 Bugs / Unexpected behaviors

Hi everyone I am experiencing an error when importing these libraries for pytorchvideo with python 3.12.1. I have tried using python 3.11.7 version but also received the same error.

Instructions To Reproduce the Issue:

  1. Import libraries: from pytorchvideo.transforms import (ApplyTransformToKey, Normalize, RandomShortSideScale, UniformTemporalSubsample, Permute)

  2. The exact command(s) you ran: import libraries as step 1

  3. Error log: ModuleNotFoundError Traceback (most recent call last) Cell In[6], line 3 1 from pytorchvideo.data import LabeledVideoDataset, Kinetics, make_clip_sampler ----> 3 from pytorchvideo.transforms import (ApplyTransformToKey, Normalize, RandomShortSideScale, UniformTemporalSubsample, Permute) 5 from torchvision.transforms import (Compose, Lambda, RandomCrop, RandomHorizontalFlip, Resize) 7 from torchvision.transforms._transforms_video import (CenterCropVideo, NormalizeVideo)

File c:\Users\pnanurdb\AppData\Local\Programs\Python\Python312\Lib\site-packages\pytorchvideo\transforms__init__.py:3 1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. ----> 3 from .augmix import AugMix # noqa 4 from .mix import CutMix, MixUp, MixVideo # noqa 5 from .rand_augment import RandAugment # noqa

File c:\Users\pnanurdb\AppData\Local\Programs\Python\Python312\Lib\site-packages\pytorchvideo\transforms\augmix.py:6 3 from typing import Any, Dict, Optional 5 import torch ----> 6 from pytorchvideo.transforms.augmentations import ( 7 _AUGMENTATION_MAX_LEVEL, 8 AugmentTransform, 9 _decreasing_int_to_arg, 10 _decreasing_to_arg, 11 _increasing_magnitude_to_arg, 12 _increasing_randomly_negate_to_arg, 13 ) ... ----> 9 import torchvision.transforms.functional_tensor as F_t 10 from torchvision.transforms.functional import InterpolationMode 13 # Maximum global magnitude used for video augmentation.

ModuleNotFoundError: No module named 'torchvision.transforms.functional_tensor'

How do i solved the no module named 'torchvision.transforms.functional_tensor'? I followed the steps in https://pytorchvideo.org/docs/tutorial_torchhub_inference but keep on receiving error when importing libraries.

JorritBootsma commented 6 months ago

Hi Dini,

Your issue is related to the incompatibility of pytorchvideo with PyTorch 2.0 due to a renaming in torchvision. Find more info in this issue.

Module pytorchvideo.transforms.augmentations.py tries to import torchvision.transforms.functional_tensor as F_t on line 9, which fails as this has been deprecated since torchvision 0.15 and removed since torchvision 0.17 (see 0.17 Release Notes).

This import statement should be adjust to import torchvision.transforms.functional as F_t and everything should work as expected.

joaorulff commented 6 months ago

Any chance a PR with this fix is coming soon?

Thanks for the amazing lib

dinihanafi commented 6 months ago

Hi Dini,

Your issue is related to the incompatibility of pytorchvideo with PyTorch 2.0 due to a renaming in torchvision. Find more info in this issue.

Module pytorchvideo.transforms.augmentations.py tries to import torchvision.transforms.functional_tensor as F_t on line 9, which fails as this has been deprecated since torchvision 0.15 and removed since torchvision 0.17 (see 0.17 Release Notes).

This import statement should be adjust to import torchvision.transforms.functional as F_t and everything should work as expected.

how do i adjust to 'import torchvision.transforms.functional as F_t'? as the error comes from this line from pytorchvideo.transforms import (ApplyTransformToKey, Normalize, RandomShortSideScale, UniformTemporalSubsample, Permute)

JorritBootsma commented 6 months ago

Hi Dini, Your issue is related to the incompatibility of pytorchvideo with PyTorch 2.0 due to a renaming in torchvision. Find more info in this issue. Module pytorchvideo.transforms.augmentations.py tries to import torchvision.transforms.functional_tensor as F_t on line 9, which fails as this has been deprecated since torchvision 0.15 and removed since torchvision 0.17 (see 0.17 Release Notes). This import statement should be adjust to import torchvision.transforms.functional as F_t and everything should work as expected.

how do i adjust to 'import torchvision.transforms.functional as F_t'? as the error comes from this line from pytorchvideo.transforms import (ApplyTransformToKey, Normalize, RandomShortSideScale, UniformTemporalSubsample, Permute)

There are several ways to go about this. Which is best depends on the requirements of your applications. If you just want to run this script locally on your machine these are the steps:

  1. Go to this file: c:\Users\pnanurdb\AppData\Local\Programs\Python\Python312\Lib\site-packages\pytorchvideo\transforms\augmentations.py
  2. In line 9 replace import torchvision.transforms.functional_tensor as F_t with import torchvision.transforms.functional as F_t (i.e. remove the _tensor)
  3. Save the file.

Your script should now run without this error being thrown.

Alternatively, you can run this command in Windows Powershell (seems you are on Windows): Note: I have NOT tested it (Get-Content "C:\Users\pnanurdb\AppData\Local\Programs\Python\Python312\Lib\site-packages\pytorchvideo\transforms\augmentations.py") -replace 'import torchvision.transforms.functional_tensor as F_t', 'import torchvision.transforms.functional as F_t' | Set-Content "C:\Users\pnanurdb\AppData\Local\Programs\Python\Python312\Lib\site-packages\pytorchvideo\transforms\augmentations.py"