Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Cannot feed value of shape (50, 128, 128, 3) for Tensor 'FID_Inception_Net/ExpandDims:0', which has shape '(1, ?, ?, 3) #6

Open
uuutty opened this issue May 8, 2018 · 17 comments

Comments

@uuutty
Copy link

uuutty commented May 8, 2018

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

@HRamses
Copy link
Collaborator

HRamses commented May 8, 2018

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.

@foofighter112
Copy link

foofighter112 commented May 14, 2018

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.

@goncalomordido
Copy link

It seems to match my previous results! Thanks.

@HRamses
Copy link
Collaborator

HRamses commented May 15, 2018

@foofighter112 : Thanks! Would it be ok for you if I adopt your solution after doing some correctness tests?

@foofighter112
Copy link

foofighter112 commented May 15, 2018 via email

@uuutty
Copy link
Author

uuutty commented May 16, 2018

@foofighter112 I find it work well for me, Thanks!

@youkaichao
Copy link

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

@congyucn
Copy link

congyucn commented Sep 5, 2018

@foofighter112 I used your code, but it still doesn't work. My Tf is 1.4.0

@WillSuen
Copy link

WillSuen commented Sep 8, 2018

Tensorflow version 1.4.0, still get the same error
change batch_size to 1 can fix this error, but running speed is slow

@happycoding1996
Copy link

@WillSuen I got the same issue on 1.4.0. Super slow running speed when using batch size 1.

@kabef94
Copy link

kabef94 commented Nov 12, 2018

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.

Hi.. I'm a little new to python.. where exactly should this be changed??

@hhqweasd
Copy link

hhqweasd commented Feb 2, 2019

replace
o.dict['_shape_val'] = tf.TensorShape(new_shape)
with
o._shape = tf.TensorShape(new_shape)
Done!

@Sanka-R
Copy link

Sanka-R commented Mar 6, 2019

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

@youngjung
Copy link

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 worked for tf 1.5.0 + python 3.6.7

youngjung pushed a commit to youngjung/TTUR that referenced this issue Apr 18, 2019
@zhangxixi0904
Copy link

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

@echooooHsu
Copy link

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

@jian3xiao
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests