ValueError: Cannot feed value of shape (50, 128, 128, 3) for Tensor 'FID_Inception_Net/ExpandDims:0', which has shape '(1, ?, ?, 3)
uuutty opened this issue · comments
I met a error for 'tf.Tensor._shape cannot be assigned', so I change the
o._shape = tf.TensorShape(new_shape)
to
o.set_shape(tf.TensorShape(new_shape))
mentioned by another project's commit
Unfortunately, this work fine for above project, but this time I still get a
ValueError: Cannot feed value of shape (50, 128, 128, 3) for Tensor 'FID_Inception_Net/ExpandDims:0', which has shape '(1, ?, ?, 3)
.
I find if I print the tensor shape use get_shape()
before and after the set_shape
call in function _get_inception_layer
, the Tensor shape don't change. It seems the set_shape
don't work.
Does anyone have any ideas? Thanks
Hi!
The problem seems to be, that in newer versions of Tf it is not possible to "lower" the information about a dimension of a given tensor, as is explained here: https://stackoverflow.com/questions/35451948/clarification-on-tf-tensor-set-shape
That's why I suspect, that the "fix" you are referring to doesn't really work.
I will try to find a solution.
Hi, I also noticed that it is not possible to change shapes of tensors which were created with validate_shape=True
(see tensorflow/tensorflow#5492), which might be the culprit here.
I changed the _get_inception_layer
function in a hacky way to make it run, and I update the shape by doing o.__dict__['_shape_val'] = tf.TensorShape(new_shape)
. I also changed if shape._dims is not None:
to if shape._dims != []:
Here is my function.
def _get_inception_layer(sess):
"""Prepares inception net for batched usage and returns pool_3 layer. """
layername = 'FID_Inception_Net/pool_3:0'
pool3 = sess.graph.get_tensor_by_name(layername)
ops = pool3.graph.get_operations()
for op_idx, op in enumerate(ops):
for o in op.outputs:
shape = o.get_shape()
if shape._dims != []:
shape = [s.value for s in shape]
new_shape = []
for j, s in enumerate(shape):
if s == 1 and j == 0:
new_shape.append(None)
else:
new_shape.append(s)
o.__dict__['_shape_val'] = tf.TensorShape(new_shape)
return pool3
I suspect the returned FID scores are still correct, but I haven't checked against reported scores.
It seems to match my previous results! Thanks.
@foofighter112 : Thanks! Would it be ok for you if I adopt your solution after doing some correctness tests?
@foofighter112 I find it work well for me, Thanks!
@foofighter112 I test your code with batch size 128 on cifar10 real data and get FID of 7.2
Then I test original code with batch size 1 on cifar10 real data and get FID of 7.1
so your code works well.
(I randomly select 10000 images from [0, 25000) and [25000. 50000) in training data and test the FID.)
@foofighter112 I used your code, but it still doesn't work. My Tf is 1.4.0
Tensorflow version 1.4.0, still get the same error
change batch_size
to 1 can fix this error, but running speed is slow
@WillSuen I got the same issue on 1.4.0. Super slow running speed when using batch size 1.
Hi, I also noticed that it is not possible to change shapes of tensors which were created with
validate_shape=True
(see tensorflow/tensorflow#5492), which might be the culprit here.I changed the
_get_inception_layer
function in a hacky way to make it run, and I update the shape by doingo.__dict__['_shape_val'] = tf.TensorShape(new_shape)
. I also changedif shape._dims is not None:
toif shape._dims != []:
Here is my function.
def _get_inception_layer(sess): """Prepares inception net for batched usage and returns pool_3 layer. """ layername = 'FID_Inception_Net/pool_3:0' pool3 = sess.graph.get_tensor_by_name(layername) ops = pool3.graph.get_operations() for op_idx, op in enumerate(ops): for o in op.outputs: shape = o.get_shape() if shape._dims != []: shape = [s.value for s in shape] new_shape = [] for j, s in enumerate(shape): if s == 1 and j == 0: new_shape.append(None) else: new_shape.append(s) o.__dict__['_shape_val'] = tf.TensorShape(new_shape) return pool3
I suspect the returned FID scores are still correct, but I haven't checked against reported scores.
Hi.. I'm a little new to python.. where exactly should this be changed??
replace
o.dict['_shape_val'] = tf.TensorShape(new_shape)
with
o._shape = tf.TensorShape(new_shape)
Done!
I am still having this issue, this fix didnt work
pyathon 3.6.8
tf 1.5.1
changing the batch size to 1 also didnt work
Hi, I also noticed that it is not possible to change shapes of tensors which were created with
validate_shape=True
(see tensorflow/tensorflow#5492), which might be the culprit here.I changed the
_get_inception_layer
function in a hacky way to make it run, and I update the shape by doingo.__dict__['_shape_val'] = tf.TensorShape(new_shape)
. I also changedif shape._dims is not None:
toif shape._dims != []:
Here is my function.
def _get_inception_layer(sess): """Prepares inception net for batched usage and returns pool_3 layer. """ layername = 'FID_Inception_Net/pool_3:0' pool3 = sess.graph.get_tensor_by_name(layername) ops = pool3.graph.get_operations() for op_idx, op in enumerate(ops): for o in op.outputs: shape = o.get_shape() if shape._dims != []: shape = [s.value for s in shape] new_shape = [] for j, s in enumerate(shape): if s == 1 and j == 0: new_shape.append(None) else: new_shape.append(s) o.__dict__['_shape_val'] = tf.TensorShape(new_shape) return pool3
I suspect the returned FID scores are still correct, but I haven't checked against reported scores.
It worked for tf 1.5.0 + python 3.6.7
replace
o.dict['_shape_val'] = tf.TensorShape(new_shape)
with
o._shape = tf.TensorShape(new_shape)
Done!
it works for tensorflow 1.14.1 python3.5
replace
o.dict['_shape_val'] = tf.TensorShape(new_shape)
with
o._shape = tf.TensorShape(new_shape)
Done!
it works for tensorflow 1.4.0 python3.6
when using two image files to compute FID, the code use get_activations_from_files() ,there is maybe a mistake in 222 "n_batches = n_imgs//batch_size + 1". I think '+1' should be removed.