0

I'm new to tensorflow and I tried using the script mentioned in Tensorflow: use pretrained inception model to avoid using a TF Record but all my predictions end up in the same wrong class. The evaluation classifier however produces correct results, so it's not the model, I believe the pre processing is what I'm doing wrong.

So I decided to try the inception preprocessing function but now it won't accept my jpgs. I get this error:

inception_preprocessing.py", line 265, in preprocess_for_eval
    image = tf.image.central_crop(image, central_fraction=central_fraction)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/image_ops_impl.py", line 335, in central_crop
    _Check3DImage(image, require_static=False)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/image_ops_impl.py", line 129, in _Check3DImage
    raise ValueError("'image' must be three-dimensional.")
ValueError: 'image' must be three-dimensional.

Here's my code:

arg_scope = inception_utils.inception_arg_scope()
im_size = 299

inputs = tf.placeholder(tf.float32, (None, im_size, im_size, 3))
inputs = inception_preprocessing.preprocess_image(inputs, im_size, im_size)

with slim.arg_scope(arg_scope):
  logits, end_points = inception_v4.inception_v4(inputs)

saver = tf.train.Saver()
saver.restore(sess,ckpt_file)

for image in sample_img:
  im = Image.open(image)
  im = im.resize((im_size,im_size))
  im = np.array(im)

  logit_values = sess.run(logits, feed_dict={inputs:im})

  print(np.argmax(logit_values))
rapaterno
  • 626
  • 4
  • 6

1 Answers1

0
inputs_processed = inception_preprocessing.preprocess_image(tf.squeeze(inputs), im_size, im_size)
inputs_processed = tf.expand_dims(inputs_processed, 0)
with slim.arg_scope(arg_scope):
    logits, end_points = inception_v4.inception_v4(inputs_processed)
# placeholder feed value should be 4D
im = np.exapnd_dims(np.array(im), 0)
Ishant Mrinal
  • 4,898
  • 3
  • 29
  • 47