stargan-v2
stargan-v2 copied to clipboard
About selecting the style codes
out = torch.stack(out, dim=1) # (batch, num_domains, style_dim) idx = torch.LongTensor(range(y.size(0))).to(y.device) s = out[idx, y] # (batch, style_dim)
Thank you for your excellent works, I have a question about the code above. This part is from model.py, class StyleEncoder, how does s=out[idx, y] work? Don't we get the s equals to one of the element of h before stacking? I'll be very appreciated if you reply!
Hi,
y
holds indices for the target domain which should be the same with the reference images.
idx
is an enumeration of indices over the minibatch, i.e., [0, 1, ... B]
where B = batch size
.
out
before stacking is list of outputs for each domains, which are in shape of (B, style_dim)
.
We added 'stacking and indexing' procedure to collect style vectors from the target domains.
Does this answer your question?
Yes, I understand, Thank you for your elaboration!