How can I test own image to Cifar-10 tutorial on Tensorflow?

后端 未结 1 1461
野趣味
野趣味 2021-01-22 19:12

I trained Tensorflow Cifar10 model and I would like to feed it with own single image (32*32, jpg/png).

I want to see label and probability of each label as an output, bu

相关标签:
1条回答
  • 2021-01-22 19:54

    The video https://youtu.be/d9mSWqfo0Xw shows an example for classifying a single image.

    After the network has already trained by python cifar10_train.py we evaluate the individual image deer6.png of CIFAR-10 database and an own photo of a matchbox. The most important modifications of the original source code of the TF tutorial are the following:

    First it is necessary to convert these images to a binary form that the cifar10_input.py can read. It can be done easily by using the code snippet that can be found at How to create dataset similar to cifar-10

    Then in order to read the converted images (called input.bin) we need modify the function input() in cifar10_input.py:

      else:
        #filenames = [os.path.join(data_dir, 'test_batch.bin')]
        filenames = [os.path.join(data_dir, 'input.bin')]
    

    (data_dir is equal to './')

    Finally to get the label we have modify the function eval_once() in source cifar10_eval.py:

          #while step < num_iter and not coord.should_stop():
          #  predictions = sess.run([top_k_op])
          print(sess.run(logits[0]))
          classification = sess.run(tf.argmax(logits[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))
    

    And of course there are some small modifications that you will need to make.

    0 讨论(0)
提交回复
热议问题