clovaai / stargan-v2

StarGAN v2 - Official PyTorch Implementation (CVPR 2020)
Other
3.48k stars 653 forks source link

About selecting the style codes #85

Open Nick-Sun1018 opened 3 years ago

Nick-Sun1018 commented 3 years ago

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!

youngjung commented 3 years ago

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?

Nick-Sun1018 commented 3 years ago

Yes, I understand, Thank you for your elaboration!