improved-gan icon indicating copy to clipboard operation
improved-gan copied to clipboard

Batch size mismatch with Inception classifier

Open catherio opened this issue 6 years ago • 10 comments

With Tensorflow 1.6.0, the line pred = sess.run(softmax, {'ExpandDims:0': inp}) raises an error because the input to the softmax in the Inception classifier expects a batch dimension of 1:

ValueError: Cannot feed value of shape (100, 32, 32, 3) for Tensor u'ExpandDims:0', which has shape '(1, ?, ?, 3)'

I assume this didn't used to be the case? For now I've patched my local fork to hardcode bs = 1, but I assume that's not the optimal fix here.

If I drop a breakpoint right before that line to show what I'm calling this with:

ipdb> len(images)
1000
ipdb> inp.shape
(100, 32, 32, 3)
ipdb> tf.get_default_graph().get_tensor_by_name("ExpandDims:0")
<tf.Tensor 'ExpandDims:0' shape=(1, ?, ?, 3) dtype=float32>

catherio avatar Mar 29 '18 01:03 catherio

I have the same exact issue. I tried Tensorflow version 1.5 and 1.6 and it is same in both the cases. Really appreciate your help in resolving this.

ptirupat avatar Apr 03 '18 16:04 ptirupat

I have the same issue.

alexanderhanboli avatar Apr 23 '18 06:04 alexanderhanboli

Any updates on this issue?

kritiagg avatar Apr 25 '18 20:04 kritiagg

An old version of tensorflow works.

HMJiangGatech avatar Apr 27 '18 15:04 HMJiangGatech

Yes, tf version 1.3 works.

kritiagg avatar May 06 '18 22:05 kritiagg

How should it work with tf version 1.3? It is not even working with version 1.2.1! https://github.com/tensorflow/tensorflow/issues/1021 With the provided model, only batch sizes of 1 are working.

moniDLpro avatar May 07 '18 13:05 moniDLpro

how to fix this issue with tf version 1.8 ? thks

IPNUISTlegal avatar Jul 30 '18 08:07 IPNUISTlegal

tf.contrib.gan.eval has functions that work in recent tensorflows.

Changing o._shape = ... to o.set_shape(...), as in #31, doesn't seem to have worked, because set_shape merges shape information instead of overriding it: https://github.com/tensorflow/tensorflow/issues/5680#issuecomment-404397495

djsutherland avatar Aug 17 '18 17:08 djsutherland

Any updates on how to solve this? Or any alternatives?

gargrohin avatar Aug 17 '20 08:08 gargrohin

Hi, Everyone for those who still have a problem, please, make sure that images have a channel-last format (h x w x 3). I hope it may help ... I had the same problem, I confused Pytorch with Tensorflow format.

Kilichbek avatar Mar 04 '21 14:03 Kilichbek