I am doing instance detect and image retrieval task by Keras and Tensorflow as backend.
I plan to use multi thread to load two model, I load maskrcnn in a thread and load mobile net in another one.
I load the maskrcnn in a thread successfully, but I failed to load mobile net in another thread, and:
show:ValueError: tensor a must be from the same graph as tensor b.
The code is as below:
Merge.py
from keras import backend as K
g1=tf.Graph()
g2=tf.Graph()
sess1=tf.Session(graph=g1)
sess2=tf.Session(graph=g2)
def intiMaskrcnn():
with g1.as_default():
with sess1.as_default():
Model1=........
def instanceDetect():
K.set_session(sess1)
with g1.as_default():
Model1.predit()
............
def intiMobilenet():
with g2.as_default():
with sess2.as_default():
Model2=........
def Retrieval():
K.set_session(sess2)
with g2.as_default():
Model2.predit()
............
Thread1.py
intiMaskrcnn()
instanceDetect()
Thread2.py
intiMobilenet()
Retrieval()
Where am I going wrong?