Skip to content

Commit dd06bf3

Browse files
committed
package code for pip install
1 parent d4b2afe commit dd06bf3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+139
-106
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ w = G.mapping(z, c, truncation_psi=0.5, truncation_cutoff=8)
151151
img = G.synthesis(w, noise_mode='const', force_fp32=True)
152152
```
153153

154-
Please refer to [`generate.py`](./generate.py), [`style_mixing.py`](./style_mixing.py), and [`projector.py`](./projector.py) for further examples.
154+
Please refer to [`generate.py`](stylegan2_ada_pytorch/generate.py), [`style_mixing.py`](stylegan2_ada_pytorch/style_mixing.py), and [`projector.py`](stylegan2_ada_pytorch/projector.py) for further examples.
155155

156156
## Preparing datasets
157157

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[build-system]
2+
requires = [
3+
"setuptools>=42",
4+
"wheel"
5+
]
6+
build-backend = "setuptools.build_meta"

setup.cfg

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[metadata]
2+
name = stylegan2-ada-pytorch
3+
version = 1.0.0
4+
description = StyleGAN2-ADA - Official PyTorch implementation
5+
long_description = file: README.md
6+
long_description_content_type = text/markdown
7+
url = https://github.com/NVlabs/stylegan2-ada-pytorch
8+
project_urls =
9+
Bug Tracker = https://github.com/NVlabs/stylegan2-ada-pytorch/issues
10+
classifiers =
11+
Programming Language :: Python :: 3
12+
License :: OSI Approved :: MIT License
13+
Operating System :: OS Independent
14+
15+
[options]
16+
package_dir =
17+
= .
18+
packages = find:
19+
python_requires = >=3.6
20+
install_requires =
21+
torch >=1.7.0
22+
click
23+
requests
24+
tqdm
25+
pyspng
26+
ninja
27+
imageio-ffmpeg ==0.4.3
28+
29+
[options.packages.find]
30+
where = .

stylegan2_ada_pytorch/__init__.py

Whitespace-only changes.

calc_metrics.py renamed to stylegan2_ada_pytorch/calc_metrics.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,17 @@
1414
import tempfile
1515
import copy
1616
import torch
17-
import dnnlib
1817

19-
import legacy
20-
from metrics import metric_main
21-
from metrics import metric_utils
22-
from torch_utils import training_stats
23-
from torch_utils import custom_ops
24-
from torch_utils import misc
18+
from stylegan2_ada_pytorch import legacy, dnnlib
19+
from stylegan2_ada_pytorch.metrics import metric_main, metric_utils
20+
from stylegan2_ada_pytorch.torch_utils import training_stats
21+
from stylegan2_ada_pytorch.torch_utils import custom_ops, misc
22+
2523

2624
#----------------------------------------------------------------------------
2725

2826
def subprocess_fn(rank, args, temp_dir):
29-
dnnlib.util.Logger(should_flush=True)
27+
stylegan2_ada_pytorch.dnnlib.util.Logger(should_flush=True)
3028

3129
# Init torch.distributed.
3230
if args.num_gpus > 1:
@@ -61,7 +59,7 @@ def subprocess_fn(rank, args, temp_dir):
6159
print(f'Calculating {metric}...')
6260
progress = metric_utils.ProgressMonitor(verbose=args.verbose)
6361
result_dict = metric_main.calc_metric(metric=metric, G=G, dataset_kwargs=args.dataset_kwargs,
64-
num_gpus=args.num_gpus, rank=rank, device=device, progress=progress)
62+
num_gpus=args.num_gpus, rank=rank, device=device, progress=progress)
6563
if rank == 0:
6664
metric_main.report_metric(result_dict, run_dir=args.run_dir, snapshot_pkl=args.network_pkl)
6765
if rank == 0 and args.verbose:
@@ -128,7 +126,7 @@ def calc_metrics(ctx, network_pkl, metrics, data, mirror, gpus, verbose):
128126
ppl_zend Perceptual path length in Z at path endpoints against cropped image.
129127
ppl_wend Perceptual path length in W at path endpoints against cropped image.
130128
"""
131-
dnnlib.util.Logger(should_flush=True)
129+
stylegan2_ada_pytorch.dnnlib.util.Logger(should_flush=True)
132130

133131
# Validate arguments.
134132
args = dnnlib.EasyDict(metrics=metrics, num_gpus=gpus, network_pkl=network_pkl, verbose=verbose)
@@ -138,11 +136,11 @@ def calc_metrics(ctx, network_pkl, metrics, data, mirror, gpus, verbose):
138136
ctx.fail('--gpus must be at least 1')
139137

140138
# Load network.
141-
if not dnnlib.util.is_url(network_pkl, allow_file_urls=True) and not os.path.isfile(network_pkl):
139+
if not stylegan2_ada_pytorch.dnnlib.util.is_url(network_pkl, allow_file_urls=True) and not os.path.isfile(network_pkl):
142140
ctx.fail('--network must point to a file or URL')
143141
if args.verbose:
144142
print(f'Loading network from "{network_pkl}"...')
145-
with dnnlib.util.open_url(network_pkl, verbose=args.verbose) as f:
143+
with stylegan2_ada_pytorch.dnnlib.util.open_url(network_pkl, verbose=args.verbose) as f:
146144
network_dict = legacy.load_network_pkl(f)
147145
args.G = network_dict['G_ema'] # subclass of torch.nn.Module
148146

File renamed without changes.
File renamed without changes.
File renamed without changes.

generate.py renamed to stylegan2_ada_pytorch/generate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
from typing import List, Optional
1414

1515
import click
16-
import dnnlib
1716
import numpy as np
1817
import PIL.Image
1918
import torch
2019

21-
import legacy
20+
from stylegan2_ada_pytorch import legacy, dnnlib
21+
2222

2323
#----------------------------------------------------------------------------
2424

@@ -80,7 +80,7 @@ def generate_images(
8080

8181
print('Loading networks from "%s"...' % network_pkl)
8282
device = torch.device('cuda')
83-
with dnnlib.util.open_url(network_pkl) as f:
83+
with stylegan2_ada_pytorch.dnnlib.util.open_url(network_pkl) as f:
8484
G = legacy.load_network_pkl(f)['G_ema'].to(device) # type: ignore
8585

8686
os.makedirs(outdir, exist_ok=True)

legacy.py renamed to stylegan2_ada_pytorch/legacy.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
import copy
1313
import numpy as np
1414
import torch
15-
import dnnlib
16-
from torch_utils import misc
15+
from stylegan2_ada_pytorch import dnnlib
16+
from stylegan2_ada_pytorch.torch_utils import misc
17+
1718

1819
#----------------------------------------------------------------------------
1920

@@ -165,7 +166,7 @@ def kwarg(tf_name, default=None, none=None):
165166
#for name, value in tf_params.items(): print(f'{name:<50s}{list(value.shape)}')
166167

167168
# Convert params.
168-
from training import networks
169+
from stylegan2_ada_pytorch.training import networks
169170
G = networks.Generator(**kwargs).eval().requires_grad_(False)
170171
# pylint: disable=unnecessary-lambda
171172
_populate_module_params(G,
@@ -262,7 +263,7 @@ def kwarg(tf_name, default=None):
262263
#for name, value in tf_params.items(): print(f'{name:<50s}{list(value.shape)}')
263264

264265
# Convert params.
265-
from training import networks
266+
from stylegan2_ada_pytorch.training import networks
266267
D = networks.Discriminator(**kwargs).eval().requires_grad_(False)
267268
# pylint: disable=unnecessary-lambda
268269
_populate_module_params(D,
@@ -305,7 +306,7 @@ def convert_network_pickle(source, dest, force_fp16):
305306
--dest=stylegan2-cat-config-f.pkl
306307
"""
307308
print(f'Loading "{source}"...')
308-
with dnnlib.util.open_url(source) as f:
309+
with stylegan2_ada_pytorch.dnnlib.util.open_url(source) as f:
309310
data = load_network_pkl(f, force_fp16=force_fp16)
310311
print(f'Saving "{dest}"...')
311312
with open(dest, 'wb') as f:

0 commit comments

Comments
 (0)