forked from NVlabs/stylegan2-ada-pytorch
-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
combine_npz.py
41 lines (31 loc) · 1.01 KB
/
combine_npz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import numpy as np
import torch
import click
import PIL.Image
import dnnlib
import legacy
#----------------------------------------------------------------------------
@click.command()
@click.pass_context
@click.option('--npzs', help='comma separated .npz files', type=str, required=True, metavar='FILE')
@click.option('--outdir', help='Where to save the output images', type=str, required=True, metavar='DIR')
def combine_npz(
ctx: click.Context,
npzs: str,
outdir: str,
):
print('Combining .npz files...')
files = npzs.split(',')
os.makedirs(outdir, exist_ok=True)
ws = torch.tensor(())
for i,f in enumerate(files):
print(f)
w = torch.tensor(np.load(f)['w'])
ws = torch.cat((ws,w), 0)
print(ws.size())
np.savez(f'{outdir}/combined.npz', w=ws.numpy())
#----------------------------------------------------------------------------
if __name__ == "__main__":
combine_npz() # pylint: disable=no-value-for-parameter
#----------------------------------------------------------------------------