elvisyjlin / AttGAN-PyTorch

AttGAN PyTorch Arbitrary Facial Attribute Editing: Only Change What You Want
MIT License
248 stars 61 forks source link

Strange Probelm #15

Closed xihuai18 closed 5 years ago

xihuai18 commented 5 years ago

I got similar output with different attribute vectors even with pretrained model image

elvisyjlin commented 5 years ago

It seems that the decoder of the generator did not get the right attributes. Could you provide more information? Did you train the model or test the model? How did you get the image output? If I can reproduce your problem, that will be easier to solve.

xihuai18 commented 5 years ago

I find the reason, I fine-tune your model using different attributes : [ "Bald", "Bangs", "Blond_Hair", "Brown_Hair", "Bushy_Eyebrows", "Eyeglasses", "Male", "Mouth_Slightly_Open", "Mustache", "Pale_Skin", "Wearing_Hat", "Young" ] I load the pretrained model but the attribute prediction layers in dec part with:

    def load(self, path):
        states = torch.load(path, map_location=lambda storage, loc: storage)
        if 'G' in states:
            states_G = {key:value for key, value in states['G'].items() if not key == "dec_layers.0.layers.0.weight" \
                       and not key == "dec_layers.1.layers.0.weight" }
#             states_G = states['G']
            self.G.load_state_dict(states_G, strict=False)
        if 'D' in states:
            states_D = states['D']
            self.D.load_state_dict(states_D, strict=False)
        if 'optim_G' in states:
            self.optim_G.load_state_dict(states['optim_G'])
        if 'optim_D' in states:
            self.optim_D.load_state_dict(states['optim_D'])

I get the output buy

def show(img):
    npimg = img.numpy()
    plt.rcParams["figure.figsize"] = (20, 10)
    plt.imshow(np.transpose(npimg, (1,2,0)), interpolation='nearest')
    plt.show()
show(vutils.make_grid(samples.cpu(), nrow=1, padding=10))

Could you give some tips on fine-tuning your model with different attributes?

xihuai18 commented 5 years ago

I think I have to speak about what I am doing. I am trying to use attention mechanism to limit the effect on the focused area according to the changed attributes(the same purpose as STGAN but with different method). And I am training the model from scratch, does the phenomena that the outputs of different attributes are the same appeared in your training procedure?

elvisyjlin commented 5 years ago

I got it now. I never try to fine-tune AttGAN, so it is actually an unexplored experiment. I'd like to make sure that you loaded the dataset with correct attributes, which are your target attributes. And read the training losses from the tensorboard. You will know you're making progress if the classification losses (dc_loss and gc_loss) drop down.

In my training procedure, the network first learnt to generate rough faces. Then it could generate faces with right attributes. The classification loss dropped and converged at this step. Afterwards, the faces from the network got better and better with respect to quality. When training from scratch, the right attributes appear on the generated faces after about 60k iterations. But in your case, you got beautiful faces without correct attributes. It's quite a weird result tho. One potential reason is that the given images and labels did not match each other.

I'm sorry that I accidentally wiped out my experimental results, such as training loss history, in the last month. Only CelebA-HQ 384x384 remains here https://github.com/elvisyjlin/AttGAN-PyTorch/issues/8#issuecomment-475630411. You can take a look if you need it.

By the way, STGAN did show a big progress in the field of face attribute manipulation. I really appreciate it. But my research is quite similar to that and also is under review...

xihuai18 commented 5 years ago

I am not a researcher now and I am trying because of interest. Thanks for your valuable job.

elvisyjlin commented 5 years ago

You're welcome. I suggest you try 1) to train the model from scratch without any code modification, then 2) to fine-tune on your target attributes. In this way, it is easier to figure out what goes wrong.