imlixinyang / HiSD

Official pytorch implementation of paper "Image-to-image Translation via Hierarchical Style Disentanglement" (CVPR2021 Oral).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About beard model

lovejing0306 opened this issue · comments

I am very interested in your jobs, can you release your beard model?

Hi, @lovejing0306, I'm sorry to infer you that the beard model has been unavailable since the training machine has been broken. But you can get it by simply modify the preprocessor and config file. It wouldn't take long for even only one GPU.
If you have any questions for you training, please contract me again.

Hi, @lovejing0306, I'm sorry to infer you that the beard model has been unavailable since the training machine has been broken. But you can get it by simply modify the preprocessor and config file. It wouldn't take long for even only one GPU. If you have any questions for you training, please contract me again.

Thanks for your reply, I will try it .

Hi, @lovejing0306, I'm sorry to infer you that the beard model has been unavailable since the training machine has been broken. But you can get it by simply modify the preprocessor and config file. It wouldn't take long for even only one GPU. If you have any questions for you training, please contract me again.

Hi, I am sorry to bother you. I want to remove beard in face. So I modify the preprocessor and config file as below:

preprocessor:

parser = argparse.ArgumentParser()
parser.add_argument('--img_path', type=str, default=None)
parser.add_argument('--label_path', type=str)
parser.add_argument("--target_path", type=str)
parser.add_argument("--start", type=int, default=3002)
parser.add_argument("--end", type=int, default=30002)
opts = parser.parse_args()

target_path = opts.target_path

os.makedirs(target_path, exist_ok=True)

Tags_Attributes = {
    # 'Bangs': ['with', 'without'],
    # 'Eyeglasses': ['with', 'without'],
    # 'HairColor': ['black', 'blond', 'brown'],
    'Beard': ['with', 'without'],
}

for tag in Tags_Attributes.keys():
    for attribute in Tags_Attributes[tag]:
        open(os.path.join(target_path, f'{tag}_{attribute}.txt'), 'w')

# celeba-hq
celeba_imgs = opts.img_path
celeba_label = opts.label_path

with open(celeba_label) as f:
    lines = f.readlines()

for line in tqdm.tqdm(lines[opts.start:opts.end]):
    line = line.split()
    # filename = os.path.join(os.path.abspath(celeba_imgs), line[0])
    filename = line[0]

    # Use only gender and age as tag-irrelevant conditions. Add other labels if you want.
    if int(line[25]) == 1:
        with open(os.path.join(target_path, 'Beard_without.txt'), mode='a') as f:
            f.write(f'{filename} {line[21]} {line[40]}\n')
    elif int(line[25]) == -1:
        with open(os.path.join(target_path, 'Beard_with.txt'), mode='a') as f:
            f.write(f'{filename} {line[21]} {line[40]}\n')

the config file :

# logger options
image_save_iter: 1000         # How often do you want to save output images during training
snapshot_save_iter: 10000     # How often do you want to save trained models
log_iter: 10                  # How often do you want to log the training stats

# optimization options
total_iterations: 600000
batch_size: 8
num_workers: 1
weight_decay: 0
beta1: 0
beta2: 0.99
init: kaiming
lr_dis: 0.0001
lr_gen_mappers: 0.000001
lr_gen_others: 0.0001

# 
adv_w: 1
sty_w: 1
rec_w: 1

style_dim: 256
noise_dim: 32

discriminators:
  # No normalization (Attribute-specific)
  channels: [32, 64, 128, 256, 512, 512, 512]
extractors:
  # No normalization (Tag-specific)
  channels: [32, 64, 128, 256, 512, 512, 512]
encoder:
  # Instance Normalization (Shared)
  channels: [64, 128, 256]
translators:
  # Adaptive Instance Normalization (Tag-specific)
  channels: [64, 64, 64, 64, 64, 64, 64, 64]
decoder:
   # Instance Normalization (Shared)
  channels: [256, 128, 64]
mappers:
  # No normalization (Attribute-specific)
  # Last num of pre_channels should be equal to the first num of post_channels
  pre_channels: [256, 256, 256]
  post_channels: [256, 256, 256]

img_dir: /datasets/face_parsing/CelebAMask-HQ/CelebA-HQ-img-512
tags:
  -
    name: Beard
    tag_irrelevant_conditions_dim: 2
    attributes:
      -
        name: 'with'
        filename: /datasets/face_parsing/CelebAMask-HQ/Beard_with.txt
      -
        name: 'without'
        filename: /datasets/face_parsing/CelebAMask-HQ/Beard_without.txt

# data options
input_dim: 3                  # number of image channels
new_size: 256                 # first resize the shortest image side to this size
crop_image_height: 256        # random crop image of this height
crop_image_width: 256         # random crop image of this width

Can you tell me, the preprocessor and config file is right ?

I think they are right and you can have a try to train with them~

I think they are right and you can have a try to train with them~

Hi, bother you again. I use the preprocessor and config file in my training code, but I meet two questions.

Question 1, the training visual quality is not really well, only few images implement the transfer from beard to no beard.

Question 2, the training visual quality get worse from 100000 steps.

I save the visual image in baidu cloud. Can you give me some advice ?

链接: https://pan.baidu.com/s/1HGcRhnIkWpdyMJ4NHJ5XCQ 提取码: fhh7

I am looking forward to your reply.

I think there are some points you can try:

  1. turn off the ALI part in discriminator by setting s[:] = 0 after
    def forward(self, x, s, y, i):
  2. since the images with beard are always male, modify the preprocess file to:
    if int(line[25]) == 1 and int(line[25]) == 1:
        with open(os.path.join(target_path, 'Beard_without.txt'), mode='a') as f:
            f.write(f'{filename} {line[40]}\n')
    elif int(line[25]) == -1 and int(line[25]) == 1:
        with open(os.path.join(target_path, 'Beard_with.txt'), mode='a') as f:
            f.write(f'{filename} {line[40]}\n')

Thanks for your advice @imlixinyang , I want to confirm these points with you.

About 1, I update the code as below, is right ?

def forward(self, x, s, y, i):
        s[:] = 0
        f = self.conv(x)
        fsy = torch.cat([f, tile_like(s, f), tile_like(y, f)], 1)
        return self.fcs[i](fsy).view(f.size(0), 2, -1)

About 2, remove the female samples from the dataset ?

Yes. Please have a try and tell me the results.

Yes. Please have a try and tell me the results.

OK, thanks. I prepared two sets of experiments. The first is remove female samples, second is remove female samples + update code s[:] = 0.

Hi, I am coming @imlixinyang .
I spent two weeks for "remove female samples" and "remove female samples + update code s[:] = 0".

The first set of experiments is "remove female samples" , the intermediate results in this link 链接: https://pan.baidu.com/s/1D8N8qqwrXB6qOueaBIwL0A 提取码: tab0

I found that there is a color deviation by view the training visual quality in the first set of experiments.

The second set of experiment is "remove female samples + update code s[:] = 0", the intermediate results in this link 链接: https://pan.baidu.com/s/1Ui6gABqD4GVFODxJrgv8wg 提取码: n87a

By setting s[:] = 0, the color deviation problem disappeared. But there are new questions, I summarize the problems as follow:

  1. some results show the identity information of person is changed
  2. some results show the image information is not well reconstructed
  3. the transfer results is not good enough

Can you give me some advice about improve generation quality ?

Thank you for your sharing results. In the rebuttal of HiSD, we also conduct experiments for beard and the results for latent-guided tasks are:
image
By removing female samples and updating code s[:] = 0, I think most of our settings are the same but you get unsatisfying results, especially for reference-guided task. In my training, HiSD is always trained with multiple tag and I suspect that the joint training of other tags may help the disentanglement and quality. Removing female examples severely decreases the number of images, which may be a major problem of beard model. Maybe you could use two more tags to see if it would help (not sure).
Any further experiments and questions are welcomed here and I would try my best to help you. @lovejing0306

Thanks for your reply.
I am very interested in your work, so I want to have a deeply discussion with you. Would you mind adding my wechat (my ID: lovejing0306) ?

Looking forward for reply. @imlixinyang

hello, after modified s[:] = 0, I met a problem,
image
Have you ever met this before? Looking forward to your replay!

hello, after modified s[:] = 0, I met a problem, image Have you ever met this before? Looking forward to your replay!

If you want to set s[:] = 0, you should write the code 's = torch.zeros_like(s)'