Skip to content

Commit

Permalink
Add CLI argument to sample more scales for moving in a direction
Browse files Browse the repository at this point in the history
  • Loading branch information
woctezuma committed Sep 19, 2020
1 parent 7be6e64 commit 15da9da
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions apply_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
default=5,
help="scalar factors for moving latent vectors along eigenvector",
)
parser.add_argument(
"-d_num",
"--degree_num",
type=int,
default=3,
help="number of scalar factors for moving latent vectors along eigenvector",
)
parser.add_argument("--ckpt", type=str, required=True, help="stylegan2 checkpoints")
parser.add_argument(
"--size", type=int, default=256, help="output image size of the generator"
Expand Down Expand Up @@ -58,29 +65,23 @@
latent = torch.randn(args.n_sample, 512, device=args.device)
latent = g.get_latent(latent)

direction = args.degree * eigvec[:, args.index].unsqueeze(0)
direction = eigvec[:, args.index].unsqueeze(0)

img, _ = g(
[latent],
truncation=args.truncation,
truncation_latent=trunc,
input_is_latent=True,
)
img1, _ = g(
[latent + direction],
truncation=args.truncation,
truncation_latent=trunc,
input_is_latent=True,
)
img2, _ = g(
[latent - direction],
truncation=args.truncation,
truncation_latent=trunc,
input_is_latent=True,
)
img_list = []

for u in torch.linspace(- args.degree, args.degree, args.d_num):

img_batch, _ = g(
[latent + u * direction],
truncation=args.truncation,
truncation_latent=trunc,
input_is_latent=True,
)

img_list.append(img_batch)

grid = utils.save_image(
torch.cat([img1, img, img2], 0),
torch.cat(img_list, 0),
f"{args.out_prefix}_index-{args.index}_degree-{args.degree}.png",
normalize=True,
range=(-1, 1),
Expand Down

0 comments on commit 15da9da

Please sign in to comment.