diff --git a/.gitignore b/.gitignore index 499acd4..ae51ef9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ stylegan/ -!stylegan/.gitkeep \ No newline at end of file +!stylegan/.gitkeep +__pycache__ +.stylegan2-cache \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 849df49..dfb1421 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu18.04 +FROM nvidia/cuda:11.2.0-cudnn8-devel-ubuntu18.04 RUN apt-get update && apt-get install python3.7 python3-dev libpython3.7-dev python3-pip cmake g++ gnupg -y RUN apt-get install libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6 libsm6 libxext6 libxrender-dev x11-apps libqt5x11extras5 -y @@ -13,7 +13,9 @@ ENV LANG=en_US.UTF-8 \ RUN python3.7 -m pip install --upgrade pip setuptools WORKDIR /usr/app +RUN python3.7 -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cu111 COPY ./requirements.txt /usr/app -RUN python3.7 -m pip install -r requirements.txt +RUN --mount=type=cache,target=/root/.cache \ + python3.7 -m pip install -r requirements.txt COPY . /usr/app diff --git a/README.md b/README.md index 2bb413a..01ebd8c 100644 --- a/README.md +++ b/README.md @@ -31,13 +31,17 @@ git clone https://github.com/RameenAbdal/StyleFlow.git cd StyleFlow/ ``` +StyleGAN2 relies on custom TensorFlow ops that are compiled on the fly using [NVCC](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html). To correctly setup the StyleGAN2 generator follow the **Requirements** in [this repo](https://github.com/NVlabs/stylegan2). +```bash +# This packages are enough to fulfill all requirements (at least for WSL Ubuntu>=20.04 installation) +sudo apt install cmake g++ gnupg nvidia-cuda-toolkit +``` + This code requires PyTorch, TensorFlow, Torchdiffeq, Python 3+ and Pyqt5. Please install dependencies by ```bash conda env create -f environment.yml ``` -StyleGAN2 relies on custom TensorFlow ops that are compiled on the fly using [NVCC](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html). To correctly setup the StyleGAN2 generator follow the **Requirements** in [this repo](https://github.com/NVlabs/stylegan2). - ## Installation (Docker) Clone this repo. @@ -47,7 +51,7 @@ git clone https://github.com/RameenAbdal/StyleFlow.git cd StyleFlow/ ``` -You must have CUDA (>=10.0 && <11.0) and [nvidia-docker2](https://github.com/NVIDIA/nvidia-docker) installed first ! +You must have CUDA >=10.0 and [nvidia-docker2](https://github.com/NVIDIA/nvidia-docker) installed first ! Then, run : @@ -84,7 +88,7 @@ xhost -local:docker 2. Run the Attribute Transfer UI ```bash - python main_attribute.py + python main_attribute.py ``` ## Web UI (Beta) @@ -99,7 +103,7 @@ Create `./data_numpy/` in the main folder and extract the above data or create y Train your model: ```bash - python train_flow.py + python train_flow.py ``` ## Projection @@ -136,8 +140,8 @@ keywords = {image editing, Generative adversarial networks} ``` @INPROCEEDINGS{9008515, author={Abdal, Rameen and Qin, Yipeng and Wonka, Peter}, - booktitle={2019 IEEE/CVF International Conference on Computer Vision (ICCV)}, - title={Image2StyleGAN: How to Embed Images Into the StyleGAN Latent Space?}, + booktitle={2019 IEEE/CVF International Conference on Computer Vision (ICCV)}, + title={Image2StyleGAN: How to Embed Images Into the StyleGAN Latent Space?}, year={2019}, volume={}, number={}, diff --git a/dnnlib/__pycache__/__init__.cpython-36.pyc b/dnnlib/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 41731f7..0000000 Binary files a/dnnlib/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/__pycache__/__init__.cpython-37.pyc b/dnnlib/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 782050c..0000000 Binary files a/dnnlib/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/dnnlib/__pycache__/util.cpython-36.pyc b/dnnlib/__pycache__/util.cpython-36.pyc deleted file mode 100644 index 278fe5f..0000000 Binary files a/dnnlib/__pycache__/util.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/__pycache__/util.cpython-37.pyc b/dnnlib/__pycache__/util.cpython-37.pyc deleted file mode 100644 index 4d5a9db..0000000 Binary files a/dnnlib/__pycache__/util.cpython-37.pyc and /dev/null differ diff --git a/dnnlib/submission/__pycache__/__init__.cpython-36.pyc b/dnnlib/submission/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 01c1243..0000000 Binary files a/dnnlib/submission/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/submission/__pycache__/__init__.cpython-37.pyc b/dnnlib/submission/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index e8d1f12..0000000 Binary files a/dnnlib/submission/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/dnnlib/submission/__pycache__/run_context.cpython-36.pyc b/dnnlib/submission/__pycache__/run_context.cpython-36.pyc deleted file mode 100644 index cd220ca..0000000 Binary files a/dnnlib/submission/__pycache__/run_context.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/submission/__pycache__/run_context.cpython-37.pyc b/dnnlib/submission/__pycache__/run_context.cpython-37.pyc deleted file mode 100644 index b4cb796..0000000 Binary files a/dnnlib/submission/__pycache__/run_context.cpython-37.pyc and /dev/null differ diff --git a/dnnlib/submission/__pycache__/submit.cpython-36.pyc b/dnnlib/submission/__pycache__/submit.cpython-36.pyc deleted file mode 100644 index d7feff9..0000000 Binary files a/dnnlib/submission/__pycache__/submit.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/submission/__pycache__/submit.cpython-37.pyc b/dnnlib/submission/__pycache__/submit.cpython-37.pyc deleted file mode 100644 index e2f9c1c..0000000 Binary files a/dnnlib/submission/__pycache__/submit.cpython-37.pyc and /dev/null differ diff --git a/dnnlib/submission/internal/__pycache__/__init__.cpython-36.pyc b/dnnlib/submission/internal/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index b6e22b4..0000000 Binary files a/dnnlib/submission/internal/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/submission/internal/__pycache__/__init__.cpython-37.pyc b/dnnlib/submission/internal/__pycache__/__init__.cpython-37.pyc index 9b5a392..0464405 100644 Binary files a/dnnlib/submission/internal/__pycache__/__init__.cpython-37.pyc and b/dnnlib/submission/internal/__pycache__/__init__.cpython-37.pyc differ diff --git a/dnnlib/submission/internal/__pycache__/local.cpython-36.pyc b/dnnlib/submission/internal/__pycache__/local.cpython-36.pyc deleted file mode 100644 index deb052b..0000000 Binary files a/dnnlib/submission/internal/__pycache__/local.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/submission/internal/__pycache__/local.cpython-37.pyc b/dnnlib/submission/internal/__pycache__/local.cpython-37.pyc index 5c22b56..37292d5 100644 Binary files a/dnnlib/submission/internal/__pycache__/local.cpython-37.pyc and b/dnnlib/submission/internal/__pycache__/local.cpython-37.pyc differ diff --git a/dnnlib/tflib/__pycache__/__init__.cpython-36.pyc b/dnnlib/tflib/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 5d9cd8c..0000000 Binary files a/dnnlib/tflib/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/tflib/__pycache__/__init__.cpython-37.pyc b/dnnlib/tflib/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index de1dc7c..0000000 Binary files a/dnnlib/tflib/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/dnnlib/tflib/__pycache__/autosummary.cpython-36.pyc b/dnnlib/tflib/__pycache__/autosummary.cpython-36.pyc deleted file mode 100644 index 075c033..0000000 Binary files a/dnnlib/tflib/__pycache__/autosummary.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/tflib/__pycache__/autosummary.cpython-37.pyc b/dnnlib/tflib/__pycache__/autosummary.cpython-37.pyc deleted file mode 100644 index 7400a42..0000000 Binary files a/dnnlib/tflib/__pycache__/autosummary.cpython-37.pyc and /dev/null differ diff --git a/dnnlib/tflib/__pycache__/custom_ops.cpython-36.pyc b/dnnlib/tflib/__pycache__/custom_ops.cpython-36.pyc deleted file mode 100644 index d5f1857..0000000 Binary files a/dnnlib/tflib/__pycache__/custom_ops.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/tflib/__pycache__/custom_ops.cpython-37.pyc b/dnnlib/tflib/__pycache__/custom_ops.cpython-37.pyc deleted file mode 100644 index 88b6120..0000000 Binary files a/dnnlib/tflib/__pycache__/custom_ops.cpython-37.pyc and /dev/null differ diff --git a/dnnlib/tflib/__pycache__/network.cpython-36.pyc b/dnnlib/tflib/__pycache__/network.cpython-36.pyc deleted file mode 100644 index b933dbd..0000000 Binary files a/dnnlib/tflib/__pycache__/network.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/tflib/__pycache__/network.cpython-37.pyc b/dnnlib/tflib/__pycache__/network.cpython-37.pyc deleted file mode 100644 index 909c389..0000000 Binary files a/dnnlib/tflib/__pycache__/network.cpython-37.pyc and /dev/null differ diff --git a/dnnlib/tflib/__pycache__/optimizer.cpython-36.pyc b/dnnlib/tflib/__pycache__/optimizer.cpython-36.pyc deleted file mode 100644 index 10c2c76..0000000 Binary files a/dnnlib/tflib/__pycache__/optimizer.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/tflib/__pycache__/optimizer.cpython-37.pyc b/dnnlib/tflib/__pycache__/optimizer.cpython-37.pyc deleted file mode 100644 index 446bb18..0000000 Binary files a/dnnlib/tflib/__pycache__/optimizer.cpython-37.pyc and /dev/null differ diff --git a/dnnlib/tflib/__pycache__/tfutil.cpython-36.pyc b/dnnlib/tflib/__pycache__/tfutil.cpython-36.pyc deleted file mode 100644 index 3c274d9..0000000 Binary files a/dnnlib/tflib/__pycache__/tfutil.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/tflib/__pycache__/tfutil.cpython-37.pyc b/dnnlib/tflib/__pycache__/tfutil.cpython-37.pyc deleted file mode 100644 index 9c90862..0000000 Binary files a/dnnlib/tflib/__pycache__/tfutil.cpython-37.pyc and /dev/null differ diff --git a/dnnlib/tflib/_cudacache/fused_bias_act_38a9d138ca98d4d9438a96143ba0bdf4.so b/dnnlib/tflib/_cudacache/fused_bias_act_38a9d138ca98d4d9438a96143ba0bdf4.so deleted file mode 100644 index c295b4b..0000000 Binary files a/dnnlib/tflib/_cudacache/fused_bias_act_38a9d138ca98d4d9438a96143ba0bdf4.so and /dev/null differ diff --git a/dnnlib/tflib/_cudacache/fused_bias_act_409f17fb342e7afb1999d94f39265be7.so b/dnnlib/tflib/_cudacache/fused_bias_act_409f17fb342e7afb1999d94f39265be7.so deleted file mode 100644 index 76f6505..0000000 Binary files a/dnnlib/tflib/_cudacache/fused_bias_act_409f17fb342e7afb1999d94f39265be7.so and /dev/null differ diff --git a/dnnlib/tflib/_cudacache/fused_bias_act_47cac38cf7a3efe20384e78d309f5d13.dll b/dnnlib/tflib/_cudacache/fused_bias_act_47cac38cf7a3efe20384e78d309f5d13.dll deleted file mode 100644 index 9f42107..0000000 Binary files a/dnnlib/tflib/_cudacache/fused_bias_act_47cac38cf7a3efe20384e78d309f5d13.dll and /dev/null differ diff --git a/dnnlib/tflib/_cudacache/fused_bias_act_8411aefb3de1f8b768085da63e11125b.so b/dnnlib/tflib/_cudacache/fused_bias_act_8411aefb3de1f8b768085da63e11125b.so deleted file mode 100644 index 9fe232b..0000000 Binary files a/dnnlib/tflib/_cudacache/fused_bias_act_8411aefb3de1f8b768085da63e11125b.so and /dev/null differ diff --git a/dnnlib/tflib/_cudacache/upfirdn_2d_0457fc9d1454f43aa82806a743538497.dll b/dnnlib/tflib/_cudacache/upfirdn_2d_0457fc9d1454f43aa82806a743538497.dll deleted file mode 100644 index cb9554a..0000000 Binary files a/dnnlib/tflib/_cudacache/upfirdn_2d_0457fc9d1454f43aa82806a743538497.dll and /dev/null differ diff --git a/dnnlib/tflib/_cudacache/upfirdn_2d_516397dd067c5a9d9fa722f543cf77e8.so b/dnnlib/tflib/_cudacache/upfirdn_2d_516397dd067c5a9d9fa722f543cf77e8.so deleted file mode 100644 index a96c41e..0000000 Binary files a/dnnlib/tflib/_cudacache/upfirdn_2d_516397dd067c5a9d9fa722f543cf77e8.so and /dev/null differ diff --git a/dnnlib/tflib/_cudacache/upfirdn_2d_a53930005280cf41f051dd27a1102610.so b/dnnlib/tflib/_cudacache/upfirdn_2d_a53930005280cf41f051dd27a1102610.so deleted file mode 100644 index d12fec3..0000000 Binary files a/dnnlib/tflib/_cudacache/upfirdn_2d_a53930005280cf41f051dd27a1102610.so and /dev/null differ diff --git a/dnnlib/tflib/autosummary.py b/dnnlib/tflib/autosummary.py index 6b0d80b..76de3f2 100644 --- a/dnnlib/tflib/autosummary.py +++ b/dnnlib/tflib/autosummary.py @@ -23,7 +23,11 @@ from collections import OrderedDict import numpy as np -import tensorflow as tf +try: + import tensorflow.compat.v1 as tf + tf.disable_v2_behavior() +except: + import tensorflow as tf from tensorboard import summary as summary_lib from tensorboard.plugins.custom_scalar import layout_pb2 diff --git a/dnnlib/tflib/custom_ops.py b/dnnlib/tflib/custom_ops.py index f87c0d8..67dface 100644 --- a/dnnlib/tflib/custom_ops.py +++ b/dnnlib/tflib/custom_ops.py @@ -13,7 +13,11 @@ import hashlib import tempfile import shutil -import tensorflow as tf +try: + import tensorflow.compat.v1 as tf + tf.disable_v2_behavior() +except: + import tensorflow as tf from tensorflow.python.client import device_lib # pylint: disable=no-name-in-module #---------------------------------------------------------------------------- @@ -126,7 +130,7 @@ def get_plugin(cuda_file): compile_opts += '"%s"' % os.path.join(tf.sysconfig.get_lib(), 'python', '_pywrap_tensorflow_internal.lib') elif os.name == 'posix': compile_opts += '"%s"' % os.path.join(tf.sysconfig.get_lib(), 'python', '_pywrap_tensorflow_internal.so') - compile_opts += ' --compiler-options \'-fPIC -D_GLIBCXX_USE_CXX11_ABI=0\'' + compile_opts += ' --compiler-options \'-fPIC -D_GLIBCXX_USE_CXX11_ABI=1\'' else: assert False # not Windows or Linux, w00t? compile_opts += ' --gpu-architecture=%s' % _get_cuda_gpu_arch_string() diff --git a/dnnlib/tflib/network.py b/dnnlib/tflib/network.py index 409babb..73c8979 100644 --- a/dnnlib/tflib/network.py +++ b/dnnlib/tflib/network.py @@ -12,7 +12,11 @@ import uuid import sys import numpy as np -import tensorflow as tf +try: + import tensorflow.compat.v1 as tf + tf.disable_v2_behavior() +except: + import tensorflow as tf from collections import OrderedDict from typing import Any, List, Tuple, Union diff --git a/dnnlib/tflib/ops/__pycache__/__init__.cpython-36.pyc b/dnnlib/tflib/ops/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 19ae206..0000000 Binary files a/dnnlib/tflib/ops/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/tflib/ops/__pycache__/__init__.cpython-37.pyc b/dnnlib/tflib/ops/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 33435eb..0000000 Binary files a/dnnlib/tflib/ops/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/dnnlib/tflib/ops/__pycache__/fused_bias_act.cpython-36.pyc b/dnnlib/tflib/ops/__pycache__/fused_bias_act.cpython-36.pyc deleted file mode 100644 index 9165718..0000000 Binary files a/dnnlib/tflib/ops/__pycache__/fused_bias_act.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/tflib/ops/__pycache__/fused_bias_act.cpython-37.pyc b/dnnlib/tflib/ops/__pycache__/fused_bias_act.cpython-37.pyc deleted file mode 100644 index d88b493..0000000 Binary files a/dnnlib/tflib/ops/__pycache__/fused_bias_act.cpython-37.pyc and /dev/null differ diff --git a/dnnlib/tflib/ops/__pycache__/upfirdn_2d.cpython-36.pyc b/dnnlib/tflib/ops/__pycache__/upfirdn_2d.cpython-36.pyc deleted file mode 100644 index ef0f785..0000000 Binary files a/dnnlib/tflib/ops/__pycache__/upfirdn_2d.cpython-36.pyc and /dev/null differ diff --git a/dnnlib/tflib/ops/__pycache__/upfirdn_2d.cpython-37.pyc b/dnnlib/tflib/ops/__pycache__/upfirdn_2d.cpython-37.pyc deleted file mode 100644 index a035579..0000000 Binary files a/dnnlib/tflib/ops/__pycache__/upfirdn_2d.cpython-37.pyc and /dev/null differ diff --git a/dnnlib/tflib/ops/fused_bias_act.py b/dnnlib/tflib/ops/fused_bias_act.py index 52f6bfd..7a5dab4 100644 --- a/dnnlib/tflib/ops/fused_bias_act.py +++ b/dnnlib/tflib/ops/fused_bias_act.py @@ -8,7 +8,14 @@ import os import numpy as np -import tensorflow as tf +try: + import tensorflow.compat.v1 as tf + tf.disable_v2_behavior() + force_ref_impl = True +except: + import tensorflow as tf + force_ref_impl = False + from .. import custom_ops from ...util import EasyDict @@ -65,7 +72,7 @@ def fused_bias_act(x, b=None, axis=1, act='linear', alpha=None, gain=None, impl= 'ref': _fused_bias_act_ref, 'cuda': _fused_bias_act_cuda, } - return impl_dict[impl](x=x, b=b, axis=axis, act=act, alpha=alpha, gain=gain) + return impl_dict['ref' if force_ref_impl else impl](x=x, b=b, axis=axis, act=act, alpha=alpha, gain=gain) #---------------------------------------------------------------------------- diff --git a/dnnlib/tflib/ops/upfirdn_2d.py b/dnnlib/tflib/ops/upfirdn_2d.py index fd23777..d69aa4d 100644 --- a/dnnlib/tflib/ops/upfirdn_2d.py +++ b/dnnlib/tflib/ops/upfirdn_2d.py @@ -8,7 +8,14 @@ import os import numpy as np -import tensorflow as tf +try: + import tensorflow.compat.v1 as tf + tf.disable_v2_behavior() + force_ref_impl = True +except: + import tensorflow as tf + force_ref_impl = False + from .. import custom_ops def _get_plugin(): @@ -59,7 +66,7 @@ def upfirdn_2d(x, k, upx=1, upy=1, downx=1, downy=1, padx0=0, padx1=0, pady0=0, 'ref': _upfirdn_2d_ref, 'cuda': _upfirdn_2d_cuda, } - return impl_dict[impl](x=x, k=k, upx=upx, upy=upy, downx=downx, downy=downy, padx0=padx0, padx1=padx1, pady0=pady0, pady1=pady1) + return impl_dict['ref' if force_ref_impl else impl](x=x, k=k, upx=upx, upy=upy, downx=downx, downy=downy, padx0=padx0, padx1=padx1, pady0=pady0, pady1=pady1) #---------------------------------------------------------------------------- diff --git a/dnnlib/tflib/optimizer.py b/dnnlib/tflib/optimizer.py index 9a1b1b8..ea94388 100644 --- a/dnnlib/tflib/optimizer.py +++ b/dnnlib/tflib/optimizer.py @@ -7,7 +7,11 @@ """Helper wrapper for a Tensorflow optimizer.""" import numpy as np -import tensorflow as tf +try: + import tensorflow.compat.v1 as tf + tf.disable_v2_behavior() +except: + import tensorflow as tf from collections import OrderedDict from typing import List, Union diff --git a/dnnlib/tflib/tfutil.py b/dnnlib/tflib/tfutil.py index 1127c7b..3996a97 100644 --- a/dnnlib/tflib/tfutil.py +++ b/dnnlib/tflib/tfutil.py @@ -8,13 +8,15 @@ import os import numpy as np -import tensorflow as tf +try: + import tensorflow.compat.v1 as tf + tf.disable_v2_behavior() +except: + import tensorflow as tf # 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 from typing import Any, Iterable, List, Union @@ -36,7 +38,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) -> List[Union[int, None]]: """Convert a Tensorflow shape to a list of ints. Retained for backwards compatibility -- use TensorShape.as_list() in new code.""" return [dim.value for dim in shape] diff --git a/docker-compose.yml b/docker-compose.yml index 09e4759..c152577 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,9 +5,14 @@ services: interface: build: . command: python3.7 /usr/app/main.py - volumes: + volumes: - /tmp/.X11-unix:/tmp/.X11-unix environment: DISPLAY: $DISPLAY QT_X11_NO_MITSHM: 1 QT_DEBUG_PLUGINS: 1 + deploy: + resources: + reservations: + devices: + - capabilities: [gpu] diff --git a/environment.yml b/environment.yml index 4292c6e..47894fc 100644 --- a/environment.yml +++ b/environment.yml @@ -2,6 +2,7 @@ name: StyleFlow channels: - anaconda - defaults + - nvidia - conda-forge dependencies: - _libgcc_mutex=0.1=conda_forge @@ -10,6 +11,8 @@ dependencies: - blas=1.0=mkl - bzip2=1.0.8=h7f98852_4 - ca-certificates=2020.12.8=h06a4308_0 + - cudatoolkit=11.1.74=h6bb024c_0 + - cudnn=8.1.0.77=h90431f1_0 - certifi=2020.12.5=py37h06a4308_0 - ffmpeg=4.3.1=h3215721_1 - freetype=2.9.1=h8a8886c_1 @@ -54,7 +57,10 @@ dependencies: - zlib=1.2.11=h7b6447c_3 - zstd=1.3.7=h0b5b093_0 - pip: - - absl-py==0.7.1 + - --extra-index-url https://download.pytorch.org/whl/lts/1.8/cu111 + - torch==1.8.2 + - torchvision==0.9.2 + - absl-py==0.10 - appdirs==1.4.4 - astor==0.8.0 - astunparse==1.6.3 @@ -64,6 +70,7 @@ dependencies: - cachetools==4.1.0 - cffi==1.12.3 - chardet==3.0.4 + - clang==5.0 - cloudpickle==1.2.1 - cycler==0.10.0 - cytoolz==0.9.0.1 @@ -76,12 +83,13 @@ dependencies: - dominate==2.3.5 - easydict==1.9 - entrypoints==0.3 - - gast==0.2.2 + - flatbuffers==1.12.0 + - gast==0.4.0 - google-auth==1.14.3 - google-auth-oauthlib==0.4.1 - google-pasta==0.2.0 - - grpcio==1.22.0 - - h5py==2.10.0 + - grpcio==1.37.0 + - h5py==3.1.0 - helpdev==0.6.10 - idna==2.8 - imageio==2.5.0 @@ -98,7 +106,7 @@ dependencies: - jupyter-client==5.2.4 - jupyter-console==6.0.0 - jupyter-core==4.5.0 - - keras==2.2.4 + - keras==2.6 - keras-applications==1.0.8 - keras-preprocessing==1.1.0 - kiwisolver==1.1.0 @@ -113,7 +121,7 @@ dependencies: - notebook==5.7.8 - oauthlib==3.1.0 - opencv-python==4.1.0.25 - - opt-einsum==3.2.1 + - opt-einsum==3.3.0 - pandocfilters==1.4.2 - parso==0.5.0 - pexpect==4.7.0 @@ -121,13 +129,13 @@ dependencies: - pillow==6.0.0 - prometheus-client==0.7.1 - prompt-toolkit==2.0.9 - - protobuf==3.8.0 + - protobuf==3.9.2 - psutil==5.6.3 - ptyprocess==0.6.0 - pyasn1==0.4.8 - pyasn1-modules==0.2.8 - pycparser==2.19 - - pycuda==2019.1.2 + - pycuda==2022.1 - pygments==2.4.2 - pyparsing==2.4.0 - pyqt5==5.13.0 @@ -151,26 +159,23 @@ dependencies: - scipy==1.2.1 - send2trash==1.5.0 - shiboken2==5.13.0 - - six==1.12.0 - - tensorboard==1.15.0 - - tensorboard-plugin-wit==1.6.0.post3 - - tensorflow-estimator==1.15.1 - - tensorflow-gpu==1.15.0 + - six==1.15.0 + - tensorboard==2.11.0 + - tensorboard-plugin-wit==1.8.1 + - tensorflow==2.6.0 + - tensorflow-estimator==2.11.0 - termcolor==1.1.0 - terminado==0.8.2 - testpath==0.4.2 - toolz==0.9.0 - - torch==1.1.0 - torchdiffeq==0.0.1 - - torchvision==0.3.0 - tornado==6.0.3 - tqdm==4.32.1 - traitlets==4.3.2 - urllib3==1.25.3 - wcwidth==0.1.7 - webencodings==0.5.1 - - werkzeug==0.15.4 + - werkzeug==1.0.1 - widgetsnbextension==3.4.2 - - wrapt==1.11.2 + - wrapt==1.12.1 - zipp==0.5.2 - diff --git a/main.py b/main.py index 14f35ef..8cbd32a 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,7 @@ +import os +os.environ["CUDA_VISIBLE_DEVICES"] = "0" +os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID' + import sys from PyQt5.QtCore import * from PyQt5.QtGui import * @@ -24,16 +28,17 @@ import torch from module.flow import cnf import os -import tensorflow as tf +try: + import tensorflow.compat.v1 as tf + tf.disable_v2_behavior() +except: + import tensorflow as tf from ui.real_time_attr_thread import RealTimeAttrThread from ui.real_time_light_thread import RealTimeLightThread # np.random.seed(2) -os.environ["CUDA_VISIBLE_DEVICES"] = "0" - - class ExWindow(QMainWindow): def __init__(self, opt): super().__init__() @@ -233,7 +238,8 @@ def real_time_lighting(self, light_index, raw_slide_value): for i in range(len(self.lighting_order)): lighting_final += self.light_current_list[i] * self.pre_lighting_distance[i] - self.final_array_target[:, :9] = lighting_final + with torch.no_grad(): + self.final_array_target[:, :9] = lighting_final self.rev = self.prior(self.fws[0], self.final_array_target, self.zero_padding, True) self.rev[0][0][0:7] = self.q_array[0][0:7] @@ -258,7 +264,8 @@ def real_time_editing(self, attr_index, raw_slide_value): attr_change = real_value - self.attr_current_list[attr_index] attr_final = attr_degree_list[attr_index] * attr_change + self.attr_current_list[attr_index] - self.final_array_target[0, attr_index + 9, 0, 0] = attr_final + with torch.no_grad(): + self.final_array_target[0, attr_index + 9, 0, 0] = attr_final self.rev = self.prior(self.fws[0], self.final_array_target, self.zero_padding, True) @@ -364,4 +371,4 @@ def lock_switch(self): app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) ex = ExWindow(opt) # ex = Ex(opt) - sys.exit(app.exec_()) + sys.exit(app.exec()) diff --git a/main_attribute.py b/main_attribute.py index 62934e0..d6a5125 100644 --- a/main_attribute.py +++ b/main_attribute.py @@ -1,3 +1,7 @@ +import os +os.environ["CUDA_VISIBLE_DEVICES"] = "0" +os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID' + import sys from PyQt5.QtCore import * from PyQt5.QtGui import * @@ -23,15 +27,17 @@ import torch from module.flow import cnf import os -import tensorflow as tf +try: + import tensorflow.compat.v1 as tf + tf.disable_v2_behavior() +except: + import tensorflow as tf from ui.real_time_attr_thread import RealTimeAttrThread from ui.real_time_light_thread import RealTimeLightThread # np.random.seed(2) -os.environ["CUDA_VISIBLE_DEVICES"] = "0" - class ExWindow(QMainWindow): def __init__(self, opt): @@ -287,7 +293,8 @@ def real_time_lighting(self, light_index, raw_slide_value): for i in range(len(self.lighting_order)): lighting_final += self.light_current_list[i] * self.pre_lighting_distance[i] - self.final_array_target[:, :9] = lighting_final + with torch.no_grad(): + self.final_array_target[:, :9] = lighting_final self.rev = self.prior(self.fws[0], self.final_array_target, self.zero_padding, True) self.rev[0][0][0:7] = self.q_array[0][0:7] @@ -314,7 +321,8 @@ def real_time_editing(self, attr_index, raw_slide_value): attr_change = real_value * self.pre_attr_distance[attr_index] attr_final = attr_degree_list[attr_index] * attr_change + self.attr_current_list[attr_index] - self.final_array_target[0, attr_index + 9, 0, 0] = attr_final + with torch.no_grad(): + self.final_array_target[0, attr_index + 9, 0, 0] = attr_final self.rev = self.prior(self.fws[0], self.final_array_target, self.zero_padding, True) @@ -406,4 +414,4 @@ def lock_switch(self): app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) ex = ExWindow(opt) # ex = Ex(opt) - sys.exit(app.exec_()) + sys.exit(app.exec()) diff --git a/module/__pycache__/cnf.cpython-36.pyc b/module/__pycache__/cnf.cpython-36.pyc deleted file mode 100644 index 1a836ba..0000000 Binary files a/module/__pycache__/cnf.cpython-36.pyc and /dev/null differ diff --git a/module/__pycache__/cnf.cpython-37.pyc b/module/__pycache__/cnf.cpython-37.pyc deleted file mode 100644 index dd72e7d..0000000 Binary files a/module/__pycache__/cnf.cpython-37.pyc and /dev/null differ diff --git a/module/__pycache__/diffeq_layers.cpython-36.pyc b/module/__pycache__/diffeq_layers.cpython-36.pyc deleted file mode 100644 index 3114e63..0000000 Binary files a/module/__pycache__/diffeq_layers.cpython-36.pyc and /dev/null differ diff --git a/module/__pycache__/diffeq_layers.cpython-37.pyc b/module/__pycache__/diffeq_layers.cpython-37.pyc deleted file mode 100644 index ff21f8d..0000000 Binary files a/module/__pycache__/diffeq_layers.cpython-37.pyc and /dev/null differ diff --git a/module/__pycache__/flow.cpython-36.pyc b/module/__pycache__/flow.cpython-36.pyc deleted file mode 100644 index 8295b15..0000000 Binary files a/module/__pycache__/flow.cpython-36.pyc and /dev/null differ diff --git a/module/__pycache__/flow.cpython-37.pyc b/module/__pycache__/flow.cpython-37.pyc deleted file mode 100644 index 316b718..0000000 Binary files a/module/__pycache__/flow.cpython-37.pyc and /dev/null differ diff --git a/module/__pycache__/normalization.cpython-36.pyc b/module/__pycache__/normalization.cpython-36.pyc deleted file mode 100644 index 690412a..0000000 Binary files a/module/__pycache__/normalization.cpython-36.pyc and /dev/null differ diff --git a/module/__pycache__/normalization.cpython-37.pyc b/module/__pycache__/normalization.cpython-37.pyc deleted file mode 100644 index 614dc27..0000000 Binary files a/module/__pycache__/normalization.cpython-37.pyc and /dev/null differ diff --git a/module/__pycache__/odefunc.cpython-36.pyc b/module/__pycache__/odefunc.cpython-36.pyc deleted file mode 100644 index caf3f6a..0000000 Binary files a/module/__pycache__/odefunc.cpython-36.pyc and /dev/null differ diff --git a/module/__pycache__/odefunc.cpython-37.pyc b/module/__pycache__/odefunc.cpython-37.pyc deleted file mode 100644 index 43e0523..0000000 Binary files a/module/__pycache__/odefunc.cpython-37.pyc and /dev/null differ diff --git a/module/__pycache__/utils.cpython-36.pyc b/module/__pycache__/utils.cpython-36.pyc deleted file mode 100644 index fb9a222..0000000 Binary files a/module/__pycache__/utils.cpython-36.pyc and /dev/null differ diff --git a/module/__pycache__/utils.cpython-37.pyc b/module/__pycache__/utils.cpython-37.pyc deleted file mode 100644 index 329d936..0000000 Binary files a/module/__pycache__/utils.cpython-37.pyc and /dev/null differ diff --git a/options/__pycache__/__init__.cpython-36.pyc b/options/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 802904b..0000000 Binary files a/options/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/options/__pycache__/__init__.cpython-37.pyc b/options/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index d95a3ee..0000000 Binary files a/options/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/options/__pycache__/base_options.cpython-36.pyc b/options/__pycache__/base_options.cpython-36.pyc deleted file mode 100644 index a68a60b..0000000 Binary files a/options/__pycache__/base_options.cpython-36.pyc and /dev/null differ diff --git a/options/__pycache__/base_options.cpython-37.pyc b/options/__pycache__/base_options.cpython-37.pyc deleted file mode 100644 index 238243e..0000000 Binary files a/options/__pycache__/base_options.cpython-37.pyc and /dev/null differ diff --git a/options/__pycache__/test_options.cpython-36.pyc b/options/__pycache__/test_options.cpython-36.pyc deleted file mode 100644 index c72ab34..0000000 Binary files a/options/__pycache__/test_options.cpython-36.pyc and /dev/null differ diff --git a/options/__pycache__/test_options.cpython-37.pyc b/options/__pycache__/test_options.cpython-37.pyc deleted file mode 100644 index e992905..0000000 Binary files a/options/__pycache__/test_options.cpython-37.pyc and /dev/null differ diff --git a/pretrained_networks.py b/pretrained_networks.py index 40ccfd9..06e9528 100644 --- a/pretrained_networks.py +++ b/pretrained_networks.py @@ -6,6 +6,7 @@ """List of pre-trained StyleGAN2 networks located on Google Drive.""" +import io import pickle import dnnlib import dnnlib.tflib as tflib @@ -71,6 +72,22 @@ def load_networks(path_or_gdrive_path): else: stream = open(path_or_url, 'rb') + try: + import tensorflow.compat.v1 as tf + tf.disable_v2_behavior() + + # For tensorflow v2.0 we need to change imports inside checkpoint code: + with stream: + data = stream.read() + + # Change imports to support tensorflow v2 + data = data.replace(b'import tensorflow as tf', b'import tensorflow.compat.v1 as tf\ntf.disable_v2_behavior()') + # This tricky replace allows to preserve file size + data = data.replace(b'Network architectures used in the StyleGAN2 paper.', b'tyleGAN2 paper.') + stream = io.BytesIO(data) + except: + import tensorflow as tf + tflib.init_tf() with stream: G, D, Gs = pickle.load(stream, encoding='latin1') diff --git a/requirements.txt b/requirements.txt index ec5136e..b80690b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ scikit-learn -absl-py==0.7.1 +absl-py==0.10 appdirs==1.4.4 astor==0.8.0 astunparse==1.6.3 @@ -10,6 +10,7 @@ bleach==3.1.0 cachetools==4.1.0 cffi==1.12.3 chardet==3.0.4 +clang==5.0 cloudpickle==1.2.1 cycler==0.10.0 cytoolz==0.9.0.1 @@ -22,12 +23,13 @@ dlib==19.21.0 dominate==2.3.5 easydict==1.9 entrypoints==0.3 -gast==0.2.2 +flatbuffers==1.12.0 +gast==0.4.0 google-auth==1.14.3 google-auth-oauthlib==0.4.1 google-pasta==0.2.0 -grpcio==1.22.0 -h5py==2.10.0 +grpcio==1.37.0 +h5py==3.1.0 helpdev==0.6.10 idna==2.8 imageio==2.5.0 @@ -44,9 +46,9 @@ jupyter==1.0.0 jupyter-client==5.2.4 jupyter-console==6.0.0 jupyter-core==4.5.0 -keras==2.2.4 +keras==2.6 keras-applications==1.0.8 -keras-preprocessing==1.1.0 +keras-preprocessing==1.1.2 kiwisolver==1.1.0 mako==1.1.2 markdown==3.1.1 @@ -59,7 +61,7 @@ networkx==2.3 notebook==5.7.8 oauthlib==3.1.0 opencv-python==4.1.0.25 -opt-einsum==3.2.1 +opt-einsum==3.3.0 pandocfilters==1.4.2 parso==0.5.0 pexpect==4.7.0 @@ -67,13 +69,13 @@ pickleshare==0.7.5 pillow==6.0.0 prometheus-client==0.7.1 prompt-toolkit==2.0.9 -protobuf==3.8.0 +protobuf==3.9.2 psutil==5.6.3 ptyprocess==0.6.0 pyasn1==0.4.8 pyasn1-modules==0.2.8 pycparser==2.19 -pycuda==2019.1.2 +pycuda==2022.1 pygments==2.4.2 pyparsing==2.4.0 pyqt5==5.13.0 @@ -97,25 +99,23 @@ scikit-video==1.1.11 scipy==1.2.1 send2trash==1.5.0 shiboken2==5.13.0 -six==1.12.0 -tensorboard==1.15.0 -tensorboard-plugin-wit==1.6.0.post3 -tensorflow-estimator==1.15.1 -tensorflow-gpu==1.15.0 +six==1.15.0 +tensorboard==2.11.0 +tensorboard-plugin-wit==1.8.1 +tensorflow==2.6.0 +tensorflow-estimator==2.11.0 termcolor==1.1.0 terminado==0.8.2 testpath==0.4.2 toolz==0.9.0 -torch==1.1.0 torchdiffeq==0.0.1 -torchvision==0.3.0 tornado==6.0.3 tqdm==4.32.1 traitlets==4.3.2 urllib3==1.25.3 wcwidth==0.1.7 webencodings==0.5.1 -werkzeug==0.15.4 +werkzeug==1.0.1 widgetsnbextension==3.4.2 -wrapt==1.11.2 +wrapt==1.12.1 zipp==0.5.2 diff --git a/ui/__pycache__/GT_mouse_event.cpython-36.pyc b/ui/__pycache__/GT_mouse_event.cpython-36.pyc deleted file mode 100644 index d87e4d0..0000000 Binary files a/ui/__pycache__/GT_mouse_event.cpython-36.pyc and /dev/null differ diff --git a/ui/__pycache__/GT_mouse_event.cpython-37.pyc b/ui/__pycache__/GT_mouse_event.cpython-37.pyc deleted file mode 100644 index b537410..0000000 Binary files a/ui/__pycache__/GT_mouse_event.cpython-37.pyc and /dev/null differ diff --git a/ui/__pycache__/__init__.cpython-36.pyc b/ui/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 546e6f1..0000000 Binary files a/ui/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/ui/__pycache__/__init__.cpython-37.pyc b/ui/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index e6082a5..0000000 Binary files a/ui/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/ui/__pycache__/mouse_event.cpython-36.pyc b/ui/__pycache__/mouse_event.cpython-36.pyc deleted file mode 100644 index 6fe56f5..0000000 Binary files a/ui/__pycache__/mouse_event.cpython-36.pyc and /dev/null differ diff --git a/ui/__pycache__/mouse_event.cpython-37.pyc b/ui/__pycache__/mouse_event.cpython-37.pyc deleted file mode 100644 index 952bbd8..0000000 Binary files a/ui/__pycache__/mouse_event.cpython-37.pyc and /dev/null differ diff --git a/ui/__pycache__/mouse_event2.cpython-36.pyc b/ui/__pycache__/mouse_event2.cpython-36.pyc deleted file mode 100644 index 8ad9884..0000000 Binary files a/ui/__pycache__/mouse_event2.cpython-36.pyc and /dev/null differ diff --git a/ui/__pycache__/mouse_event2.cpython-37.pyc b/ui/__pycache__/mouse_event2.cpython-37.pyc deleted file mode 100644 index 0241b7c..0000000 Binary files a/ui/__pycache__/mouse_event2.cpython-37.pyc and /dev/null differ diff --git a/ui/__pycache__/real_time_attr_thread.cpython-36.pyc b/ui/__pycache__/real_time_attr_thread.cpython-36.pyc deleted file mode 100644 index 9f35c68..0000000 Binary files a/ui/__pycache__/real_time_attr_thread.cpython-36.pyc and /dev/null differ diff --git a/ui/__pycache__/real_time_attr_thread.cpython-37.pyc b/ui/__pycache__/real_time_attr_thread.cpython-37.pyc deleted file mode 100644 index 988a19b..0000000 Binary files a/ui/__pycache__/real_time_attr_thread.cpython-37.pyc and /dev/null differ diff --git a/ui/__pycache__/real_time_light_thread.cpython-36.pyc b/ui/__pycache__/real_time_light_thread.cpython-36.pyc deleted file mode 100644 index 5850244..0000000 Binary files a/ui/__pycache__/real_time_light_thread.cpython-36.pyc and /dev/null differ diff --git a/ui/__pycache__/real_time_light_thread.cpython-37.pyc b/ui/__pycache__/real_time_light_thread.cpython-37.pyc deleted file mode 100644 index 700fcee..0000000 Binary files a/ui/__pycache__/real_time_light_thread.cpython-37.pyc and /dev/null differ diff --git a/ui/__pycache__/ui.cpython-36.pyc b/ui/__pycache__/ui.cpython-36.pyc deleted file mode 100644 index 7e8db47..0000000 Binary files a/ui/__pycache__/ui.cpython-36.pyc and /dev/null differ diff --git a/ui/__pycache__/ui.cpython-37.pyc b/ui/__pycache__/ui.cpython-37.pyc deleted file mode 100644 index 5deea37..0000000 Binary files a/ui/__pycache__/ui.cpython-37.pyc and /dev/null differ diff --git a/ui/__pycache__/ui2.cpython-36.pyc b/ui/__pycache__/ui2.cpython-36.pyc deleted file mode 100644 index b126e42..0000000 Binary files a/ui/__pycache__/ui2.cpython-36.pyc and /dev/null differ diff --git a/ui/__pycache__/ui2.cpython-37.pyc b/ui/__pycache__/ui2.cpython-37.pyc deleted file mode 100644 index 15482c7..0000000 Binary files a/ui/__pycache__/ui2.cpython-37.pyc and /dev/null differ diff --git a/ui/real_time_attr_thread.py b/ui/real_time_attr_thread.py index 9c015d6..6e9eecd 100644 --- a/ui/real_time_attr_thread.py +++ b/ui/real_time_attr_thread.py @@ -4,7 +4,11 @@ from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * -import tensorflow as tf +try: + import tensorflow.compat.v1 as tf + tf.disable_v2_behavior() +except: + import tensorflow as tf import PIL import datetime import os diff --git a/ui/real_time_light_thread.py b/ui/real_time_light_thread.py index d61f879..d605683 100644 --- a/ui/real_time_light_thread.py +++ b/ui/real_time_light_thread.py @@ -4,7 +4,11 @@ from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * -import tensorflow as tf +try: + import tensorflow.compat.v1 as tf + tf.disable_v2_behavior() +except: + import tensorflow as tf import PIL import datetime import os diff --git a/utils.py b/utils.py index 63b91ea..b623c4d 100644 --- a/utils.py +++ b/utils.py @@ -1,7 +1,11 @@ import PIL.Image import dnnlib import dnnlib.tflib as tflib -import tensorflow as tf +try: + import tensorflow.compat.v1 as tf + tf.disable_v2_behavior() +except: + import tensorflow as tf import PIL.ImageFile