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

Cannot interpret feed_dict key as Tensor in face.py #86

Closed 1vash closed 6 years ago

1vash commented 6 years ago

I run faces.py script in docker container with Ubuntu 16.04 xenial. When using the 2nd query for image classification I get internal server error with the error traceback below.

* Running on http://0.0.0.0:8084/ (Press CTRL+C to quit)
2018-08-30 10:40:11.966716: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2018-08-30 10:40:11.966803: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2018-08-30 10:40:11.966820: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2018-08-30 10:40:11.966831: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2018-08-30 10:40:11.966841: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
[ INFO:0] Initialize OpenCL runtime...
172.18.0.1 - - [30/Aug/2018 10:40:13] "POST /classifyImage HTTP/1.1" 200 -
[2018-08-30 10:40:30,175] ERROR in app: Exception on /classifyImage [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py", line 930, in _run
    allow_operation=False)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 2414, in as_graph_element
    return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 2493, in _as_graph_element_locked
    raise ValueError("Tensor %s is not an element of this graph." % obj)
ValueError: Tensor Tensor("Placeholder:0", shape=(3, 3, 1, 8), dtype=float32) is not an element of this graph.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/dist-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "faces.py", line 18, in upload
    eg_processor.process_image(image)
  File "/usr/src/app/src/web/emotion_gender_processor.py", line 42, in process_image
    emotion_classifier = load_model(emotion_model_path, compile=False)
  File "/usr/local/lib/python3.6/dist-packages/keras/models.py", line 249, in load_model
    topology.load_weights_from_hdf5_group(f['model_weights'], model.layers)
  File "/usr/local/lib/python3.6/dist-packages/keras/engine/topology.py", line 3008, in load_weights_from_hdf5_group
    K.batch_set_value(weight_value_tuples)
  File "/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py", line 2189, in batch_set_value
    get_session().run(assign_ops, feed_dict=feed_dict)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py", line 778, in run
    run_metadata_ptr)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py", line 933, in _run
    + e.args[0])
TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(3, 3, 1, 8), dtype=float32) is not an element of this graph.
172.18.0.1 - - [30/Aug/2018 10:40:30] "POST /classifyImage HTTP/1.1" 500 -

Ubuntu: 16.04 Requirements Package Version


chardet 2.3.0
click 6.7
cycler 0.10.0
docutils 0.14
Flask 1.0.2
h5py 2.7.0
itsdangerous 0.24
Jinja2 2.10
Keras 2.0.5
kiwisolver 1.0.1
MarkupSafe 1.0
matplotlib 2.2.3
numpy 1.12.1
opencv-python 3.2.0.8
pandas 0.19.1
Pillow 5.2.0
pip 18.0
protobuf 3.6.1
pycurl 7.43.0
pygobject 3.20.0
pyparsing 2.2.0
python-apt 1.1.0b1+ubuntu0.16.4.2 python-dateutil 2.7.3
pytz 2018.5
PyYAML 3.13
requests 2.9.1
scipy 1.1.0
setuptools 40.2.0
six 1.11.0
ssh-import-id 5.5
statistics 1.0.3.5
tensorflow 1.1.0
Theano 1.0.2
unattended-upgrades 0.1
urllib3 1.13.1
Werkzeug 0.14.1
wheel 0.31.1

I've also tried downgrade and upgrade some packages ( tensorflow==1.9 , keras==2.2.0, opencv-python==3.4.0.12, numpy==1.14.2, pandas==0.23.4) But the bug is stayed untouched.

What it can be and how I can fix this? Help please to solve this issue. By the way it happens only on linux ubuntu, on my MacOS all works great

Updated: I have tried to build Dockerfile that was in the root folder (with Debian image), nothing has been changed or added. Commands docker build -t face . docker run -td face docker exec -ti CONTAINER ID bash curl -v -F image=@90.jpg http://localhost:8084/classifyImage > image.png

So, the output is the same, after 2 query on Flask /classifyImage API I get the Error described above

But the funny story is when I tried download image docker pull ekholabs/face-classifier and test this image --> all worked correctly!

I believe that the problem is inside installed packaged, something has been changed but I couldn't find what package is exactly differs from what had been used during the building image so times before

1vash commented 6 years ago

I found what was wrong. Package version of Flask has to be hardcoded == 0.12.2