CellProfiling / HPA-Cell-Segmentation

Apache License 2.0
95 stars 26 forks source link

ImportError: cannot import name 'isStringType' from 'PIL._util' #15

Closed hav4ik closed 3 years ago

hav4ik commented 3 years ago

I tried to execute the code from README.org in the Kaggle environment, and got the following error:

ImportError: cannot import name 'isStringType' from 'PIL._util' (/opt/conda/lib/python3.7/site-packages/PIL/_util.py)

Relevant package versions:

pillow==6.2.1
torch==1.4.0
torchvision==0.5.0
imageio==2.8.0
scikit-image==0.16.2
opencv-python==4.4.0.46
click==7.1.1

Full call stack:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-5-d0f02b66e2bb> in <module>
     15     device="cuda",
     16     padding=False,
---> 17     multi_channel_model=True,
     18 )
     19 

/opt/conda/lib/python3.7/site-packages/hpacellseg/cellsegmentator.py in __init__(self, nuclei_model, cell_model, scale_factor, device, padding, multi_channel_model)
     84                 download_with_url(NUCLEI_MODEL_URL, nuclei_model)
     85             nuclei_model = torch.load(
---> 86                 nuclei_model, map_location=torch.device(self.device)
     87             )
     88         if isinstance(nuclei_model, torch.nn.DataParallel) and device == "cpu":

/opt/conda/lib/python3.7/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    527             with _open_zipfile_reader(f) as opened_zipfile:
    528                 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
--> 529         return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
    530 
    531 

/opt/conda/lib/python3.7/site-packages/torch/serialization.py in _legacy_load(f, map_location, pickle_module, **pickle_load_args)
    700     unpickler = pickle_module.Unpickler(f, **pickle_load_args)
    701     unpickler.persistent_load = persistent_load
--> 702     result = unpickler.load()
    703 
    704     deserialized_storage_keys = pickle_module.load(f, **pickle_load_args)

/opt/conda/lib/python3.7/site-packages/pytorch_zoo/__init__.py in <module>
      3 import pytorch_zoo.inception as inception
      4 import pytorch_zoo.inception_resnet_v2 as inception_resnet_v2
----> 5 import pytorch_zoo.ins_test as ins_test
      6 import pytorch_zoo.RAdam as RAdam
      7 import pytorch_zoo.resnet as resnet

/opt/conda/lib/python3.7/site-packages/pytorch_zoo/ins_test.py in <module>
      1 import torch
      2 import torch.nn as nn
----> 3 import torchvision.models as models
      4 from torch.nn import functional as F
      5 

/opt/conda/lib/python3.7/site-packages/torchvision/__init__.py in <module>
      2 
      3 from torchvision import models
----> 4 from torchvision import datasets
      5 from torchvision import ops
      6 from torchvision import transforms

/opt/conda/lib/python3.7/site-packages/torchvision/datasets/__init__.py in <module>
      7 from .svhn import SVHN
      8 from .phototour import PhotoTour
----> 9 from .fakedata import FakeData
     10 from .semeion import SEMEION
     11 from .omniglot import Omniglot

/opt/conda/lib/python3.7/site-packages/torchvision/datasets/fakedata.py in <module>
      1 import torch
      2 from .vision import VisionDataset
----> 3 from .. import transforms
      4 
      5 

/opt/conda/lib/python3.7/site-packages/torchvision/transforms/__init__.py in <module>
----> 1 from .transforms import *

/opt/conda/lib/python3.7/site-packages/torchvision/transforms/transforms.py in <module>
     15 import warnings
     16 
---> 17 from . import functional as F
     18 
     19 if sys.version_info < (3, 3):

/opt/conda/lib/python3.7/site-packages/torchvision/transforms/functional.py in <module>
      3 import sys
      4 import math
----> 5 from PIL import Image, ImageOps, ImageEnhance, __version__ as PILLOW_VERSION
      6 try:
      7     import accimage

/opt/conda/lib/python3.7/site-packages/PIL/ImageOps.py in <module>
     22 
     23 from . import Image
---> 24 from ._util import isStringType
     25 
     26 #

ImportError: cannot import name 'isStringType' from 'PIL._util' (/opt/conda/lib/python3.7/site-packages/PIL/_util.py)

Judging by the call stack, it's more of a torchvision problem. If you can share the pip freeze of your local environment where the code is reproducible, it would solve the issue.

hav4ik commented 3 years ago

Solved. The trick was to install the HPA Cell Segmentation package with

!pip install https://github.com/CellProfiling/HPA-Cell-Segmentation/archive/master.zip

Instead of what I had locally, which is

!git clone https://github.com/CellProfiling/HPA-Cell-Segmentation
!cd HPA-Cell-Segmentation; sh install.sh
kunal9665 commented 1 year ago

facing still issues now

ramani41 commented 1 year ago

In Colab, even after installing the HPA Cell Segmentation package I have the same problem. I still get the error message "ImportError: cannot import name 'isStringType' from 'PIL._util' (/usr/local/lib/python3.8/dist-packages/PIL/_util.py)"

dst111dst commented 1 year ago

Me tooooo, how do you fix it up?:(