naturomics / CapsNet-Tensorflow

A Tensorflow implementation of CapsNet(Capsules Net) in paper Dynamic Routing Between Capsules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to test a new image?

ycrjycm opened this issue · comments

commented

Hi,

If I want to load an image and get its softmax score, How to write the script?
I've been trying several hours, since I'm a beginner in tensorflow and it's kind diffcult for me.

    with tf.Graph().as_default():
        image = tf.cast(image_arr, tf.float32)
        image = tf.image.per_image_standardization(image)
        image = tf.reshape(image, [1,28, 28, 1])
        #x = tf.placeholder(tf.float32,shape = [1,28, 28, 1])
        feature=CapsNet.test_net(image)
        logits = tf.nn.softmax(feature)
        #saver = tf.train.Saver()
        aaa=1
        with tf.Session() as sess:
            saver = tf.train.import_meta_graph('./logdir/model_epoch_0048_step_23899.meta')
            saver.restore(sess, './logdir/model_epoch_0048_step_23899')
            print(image.shape)
            test_result = sess.run(aaa,image)