face_classification icon indicating copy to clipboard operation
face_classification copied to clipboard

ImportError: cannot import name 'imread'

Open Tyler-Hilbert opened this issue 5 years ago • 4 comments

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.

Tyler-Hilbert avatar Jun 20 '19 22:06 Tyler-Hilbert

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.

hiro-24 avatar Jun 26 '19 06:06 hiro-24

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

o0Roy avatar Sep 03 '19 08:09 o0Roy

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"]

enric1994 avatar Oct 16 '19 10:10 enric1994

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 avatar Nov 04 '19 09:11 rovesoul