jrosebr1/simple-keras-rest-api

Getting Value() error

anujgupta82 opened this issue · 4 comments

I cloned this code with

Keras==2.1.5
tensorflow==1.7.0

When I send a request I am getting

File "/home/root1/.virtualenv/MyDir/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3557, in _as_graph_element_locked
raise ValueError("Tensor %s is not an element of this graph." % obj)

Below is complete screen shot of the error

bug1

Any suggestions will be of great help

This is resolved.
This is a very well researched problem. The solution is given in Issue #1

def load_model():
	global model
	model = ResNet50(weights="imagenet")
            # this is key : save the graph after loading the model
	global graph
	graph = tf.get_default_graph()

While predicting, use the same graph

    with graph.as_default():
	preds = model.predict(image)
	#... etc

Congrats on resolving the issue @anujgupta82 and thank you for sharing the relevant links just in case others have this problem.

This works for the developmental server, but it does not work if you want to use a standalone wsgi container e.g. gunicorn, gevent, uwsgi.

Also there is another solution if you just want to get the model to work. Essentially just get rid of the load_model() function.
run_keras_server.txt

The above works on the standalone wsgi containers but not on the
Flask developmental server ???
Is there a solution that works for all cases?

Hey @johncleveland, please don't copy and paste the same question into multiple threads. Your question has already been addressed and answered in #1. Thanks.