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: Shape of a new variable (ref_img_features) must be fully defined, but instead was (?, 64, 64, 256) #11

Open
Fresh-Orange opened this issue Mar 29, 2019 · 2 comments

Comments

@Fresh-Orange
Copy link

When I run “python3 encode_images.py aligned_images/ generated_images/ latent_representations/”,I get the errer:

Traceback (most recent call last):
File "encode_images.py", line 86, in
main()
File "encode_images.py", line 61, in main
perceptual_model.build_perceptual_model(generator.generated_image)
File "/media/data2/laixc/stylegan-encoder/encoder/perceptual_model.py", line 41, in build_perceptual_model
dtype='float32', initializer=tf.initializers.zeros())
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/variable_scope.py", line 1328, in get_variable
constraint=constraint)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/variable_scope.py", line 1090, in get_variable
constraint=constraint)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/variable_scope.py", line 435, in get_variable
constraint=constraint)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/variable_scope.py", line 404, in _true_getter
use_resource=use_resource, constraint=constraint)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/variable_scope.py", line 764, in _get_single_variable
"but instead was %s." % (name, shape))
ValueError: Shape of a new variable (ref_img_features) must be fully defined, but instead was (?, 64, 64, 256).

@YZ576023775
Copy link

the same error,have you solved it?

@Fresh-Orange
Copy link
Author

the same error,have you solved it?

Yes, I solved it by modifying the following two lines in perceptual_model.py

self.ref_img_features = tf.get_variable('ref_img_features', shape=generated_img_features.shape,
                                                dtype='float32', initializer=tf.initializers.zeros())

self.features_weight = tf.get_variable('features_weight', shape=generated_img_features.shape,
                                               dtype='float32', initializer=tf.initializers.zeros())

to

in_shape = (1, generated_img_features.shape[1], generated_img_features.shape[2], generated_img_features.shape[3])

self.ref_img_features = tf.get_variable('ref_img_features',
                                                shape=in_shape,
                                                dtype='float32', initializer=tf.initializers.zeros())

self.features_weight = tf.get_variable('features_weight', shape=in_shape,
                                               dtype='float32', initializer=tf.initializers.zeros())

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

2 participants