BeautyGAN_pytorch
BeautyGAN_pytorch copied to clipboard
A Guide To Run The Code
After many hours, I finally can run the code 2333. Here are some tips to run the code:
- the train_MAKEMIX.txt means the names of those with-makeup pics in the MT dataset(train_SYMIX means non-makeup pics). It looks like this:
The names are duplicated in every row because the mask pics share the same name. The mask pics are in the "seg" folder of the MT dataset.
You can wirte a Python script to automatically read the names of the pics. As for me, I choose 2400 makeup pics for training, the rest 300 for testing. Remember to duplicate the name!
-
You can organize the dataset like this: Then you should change the paths in makeup.py. For example:
-
You can just download the VGG model from the Pytorch model zoo
import torchvision.models as models
#self.vgg = net.VGG()
#self.vgg.load_state_dict(torch.load('vgg_conv.pth'))
self.vgg=models.vgg16(pretrained=True)
And then, write a forward function on your own to seize the 4th conv layer:
#you can print the vgg16 model and find that the 4th layer conv's id is 17.
def vgg_forward(self,model,x):
for i in range(18):
x=model.features[i](x)
return x
Finally:
vgg_org=self.vgg_forward(self.vgg,org_A)
vgg_org = Variable(vgg_org.data).detach()
vgg_fake_A=self.vgg_forward(self.vgg,fake_A)
g_loss_A_vgg = self.criterionL2(vgg_fake_A, vgg_org) * self.lambda_A * self.lambda_vgg
......
(At this time the network speed of my home really sucks....It is so hard to download the ImageNet dataset, and it's hard to make the parameters match since the author have made some modifications to the VGG. I think the method above can work for you~)
At last, I am really grateful for the work that the author has done. It helps me a lot! Great thanks!
sorry for the spelling mistake the function should be like this:
and then you can call this function:
------------------ 原始邮件 ------------------ 发件人: "clg-rd"<[email protected]>; 发送时间: 2020年3月20日(星期五) 中午1:42 收件人: "wtjiang98/BeautyGAN_pytorch"<[email protected]>; 抄送: "how talented i am!"<[email protected]>;"Author"<[email protected]>; 主题: Re: [wtjiang98/BeautyGAN_pytorch] A Guide To Run The Code (#8)
it looks like there is an error in the function vgg_" forward " can you please fix it...
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Sorry, but I have a question. Is it necessary to train the vgg16 by ourselves? Or just use the pretrained model downloaded from Pytorch? ( and using features[:18] for the vgg forwarding)
@Jian-danai I think we can just use the pretrained model from Pytorch. I have run the code and the result was still good. The aim of vgg16 is to extract high-level features, and pretrained model can do this, too. By the way, training vgg model on ImageNet by ourselves takes much time lol😏。
@Jian-danai I think we can just use the pretrained model from Pytorch. I have run the code and the result was still good. The aim of vgg16 is to extract high-level features, and pretrained model can do this, too. By the way, training vgg model on ImageNet by ourselves takes much time lol😏。 I see. Thank you very much.
By the way, can you change the batch size? When I change the batch size from 1 to 2, I will get this error:
Traceback (most recent call last):
File "train.py", line 83, in
Note that the masks and the facial images are loaded together:
for self.i, (img_A, img_B, mask_A, mask_B) in enumerate(self.data_loader_train):
So when you change the batch_size(e.g. batch_size=2), you should change such lines like this:
mask_src = mask_src.expand(2, 3, mask_src.size(2), mask_src.size(2)).squeeze()
Because expand(a,b,c,d) is to create a tensor whose shape is (a,b,c,d). In this case, a is the batch size.
By the way, no need to change the batch_size because: generating makeup images is a 'specific' task ; larger batch means heavier requirement on GPU memory. As for batch=1(no modification to author's code except the vgg I mentioned before), it takes about 5000MB GPU memory(I checked it via 'nvidia-smi' command). You may exceed your GPU memory if you enlarge your batch size.
Thanks for your reply, but I do not understand why enlarging my batch size is meaningless. If I have enough GPU mem, will the larger batch_size contribute to the higher training speed or higher accuracy or not?
I have tried modifiying 'train.py'
parser.add_argument('--batch_size', default='2', type=int, help='batch_size')
and then modified 'solver_makeup.py' with
mask_src = mask_src.expand(2, 3, mask_src.size(2), mask_src.size(2)).squeeze()
mask_tar = mask_tar.expand(2, 3, mask_tar.size(2), mask_tar.size(2)).squeeze()
but still got this error (actually yesterday I have tried modifying these two files)
Traceback (most recent call last):
File "train.py", line 83, in
One more question, the multi-GPU mode doesn't work, right? (because I have not found the related code for multi-GPU computation....)
I am checking on this; The author did not implement Multi-GPU, you need to do it yourself~~
@TalentedMUSE Hey is is any chance for you to share your code?
Hi, does anyone know why the BeautyGAN authors choose 6 residual blocks in the generator but not 9 as in CycleGAN because the training images are 256*256?
I also find that some unofficial implementations based on tensorflow are using 9 blocks. For example, https://github.com/baldFemale/beautyGAN-tf-Implement
It's really weird!
I am checking on this; The author did not implement Multi-GPU, you need to do it yourself~~
Thanks for your sharing, but I found the data set mask pictures are all black?no any other content like this, it‘s really normal?
@yql0612 They are not all black. If you open the image and have a look you will find that there are some grey segmentation labels.
I browsed all the pictures and found that they are still black. If it is convenient, can you provide the data set you review. Thank you very much.~
------------------ 原始邮件 ------------------ 发件人: "DateBro"<[email protected]>; 发送时间: 2020年8月5日(星期三) 上午10:58 收件人: "wtjiang98/BeautyGAN_pytorch"<[email protected]>; 抄送: "1079578049"<[email protected]>; "Mention"<[email protected]>; 主题: Re: [wtjiang98/BeautyGAN_pytorch] A Guide To Run The Code (#8)
@yql0612 They are not all black. If you open the image and have a look you will find that there are some grey segmentation labels.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
@yql0612 I have opened your screenshot in a new tab and found it not all black. If you look carefully, you can find that there are some face segmentations, whose grey value is slightly bigger than 0.
OK,I see... thanks~
------------------ 原始邮件 ------------------ 发件人: "DateBro"<[email protected]>; 发送时间: 2020年8月5日(星期三) 下午2:34 收件人: "wtjiang98/BeautyGAN_pytorch"<[email protected]>; 抄送: "1079578049"<[email protected]>; "Mention"<[email protected]>; 主题: Re: [wtjiang98/BeautyGAN_pytorch] A Guide To Run The Code (#8)
@yql0612 I have opened your screenshot in a new tab and found it not all black. If you look carefully, you can find that there are some face segmentations, whose grey value is slightly bigger than 0.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
@yql0612 They are not all black. If you open the image and have a look you will find that there are some grey segmentation labels.
When I trained according this project,I meet some problems as follows: File "/home/data_mount_2/yql/makeup_model/BeautyGAN_pytorch-master/data_loaders/makeup.py", line 79, in getitem image_B = Image.open(os.path.join(self.image_path, "test/makeup", getattr(self, "test_" + self.cls_B + "filenames")[index % getattr(self, 'num_of_test' + self.cls_list[1] + 'data')])).convert("RGB") File "/home/data_mount_2/yql/conda/envs/PSGAN/lib/python3.7/site-packages/PIL/Image.py", line 2878, in open fp = builtins.open(filename, "rb") FileNotFoundError: [Errno 2] No such file or directory: '/home/data_mount_2/yql/dataset/BeautyGAN/data/test/makeup/train_MAKEMIX.txt'
But when I add the txt to /test/makeup folder, there are another problem arises like this: File "/home/data_mount_2/yql/makeup_model/BeautyGAN_pytorch-master/data_loaders/makeup.py", line 79, in getitem image_B = Image.open(os.path.join(self.image_path, "test/makeup", getattr(self, "test" + self.cls_B + "filenames")[index % getattr(self, 'num_of_test' + self.cls_list[1] + '_data')])).convert("RGB") File "/home/data_mount_2/yql/conda/envs/PSGAN/lib/python3.7/site-packages/PIL/Image.py", line 2931, in open "cannot identify image file %r" % (filename if filename else fp) PIL.UnidentifiedImageError: cannot identify image file '/home/data_mount_2/yql/dataset/BeautyGAN/data/test/makeup/train_MAKEMIX.txt' I have try many times to solve it, but still not work, I sincerely need your help, Thank you very much!
Thank you for your tips! It helps a lot!
Has there anyone met this problem?? NEED HELP!!!!
Has there anyone met this problem?? NEED HELP!!!!
Could you check if your .txt file is empty or not?
Has there anyone met this problem?? NEED HELP!!!!
Could you check if your .txt file is empty or not?
My txt is like this,I don't konw what else to do,please help!!
@wangyyff I think you should double-check your txt file. Pls follow the guideline here https://github.com/wtjiang98/BeautyGAN_pytorch/issues/8#issue-569602870
Are you using Makeup Transfer Dataset or Custom dataset?
I write the txt like the guideline and put them in right place,but I am sorry that I don't know what is custom or makeup transfer dataset. Could you please tell me more?
@wangyyff I think you should double-check your txt file. Plt follow the guideline here #8 (comment)
Are you using Makeup Transfer Dataset or Custom dataset?
I write the txt like the guideline and put them in right place,but I am sorry that I don't know what is custom or makeup transfer dataset. Could you please tell me more?
@wangyyff I think you should double-check your txt file. Plt follow the guideline here #8 (comment)
Are you using Makeup Transfer Dataset or Custom dataset?
I am so sorry! I have solved this problem but now there is a new problem! I didn't have the folder "addings" and the file "vgg_conv.pth". Where can I find them???
@wangyyff I think you should double-check your txt file. Plt follow the guideline here #8 (comment) Are you using Makeup Transfer Dataset or Custom dataset?
I am so sorry! I have solved this problem but now there is a new problem! I didn't have the folder "addings" and the file "vgg_conv.pth". Where can I find them???
download the vgg model in "https://bethgelab.org/media/uploads/pytorch_models/vgg_conv.pth".
@wangyyff I think you should double-check your txt file. Plt follow the guideline here #8 (comment) Are you using Makeup Transfer Dataset or Custom dataset?
I am so sorry! I have solved this problem but now there is a new problem! I didn't have the folder "addings" and the file "vgg_conv.pth". Where can I find them???
download the vgg model in "https://bethgelab.org/media/uploads/pytorch_models/vgg_conv.pth".
Thanks for all your help!! Now there's another problem. Maybe I'm just a foolish! ! All the images are in "makeup" and the txts are in "makeup_final. Where do I need to rewrite?
After many hours, I finally can run the code 2333. Here are some tips to run the code:
- the train_MAKEMIX.txt means the names of those with-makeup pics in the MT dataset(train_SYMIX means non-makeup pics). It looks like this:
The names are duplicated in every row because the mask pics share the same name. The mask pics are in the "seg" folder of the MT dataset.
You can wirte a Python script to automatically read the names of the pics. As for me, I choose 2400 makeup pics for training, the rest 300 for testing. Remember to duplicate the name!
- You can organize the dataset like this: Then you should change the paths in makeup.py. For example:
- You can just download the VGG model from the Pytorch model zoo
import torchvision.models as models #self.vgg = net.VGG() #self.vgg.load_state_dict(torch.load('vgg_conv.pth')) self.vgg=models.vgg16(pretrained=True)
And then, write a forward function on your own to seize the 4th conv layer:
#you can print the vgg16 model and find that the 4th layer conv's id is 17. def vgg_forward(self,model,x): for i in range(18): x=model.features[i](x) return x
Finally:
vgg_org=self.vgg_forward(self.vgg,org_A) vgg_org = Variable(vgg_org.data).detach() vgg_fake_A=self.vgg_forward(self.vgg,fake_A) g_loss_A_vgg = self.criterionL2(vgg_fake_A, vgg_org) * self.lambda_A * self.lambda_vgg ......
(At this time the network speed of my home really sucks....It is so hard to download the ImageNet dataset, and it's hard to make the parameters match since the author have made some modifications to the VGG. I think the method above can work for you~)
At last, I am really grateful for the work that the author has done. It helps me a lot! Great thanks!
Hello, I'm just starting to learn, so I don't understand a lot. Would you please share your code? Thanks a million!
After many hours, I finally can run the code 2333. Here are some tips to run the code:
- the train_MAKEMIX.txt means the names of those with-makeup pics in the MT dataset(train_SYMIX means non-makeup pics). It looks like this:
The names are duplicated in every row because the mask pics share the same name. The mask pics are in the "seg" folder of the MT dataset. You can wirte a Python script to automatically read the names of the pics. As for me, I choose 2400 makeup pics for training, the rest 300 for testing. Remember to duplicate the name!
- You can organize the dataset like this: Then you should change the paths in makeup.py. For example:
- You can just download the VGG model from the Pytorch model zoo
import torchvision.models as models #self.vgg = net.VGG() #self.vgg.load_state_dict(torch.load('vgg_conv.pth')) self.vgg=models.vgg16(pretrained=True)
And then, write a forward function on your own to seize the 4th conv layer:
#you can print the vgg16 model and find that the 4th layer conv's id is 17. def vgg_forward(self,model,x): for i in range(18): x=model.features[i](x) return x
Finally:
vgg_org=self.vgg_forward(self.vgg,org_A) vgg_org = Variable(vgg_org.data).detach() vgg_fake_A=self.vgg_forward(self.vgg,fake_A) g_loss_A_vgg = self.criterionL2(vgg_fake_A, vgg_org) * self.lambda_A * self.lambda_vgg ......
(At this time the network speed of my home really sucks....It is so hard to download the ImageNet dataset, and it's hard to make the parameters match since the author have made some modifications to the VGG. I think the method above can work for you~) At last, I am really grateful for the work that the author has done. It helps me a lot! Great thanks!
Hello, I'm just starting to learn, so I don't understand a lot. Would you please share your code? Thanks a million!
he change the file solver_makeup.py for vgg and create 4 txt files(train_MAKEMIX,test_MAKEMIX,train_SYMIX ,test_SYMIX )
After many hours, I finally can run the code 2333. Here are some tips to run the code:
- the train_MAKEMIX.txt means the names of those with-makeup pics in the MT dataset(train_SYMIX means non-makeup pics). It looks like this:
The names are duplicated in every row because the mask pics share the same name. The mask pics are in the "seg" folder of the MT dataset. You can wirte a Python script to automatically read the names of the pics. As for me, I choose 2400 makeup pics for training, the rest 300 for testing. Remember to duplicate the name!
- You can organize the dataset like this: Then you should change the paths in makeup.py. For example:
- You can just download the VGG model from the Pytorch model zoo
import torchvision.models as models #self.vgg = net.VGG() #self.vgg.load_state_dict(torch.load('vgg_conv.pth')) self.vgg=models.vgg16(pretrained=True)
And then, write a forward function on your own to seize the 4th conv layer:
#you can print the vgg16 model and find that the 4th layer conv's id is 17. def vgg_forward(self,model,x): for i in range(18): x=model.features[i](x) return x
Finally:
vgg_org=self.vgg_forward(self.vgg,org_A) vgg_org = Variable(vgg_org.data).detach() vgg_fake_A=self.vgg_forward(self.vgg,fake_A) g_loss_A_vgg = self.criterionL2(vgg_fake_A, vgg_org) * self.lambda_A * self.lambda_vgg ......
(At this time the network speed of my home really sucks....It is so hard to download the ImageNet dataset, and it's hard to make the parameters match since the author have made some modifications to the VGG. I think the method above can work for you~) At last, I am really grateful for the work that the author has done. It helps me a lot! Great thanks!
Hello, I'm just starting to learn, so I don't understand a lot. Would you please share your code? Thanks a million!
he change the file solver_makeup.py for vgg and create 4 txt files(train_MAKEMIX,test_MAKEMIX,train_SYMIX ,test_SYMIX )
Thanks for your reply! But after i have tried for many days i can not still run the code. So would you mind sharing your code for me? Thanks a million!
@Hellboykun I think your results are not that bad. Mine look terrible. (Left to right: Source | Reference | Output)
But I found the original pretrained model is very stable. Check in Holan's Github: https://github.com/Honlan/BeautyGAN Or direct to Google Drive: https://drive.google.com/drive/folders/1pgVqnF2-rnOxcUQ3SO4JwHUFTdiSe5t9
Sadly, it is tensorflow, and they doesn't provide training code!!