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

updated tfutil for tensorflow 2.x #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dnnlib/tflib/tfutil.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
#
# This work is licensed under the Creative Commons Attribution-NonCommercial
# 4.0 International License. To view a copy of this license, visit
Expand Down Expand Up @@ -31,7 +31,7 @@ def is_tf_expression(x: Any) -> bool:
return isinstance(x, (tf.Tensor, tf.Variable, tf.Operation))


def shape_to_list(shape: Iterable[tf.Dimension]) -> List[Union[int, None]]:
def shape_to_list(shape: Iterable[tf.compat.v1.Dimension]) -> List[Union[int, None]]:
"""Convert a Tensorflow shape to a list of ints."""
return [dim.value for dim in shape]

Expand Down Expand Up @@ -71,7 +71,7 @@ def absolute_name_scope(scope: str) -> tf.name_scope:
return tf.name_scope(scope + "/")


def absolute_variable_scope(scope: str, **kwargs) -> tf.variable_scope:
def absolute_variable_scope(scope: str, **kwargs) -> tf.compat.v1.variable_scope:
"""Forcefully enter the specified variable scope, ignoring any surrounding scopes."""
return tf.variable_scope(tf.VariableScope(name=scope, **kwargs), auxiliary_name_scope=False)

Expand Down Expand Up @@ -125,7 +125,7 @@ def assert_tf_initialized():
raise RuntimeError("No default TensorFlow session found. Please call dnnlib.tflib.init_tf().")


def create_session(config_dict: dict = None, force_as_default: bool = False) -> tf.Session:
def create_session(config_dict: dict = None, force_as_default: bool = False) -> tf.compat.v1.Session:
"""Create tf.Session based on config dict."""
# Setup TensorFlow config proto.
cfg = _sanitize_tf_config(config_dict)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 132, I had to also update

config_proto =  tf.compat.v1.ConfigProto()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, do you have full working code for this repo but using tf 2.x?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atreeleaf I'll review the codebase again and replace any other depreciated functions. Thanks for bringing this to my attention

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atreeleaf @PsVenom
Hi all! Is there a running Tensorflow2 compatible StyleGAN2 Colab notebook? Thank you!

Expand Down