oarriaga / face_classification

Real-time face detection and emotion/gender classification using fer2013/imdb datasets with a keras CNN model and openCV.
MIT License
5.61k stars 1.59k forks source link

ImportError: cannot import name 'imread' #115

Open Tyler-Hilbert opened 5 years ago

Tyler-Hilbert commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

enric1994 commented 5 years ago

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 commented 5 years ago

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

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