Tensorflow:图像预处理启动v4不接受我的jpg

时间:2017-08-06 13:31:42

标签: python machine-learning tensorflow deep-learning

我是tensorflow的新手,我尝试使用Tensorflow: use pretrained inception model中提到的脚本来避免使用TF记录,但我的所有预测最终都在同一个错误的类中。然而,评估分类器产生了正确的结果,因此它不是模型,我相信预处理是我做错了。

所以我决定尝试初始预处理功能,但现在它不接受我的jpgs。我收到这个错误:

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.

这是我的代码:

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))

1 个答案:

答案 0 :(得分: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)