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

TensorFlow 2.x compatibility #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ayyucedemirbas
Copy link

No description provided.

These lines solve "AttributeError: module 'tensorflow' has no attribute 'python_io'" problem
These lines solve "AttributeError: module 'tensorflow._api.v2.train' has no attribute 'Optimizer'" problem
These two lines are not required:

import tensorflow.contrib   
tf.contrib = tensorflow.contrib

it works perfectly without them.
@kumari-jaya
Copy link

After solving all the compatibility issue using compat.v1 , faced following error:

python3 project_images.py --num-steps 500 aligned generated
2021-08-06 09:38:22.811302: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0
Loading networks from "http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-ffhq-config-f.pkl"...
2021-08-06 09:38:24.021056: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 AVX512F FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-08-06 09:38:24.022195: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcuda.so.1
2021-08-06 09:38:24.067701: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-08-06 09:38:24.068318: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1733] Found device 0 with properties:
pciBusID: 0000:00:1e.0 name: Tesla T4 computeCapability: 7.5
coreClock: 1.59GHz coreCount: 40 deviceMemorySize: 14.75GiB deviceMemoryBandwidth: 298.08GiB/s
2021-08-06 09:38:24.068367: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0
2021-08-06 09:38:25.177804: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcublas.so.11
2021-08-06 09:38:25.177953: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcublasLt.so.11
2021-08-06 09:38:26.000717: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcufft.so.10
2021-08-06 09:38:26.290309: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcurand.so.10
2021-08-06 09:38:27.391258: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcusolver.so.11
2021-08-06 09:38:27.629439: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcusparse.so.11
2021-08-06 09:38:27.629671: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudnn.so.8
2021-08-06 09:38:27.629795: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-08-06 09:38:27.630474: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-08-06 09:38:27.631021: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1871] Adding visible gpu devices: 0
2021-08-06 09:38:27.631068: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0
2021-08-06 09:38:28.212071: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1258] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-08-06 09:38:28.212111: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1264] 0
2021-08-06 09:38:28.212127: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1277] 0: N
2021-08-06 09:38:28.212318: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-08-06 09:38:28.212943: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-08-06 09:38:28.213522: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-08-06 09:38:28.214070: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1418] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 13805 MB memory) -> physical GPU (device: 0, name: Tesla T4, pci bus id: 0000:00:1e.0, compute capability: 7.5)
Traceback (most recent call last):
File "project_images.py", line 122, in
main()
File "project_images.py", line 100, in main
_G, _D, Gs = pretrained_networks.load_networks(args.network_pkl)
File "/home/ubuntu/toonify/stylegan2/pretrained_networks.py", line 76, in load_networks
G, D, Gs = pickle.load(stream, encoding='latin1')
File "/home/ubuntu/toonify/stylegan2/dnnlib/tflib/network.py", line 270, in setstate
tfutil.assert_tf_initialized()
File "/home/ubuntu/toonify/stylegan2/dnnlib/tflib/tfutil.py", line 137, in assert_tf_initialized
if tf.get_default_session() is None:
AttributeError: module 'tensorflow' has no attribute 'get_default_session'
root@ip-172-31-31-105:/home/ubuntu/toonify/stylegan2# vi /home/ubuntu/toonify/stylegan2/dnnlib/tflib/tfutil.py
root@ip-172-31-31-105:/home/ubuntu/toonify/stylegan2# python3 project_images.py --num-steps 500 aligned generated
2021-08-06 09:38:51.075316: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0
Loading networks from "http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-ffhq-config-f.pkl"...
2021-08-06 09:38:52.300083: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 AVX512F FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-08-06 09:38:52.301180: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcuda.so.1
2021-08-06 09:38:52.344258: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-08-06 09:38:52.344843: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1733] Found device 0 with properties:
pciBusID: 0000:00:1e.0 name: Tesla T4 computeCapability: 7.5
coreClock: 1.59GHz coreCount: 40 deviceMemorySize: 14.75GiB deviceMemoryBandwidth: 298.08GiB/s
2021-08-06 09:38:52.344879: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0
2021-08-06 09:38:52.347631: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcublas.so.11
2021-08-06 09:38:52.347707: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcublasLt.so.11
2021-08-06 09:38:52.349419: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcufft.so.10
2021-08-06 09:38:52.349736: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcurand.so.10
2021-08-06 09:38:52.352832: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcusolver.so.11
2021-08-06 09:38:52.353485: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcusparse.so.11
2021-08-06 09:38:52.353634: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudnn.so.8
2021-08-06 09:38:52.353728: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-08-06 09:38:52.354345: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-08-06 09:38:52.354875: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1871] Adding visible gpu devices: 0
2021-08-06 09:38:52.354912: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0
2021-08-06 09:38:52.940980: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1258] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-08-06 09:38:52.941022: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1264] 0
2021-08-06 09:38:52.941038: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1277] 0: N
2021-08-06 09:38:52.941210: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-08-06 09:38:52.941797: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-08-06 09:38:52.942360: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-08-06 09:38:52.942890: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1418] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 13805 MB memory) -> physical GPU (device: 0, name: Tesla T4, pci bus id: 0000:00:1e.0, compute capability: 7.5)
Traceback (most recent call last):
File "project_images.py", line 122, in
main()
File "project_images.py", line 100, in main
_G, _D, Gs = pretrained_networks.load_networks(args.network_pkl)
File "/home/ubuntu/toonify/stylegan2/pretrained_networks.py", line 76, in load_networks
G, D, Gs = pickle.load(stream, encoding='latin1')
File "/home/ubuntu/toonify/stylegan2/dnnlib/tflib/network.py", line 297, in setstate
self._init_graph()
File "/home/ubuntu/toonify/stylegan2/dnnlib/tflib/network.py", line 140, in _init_graph
with tf.name_scope(None):
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 6647, in init
raise ValueError("name for name_scope must be a string.")
ValueError: name for name_scope must be a string.

@sieu-n
Copy link

sieu-n commented Aug 27, 2021

Is this branch working?

@johndpope
Copy link

This repo built was superseded by stypegan2-ada (all models are compatible but dnn library got updated ) and then stylegan2-ada-pytorch. (You can import tf models to pytorch no problem)

@digital-thinking
Copy link

Is this branch working?

No, it's not enough to change the imports, there is more work necessary to make it work with TF2

@innat
Copy link

innat commented Mar 5, 2022

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

Successfully merging this pull request may close these issues.

6 participants