Tensor is not an element of this graph; deploying Keras model

前端 未结 6 874
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-28 15:30

Im deploying a keras model and sending the test data to the model via a flask api. I have two files:

First: My Flask App:

# Let\'s startup the Flask          


        
6条回答
  •  梦毁少年i
    2020-12-28 16:36

    Flask uses multiple threads. The problem you are running into is because the tensorflow model is not loaded and used in the same thread. One workaround is to force tensorflow to use the gloabl default graph .

    Add this after you load your model

    global graph
    graph = tf.get_default_graph() 
    

    And inside your predict

    with graph.as_default():
        y_hat = keras_model_loaded.predict(predict_request, batch_size=1, verbose=1)
    

提交回复
热议问题