Lightning-Universe / lightning-flash

Your PyTorch AI Factory - Flash enables you to easily configure and run complex AI recipes for over 15 tasks across 7 data domains

Home Page:https://lightning-flash.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ImportError: cannot import name 'is_directory' from 'PIL._util'

lcoandrade opened this issue Β· comments

πŸ› Bug

Install lightning-flash and lightning-flash[image] in a Google Colab and try to import flash.

!pip install lightning-flash
!pip install 'lightning-flash[image]'
!pip install kornia

import flash

Raises:

ImportError Traceback (most recent call last)
in
1 import torch
----> 2 import flash
3 from flash.core.data.utils import download_data
4 from flash.image import SemanticSegmentation, SemanticSegmentationData
5 import os

8 frames
/usr/local/lib/python3.7/dist-packages/flash/init.py in
20 if _TORCH_AVAILABLE:
21
---> 22 from flash.core.data.callback import FlashCallback
23 from flash.core.data.data_module import DataModule
24 from flash.core.data.io.input import DataKeys, Input

/usr/local/lib/python3.7/dist-packages/flash/core/data/callback.py in
6
7 import flash
----> 8 from flash.core.data.utils import _STAGES_PREFIX
9 from flash.core.utilities.stages import RunningStage
10

/usr/local/lib/python3.7/dist-packages/flash/core/data/utils.py in
37
38 if _TORCHVISION_AVAILABLE:
---> 39 from torchvision.datasets.folder import default_loader
40
41 _STAGES_PREFIX = {

/usr/local/lib/python3.7/dist-packages/torchvision/init.py in
3
4 import torch
----> 5 from torchvision import datasets
6 from torchvision import io
7 from torchvision import models

/usr/local/lib/python3.7/dist-packages/torchvision/datasets/init.py in
----> 1 from ._optical_flow import KittiFlow, Sintel, FlyingChairs, FlyingThings3D, HD1K
2 from .caltech import Caltech101, Caltech256
3 from .celeba import CelebA
4 from .cifar import CIFAR10, CIFAR100
5 from .cityscapes import Cityscapes

/usr/local/lib/python3.7/dist-packages/torchvision/datasets/_optical_flow.py in
10 from PIL import Image
11
---> 12 from ..io.image import _read_png_16
13 from .utils import verify_str_arg
14 from .vision import VisionDataset

/usr/local/lib/python3.7/dist-packages/torchvision/io/init.py in
3 import torch
4
----> 5 from ..utils import _log_api_usage_once
6
7 try:

/usr/local/lib/python3.7/dist-packages/torchvision/utils.py in
7 import numpy as np
8 import torch
----> 9 from PIL import Image, ImageColor, ImageDraw, ImageFont
10
11 all = [

/usr/local/lib/python3.7/dist-packages/PIL/ImageFont.py in
35 from . import Image
36 from ._deprecate import deprecate
---> 37 from ._util import is_directory, is_path
38
39

ImportError: cannot import name 'is_directory' from 'PIL._util' (/usr/local/lib/python3.7/dist-packages/PIL/_util.py)

Expected behavior

Import Flash without raising any errors.

Environment

  • Google Colab 2022/8/11
  • Flash Version: 0.7.5
  • kornia: 0.6.6

Additional context

Hi, @lcoandrade - Thank you for raising the issue. This seemed odd that you had to face this error, so I thought I'll check myself on a Google Colab.

I noticed that you get a warning after you've done: pip install "lightning-flash[image]":

WARNING: The following packages were previously imported in this runtime:
  [PIL]
You must restart the runtime in order to use newly installed versions.

If you restart the runtime, and try importing Flash, it should work. I am also not sure that you need to install kornia separately, doing pip install "lightning-flash[image] does install Kornia (it did for me on the colab), so maybe restarting the runtime solves the issues for you? If it doesn't, please let me know and I'll be happy to take another look at it.

Thank you very much!