ValueError: Tensor 'A' must be from the same graph as Tensor 'B' ValueError: Tensor 'A' must be from the same graph as Tensor 'B' flask flask

ValueError: Tensor 'A' must be from the same graph as Tensor 'B'


you'll need open different session and specify which graph goes with each session, else Keras will replace each graph as default.

from tensorflow import Graph, Session, load_modelfrom Keras import backend as K

Loading the graphs:

graph1 = Graph()    with graph1.as_default():        session1 = Session()        with session1.as_default():            model = load_model(foo.h5)graph2 = Graph()    with graph2.as_default():        session2 = Session()        with session2.as_default():            model2 = load_model(foo2.h5)

Predicting/Using the graphs:

K.set_session(session1)    with graph1.as_default():        result = model.predict(data)


The problem here is your loop. You're trying to generate a new graph in each iteration.

This line

model = ResNet50(weights='imagenet')

Should only be called once. So either define it as a global variable or create it before and pass it as a parameter to getResNet50Prediction()