Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'imread' #115

Open
Tyler-Hilbert opened this issue Jun 20, 2019 · 4 comments
Open

ImportError: cannot import name 'imread' #115

Tyler-Hilbert opened this issue Jun 20, 2019 · 4 comments

Comments

@Tyler-Hilbert
Copy link

I am running this example on a Ubuntu18 on AWS. I am able to build it without errors, but when I run the dockerfile it exits.


$docker build . --tag fc
Successfully built 9b501a367521
Successfully tagged fc:latest

$docker run -d -p 8084:8084 --name=fc fc
3c25112508ac7b4ac154710f215fb1fc09db8550e29b3ed53e1fa4a3e3bd0eec

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
3c25112508ac        fc                  "python3 src/web/fac…"   12 seconds ago      Exited (1) 9 seconds ago                       fc

I check out the log file and find the following ImportError:

$ docker logs 3c25112508ac
Using TensorFlow backend.
Traceback (most recent call last):
  File "src/web/faces.py", line 4, in <module>
    import emotion_gender_processor as eg_processor
  File "/ekholabs/face-classifier/src/web/emotion_gender_processor.py", line 16, in <module>
    from utils.preprocessor import preprocess_input
  File "/ekholabs/face-classifier/src/utils/preprocessor.py", line 2, in <module>
    from scipy.misc import imread, imresize
ImportError: cannot import name 'imread'

How do I go about correctly running the Dockerfile?
I haven't changed anything so I don't know why I would have an ImportError. I googled it and it looks like the issue is with including Pillow, but when I check the Dockerfile I think it is being included.

@hiro-24
Copy link

hiro-24 commented Jun 26, 2019

Hello,
I had the same problem. But I solved it in the following way.

[From the conclusion]
Please use the 'scikit-imag' and 'imageio' instead of 'scipy.misc'.

[Solution]
First, Install the 'scikit-imag' and 'imageio'
pip install scikit-imag
pip install imageio

And add the following code to preprocessor.py.
from imageio import imread
from skimage.transform import resize

So, please delete the problem code.
from scipy.misc import imread, imresize

Second,
Please change the the same python file's code (preprocessor.py.)
Change before
def _imresize(image_array, size): return imresize(image_array, size)
to
Change after
def _resize(image_array, size): return resize(image_array, size)

I think this will solve this problem.
Please try this.

@o0Roy
Copy link

o0Roy commented Sep 3, 2019

You can change the scipy version to 1.2.1, and I solved it this way.

@enric1994
Copy link

This Dockerfile works for me, replace it with the current one:

FROM jjanzic/docker-python3-opencv:contrib-opencv-3.2.0

RUN apt-get -y update && apt-get install -y git vim procps curl

#Face classificarion dependencies & web application
RUN pip3 install numpy==1.13.3 scipy==1.2.1 scikit-learn pillow tensorflow==1.1.0 pandas==0.19.1 h5py==2.7.0 opencv-python==3.2.0.8 keras==2.0.5 statistics pyyaml pyparsing cycler matplotlib Flask

ADD . /ekholabs/face-classifier

WORKDIR ekholabs/face-classifier

ENV PYTHONPATH=$PYTHONPATH:src
ENV FACE_CLASSIFIER_PORT=8084
EXPOSE $FACE_CLASSIFIER_PORT

ENTRYPOINT ["python3"]
CMD ["src/web/faces.py"]

@rovesoul
Copy link

rovesoul commented Nov 4, 2019

This Dockerfile works for me, replace it with the current one:

FROM jjanzic/docker-python3-opencv:contrib-opencv-3.2.0

RUN apt-get -y update && apt-get install -y git vim procps curl

#Face classificarion dependencies & web application
RUN pip3 install numpy==1.13.3 scipy==1.2.1 scikit-learn pillow tensorflow==1.1.0 pandas==0.19.1 h5py==2.7.0 opencv-python==3.2.0.8 keras==2.0.5 statistics pyyaml pyparsing cycler matplotlib Flask

ADD . /ekholabs/face-classifier

WORKDIR ekholabs/face-classifier

ENV PYTHONPATH=$PYTHONPATH:src
ENV FACE_CLASSIFIER_PORT=8084
EXPOSE $FACE_CLASSIFIER_PORT

ENTRYPOINT ["python3"]
CMD ["src/web/faces.py"]

感谢,你的回复很重要,解决了问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants