TensorFlow ValueError: Cannot feed value of shape (64, 64, 3) for Tensor u'Placeholder:0', which has shape '(?, 64, 64, 3)'

前端 未结 2 2028
一生所求
一生所求 2020-11-30 00:04

I am new to TensorFlow and machine learning. I am trying to classify two objects a cup and a pendrive (jpeg images). I have trained and exported a model.ckpt successfully. N

相关标签:
2条回答
  • 2020-11-30 00:13

    image has a shape of (64,64,3).

    Your input placeholder _x have a shape of (?, 64,64,3).

    The problem is that you're feeding the placeholder with a value of a different shape.

    You have to feed it with a value of (1, 64, 64, 3) = a batch of 1 image.

    Just reshape your image value to a batch with size one.

    image = array(img).reshape(1, 64,64,3)
    

    P.S: the fact that the input placeholder accepts a batch of images, means that you can run predicions for a batch of images in parallel. You can try to read more than 1 image (N images) and than build a batch of N image, using a tensor with shape (N, 64,64,3)

    0 讨论(0)
  • 2020-11-30 00:17

    Powder's comment may go undetected like I missed it so many times,. So with the hope of making it more visible, I will re-iterate his point.

    Sometimes using image = array(img).reshape(a,b,c,d) will reshape alright but from experience, my kernel crashes every time I try to use the new dimension in an operation. The safest to use is

    np.expand_dims(img, axis=0)

    It works perfect every time. I just can't explain why. This link has a great explanation and examples regarding its usage.

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