How to feed Cifar10 trained model with my own image and get label as output?

后端 未结 2 1339
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 21:44

I am trying to use the trained model based on the Cifar10 tutorial and would like to feed it with an external image 32x32 (jpg or png).
My goal is to be able to get

2条回答
  •  盖世英雄少女心
    2021-01-13 22:38

    The original source code in cifar10_eval.py can also be used for testing own individual images as it is shown in the following console output

    nbatfai@robopsy:~/Robopsychology/repos/gpu/tensorflow/tensorflow/models/image/cifar10$ python cifar10_eval.py --run_once True 2>/dev/null
    [ -0.63916457  -3.31066918   2.32452989   1.51062226  15.55279636
    -0.91585422   1.26451302  -4.11891603  -7.62230825  -4.29096413]
    deer
    nbatfai@robopsy:~/Robopsychology/repos/gpu/tensorflow/tensorflow/models/image/cifar10$ python cifar2bin.py matchbox.png input.bin 
    nbatfai@robopsy:~/Robopsychology/repos/gpu/tensorflow/tensorflow/models/image/cifar10$ python cifar10_eval.py --run_once True 2>/dev/null
    [ -1.30562115  12.61497402  -1.34208572  -1.3238833   -6.13368177
    -1.17441642  -1.38651907  -4.3274951    2.05489922   2.54187846]
    automobile
    nbatfai@robopsy:~/Robopsychology/repos/gpu/tensorflow/tensorflow/models/image/cifar10$ 
    

    and code snippet

    #while step < num_iter and not coord.should_stop():
    # predictions = sess.run([top_k_op])
    print(sess.run(logits[0]))
    classification = sess.run(tf.argmalogits[0], 0))
    cifar10classes = ["airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck"]
    print(cifar10classes[classification])
    
    #true_count += np.sum(predictions)
    step += 1
    
    # Compute precision @ 1.
    precision = true_count / total_sample_count
    # print('%s: precision @ 1 = %.3f' % (datetime.now(), precision))
    

    More details can be found in the post How can I test own image to Cifar-10 tutorial on Tensorflow?

提交回复
热议问题