trying to run styleGAN in jyputer notebook, it says "tensorflow' has no attribute 'Dimension"

3.3k Views Asked by At

enter image description here!python encode_images.py --optimizer=lbfgs --face_mask=True --iterations=6 --use_lpips_loss=0 --use_discriminator_loss=0 --output_video=True aligned_images/ generated_images/ latent_representations/

print("\n************ Latent code optimization finished! ***************")

2021-08-24 13:33:11.033451: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll

Traceback (most recent call last): File "encode_images.py", line 12, in import dnnlib.tflib as tflib File "C:\Users\bkvij\Office Rapid Innovation\StyleGAN Face Morphing - Arxiv Insights\stylegan-encoder\dnnlib\tflib_init_.py", line 8, in

from . import autosummary File "C:\Users\bkvij\Office Rapid Innovation\StyleGAN Face Morphing - Arxiv Insights\stylegan-encoder\dnnlib\tflib\autosummary.py", line 31, in

from . import tfutil File "C:\Users\bkvij\Office Rapid Innovation\StyleGAN Face Morphing - Arxiv Insights\stylegan-encoder\dnnlib\tflib\tfutil.py", line 34, in

def shape_to_list(shape: Iterable[tf.Dimension]) -> List[Union[int, None]]: AttributeError: module 'tensorflow' has no attribute 'Dimension'

4

There are 4 best solutions below

0
On

To expand on Faezeh's answer, you'll have to make the following edits to tfutils.py

From tf.Dimension (line 34) tf.variable_scope (line 74) tf.Session (line 128)

To tf.compat.v1.Dimension tf.compat.v1.variable_scope tf.compat.v1.Session

alternatively, you could just download tensorflow 1.x and save yourself the hassle

0
On

I think you're using TensorFlow v2, use google colape and it will fix the problem for you, otherwise, you will need to make a virtual environment with Python 3.6 TensorFlow 1.10 cuDNN 7.3.1 and it will solve the problem

0
On

It's because tf.Dimension is deprecated.

Go to stylegan/dnnlib/tflib/tfutil.py and change the tf.Dimension in line 34 to tf.compat.v1.Dimension.

1
On

you can use it on terminal ' pip install tensorflow-addons==0.14.0