stargan-v2 icon indicating copy to clipboard operation
stargan-v2 copied to clipboard

About generated images

Open sumeyyegsu opened this issue 4 years ago • 3 comments

Thank you for your work. Using pretrained model, for some of celeba_hq images, I want to get generated images one by one (each generated image in a single .jpg file). However, using the existing system, I obtain only one file named reference.jpg that contain all generated images. How can I do that, what I need to change?

sumeyyegsu avatar Jan 24 '21 18:01 sumeyyegsu

Any luck with this yet?

jaker34 avatar Apr 23 '21 13:04 jaker34

It seems there is no such built-in function. You have to write it yourself if you want it.

usingnamespacestc avatar May 06 '21 03:05 usingnamespacestc

The function called is "translate_using_reference" in utils.py. Here's an edit to output singles images.

@torch.no_grad()
def translate_using_reference_singles(nets, args, x_src, x_ref, y_ref, filename):
    #Counter so each image has separate name
    image_count = 0 
    N, C, H, W = x_src.size()
    #Creates the row with source images and white box
    wb = torch.ones(1, C, H, W).to(x_src.device)
    x_src_with_wb = torch.cat([wb, x_src], dim=0)

    masks = nets.fan.get_heatmap(x_src) if args.w_hpf > 0 else None
    s_ref = nets.style_encoder(x_ref, y_ref)
    s_ref_list = s_ref.unsqueeze(1).repeat(1, N, 1)
    x_concat = [x_src_with_wb]
    # Creates each subsequent row of images
    for i, s_ref in enumerate(s_ref_list):
        x_fake = nets.generator(x_src, s_ref, masks=masks)
        #Rather than concat a row, we can output each image one at a time
        for x_fake_0 in x_fake:
            save_image(x_fake_0,1,filename + f'.{image_count:06d}.jpg')
            image_count+=1
            
        #x_fake_with_ref = torch.cat([x_ref[i:i+1], x_fake], dim=0)
        #x_concat += [x_fake_with_ref]

    #x_concat = torch.cat(x_concat, dim=0)
    #save_image(x_concat, N+1, filename)
    del x_concat

eric-yim avatar May 11 '21 16:05 eric-yim