简体   繁体   中英

convolutional neural network- how to use two cnn model on same image

I want to use two differently trained CNN (convolutional neural network) modules on the same image. I trained the two modules, 1 for detection and one for classification. Now, I want to use these two modules on the same image. The code is in python using the keras and tensorflow libraries. Two different CNN on the same image

In tensorflow you need to explicitly specify the computational graph for both of your models.

# build two separate graphs `g1` and `g2`

tf.reset_default_graph()
with tf.Session(graph=g1) as session:
    result = sess.run(detect, feed_dict={x: test_x})
    print(result)

tf.reset_default_graph()
with tf.Session(graph=g2) as session:
    result = sess.run(recognize, feed_dict={x: test_x})
    print(result)

There are also some caveats when multiple graphs are built in one application, see this question .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM