Cannot fix ImportError: cannot import name 'ToTensorV2' from 'albumentations.pytorch' on Colab

Viewed 12886

I tried all three solutions from this question to solve the problem, but still receive an error:

ImportError: cannot import name 'ToTensorV2' from 'albumentations.pytorch' (/usr/local/lib/python3.7/dist-packages/albumentations/pytorch/__init__.py)

My current code:

!pip install -U albumentations
import albumentations 
from albumentations.pytorch import ToTensorV2
2 Answers

Have you tried factory resetting the runtime? If you haven't, maybe python was still loading the earlier version. I have just tested the accepted solution from the linked question on a fresh colab instance and it worked fine:

!pip install albumentations==0.4.6
import albumentations 
from albumentations.pytorch import ToTensorV2

Here it works for me. Importing from github doesn't have any kind of problem.

!pip install -U git+https://github.com/albu/albumentations > /dev/null && echo import albumentations from albumentations.pytorch import ToTensorV2

Related