From 0ec44407450fdbcf589898d83f8d3ac1d01ef3d5 Mon Sep 17 00:00:00 2001 From: Ayyuce Demirbas Date: Sun, 18 Jul 2021 18:02:21 +0300 Subject: [PATCH 1/3] TensorFlow 2.x compatibility These lines solve "AttributeError: module 'tensorflow' has no attribute 'python_io'" problem --- dataset_tool.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dataset_tool.py b/dataset_tool.py index d8c4dc28..56aa1490 100755 --- a/dataset_tool.py +++ b/dataset_tool.py @@ -15,7 +15,8 @@ import six.moves.queue as Queue # pylint: disable=import-error import traceback import numpy as np -import tensorflow as tf +import tensorflow.compat.v1 as tf +tf.disable_v2_behavior() import PIL.Image import dnnlib.tflib as tflib From 2f02378aac608fcc1f8bbb8763aa402bacf3081c Mon Sep 17 00:00:00 2001 From: Ayyuce Demirbas Date: Sun, 18 Jul 2021 18:05:23 +0300 Subject: [PATCH 2/3] TensorFlow 2.x compatibility These lines solve "AttributeError: module 'tensorflow._api.v2.train' has no attribute 'Optimizer'" problem --- dnnlib/tflib/optimizer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dnnlib/tflib/optimizer.py b/dnnlib/tflib/optimizer.py index 9389b5ad..7e71b486 100755 --- a/dnnlib/tflib/optimizer.py +++ b/dnnlib/tflib/optimizer.py @@ -8,7 +8,8 @@ import platform import numpy as np -import tensorflow as tf +import tensorflow.compat.v1 as tf +tf.disable_v2_behavior() from collections import OrderedDict from typing import List, Union From d0d9334cdd3a1f4340647296e5dc74cde28639a8 Mon Sep 17 00:00:00 2001 From: Ayyuce Demirbas Date: Sun, 18 Jul 2021 18:09:59 +0300 Subject: [PATCH 3/3] TensorFlow 2.x compatibility These two lines are not required: import tensorflow.contrib tf.contrib = tensorflow.contrib it works perfectly without them. --- dnnlib/tflib/tfutil.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dnnlib/tflib/tfutil.py b/dnnlib/tflib/tfutil.py index 1127c7be..68a0539d 100755 --- a/dnnlib/tflib/tfutil.py +++ b/dnnlib/tflib/tfutil.py @@ -8,13 +8,15 @@ import os import numpy as np -import tensorflow as tf +import tensorflow.compat.v1 as tf +tf.disable_v2_behavior() + # Silence deprecation warnings from TensorFlow 1.13 onwards import logging logging.getLogger('tensorflow').setLevel(logging.ERROR) -import tensorflow.contrib # requires TensorFlow 1.x! -tf.contrib = tensorflow.contrib +#import tensorflow.contrib # requires TensorFlow 1.x! +#tf.contrib = tensorflow.contrib from typing import Any, Iterable, List, Union