Closed wjun0830 closed 4 years ago
I too wanna know how to test on our custom datasets with the pre-trained model. Have you tested @wjun0830?
Nope not yet. I think i have to modify the code if i want to test the whole custom set since testset is already specified in Class when training. However, by swapping a image in celeba result direc with custom image, I could test it on a single image.
2019년 11월 15일 (금) 오후 6:27, Ujjawal Kumar Singh notifications@github.com님이 작성:
I too wanna know how to test on our custom datasets with the pre-trained model. Have you tested @wjun0830 https://github.com/wjun0830?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yunjey/stargan/issues/108?email_source=notifications&email_token=AHQYPMC6AHTH77OSFL4LJD3QTZTP3A5CNFSM4JILK3VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEE23KQ#issuecomment-554282410, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHQYPME63NNUA3MTP6INZX3QTZTP3ANCNFSM4JILK3VA .
Thank you Wjun. But I tested it as I used to test with normal gan. As we have the checkpoints of the generator, we can load the checkpoints after defining the generator model. Then use it for new image generation. By the way, I couldn't get the final generated image due to my Runtime Error: CUDA out of memory. But you can try it. Most probably, it will give the result. This is the code:-
import torch import cv2 import numpy as np import model import solver from torch.backends import cudnn from torchvision.utils import save_image from PIL import Image
model = model.Generator() model = model.cuda() model.load_state_dict(torch.load("./stargan_celeba_256/models/200000-G.ckpt"))
pilImg = Image.open("data/celeba/test/input_1573800763_075695.jpg") npImg = np.array(pilImg)
example_img = torch.from_numpy(npImg).float().unsqueeze(0) print(example_img.shape) example_img = example_img.permute(0, 3, 1, 2) print(example_img.shape) print("======RGB data [0, 255]======") print(example_img) example_img = example_img.div(255) example_img = example_img.sub(0.5) example_img = example_img.div(0.5) example_img = example_img.cuda()
example_c = torch.cuda.FloatTensor([[0,0,1,0,0]])
imgGen = model(example_img, example_c) save_image(imgGen, "./%s.png" % 100, normalize=True)
On Fri, Nov 15, 2019 at 3:17 PM wjun0830 notifications@github.com wrote:
Nope not yet. I think i have to modify the code if i want to test the whole custom set since testset is already specified in Class when training. However, by swapping a image in celeba result direc with custom image, I could test it on a single image.
2019년 11월 15일 (금) 오후 6:27, Ujjawal Kumar Singh <notifications@github.com
님이 작성:
I too wanna know how to test on our custom datasets with the pre-trained model. Have you tested @wjun0830 https://github.com/wjun0830?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub < https://github.com/yunjey/stargan/issues/108?email_source=notifications&email_token=AHQYPMC6AHTH77OSFL4LJD3QTZTP3A5CNFSM4JILK3VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEE23KQ#issuecomment-554282410 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AHQYPME63NNUA3MTP6INZX3QTZTP3ANCNFSM4JILK3VA
.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/yunjey/stargan/issues/108?email_source=notifications&email_token=AH2BJCHEBSRPE6ROKLKSQXLQTZV2ZA5CNFSM4JILK3VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEE4ZAQ#issuecomment-554290306, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH2BJCCQOLSJB2N2CI2WVXDQTZV2ZANCNFSM4JILK3VA .
I checked with this code on another machine, but the result is not good.
Oh thanks. Can I see the results? I thought stargan needs the picture with attributes array so this code may not work. when you see the torch code in its github, they preprocess image with the matching attributes. Did you consider that?
2019년 11월 15일 (금) 오후 11:59, Ujjawal Kumar Singh notifications@github.com님이 작성:
I checked with this code on another machine, but the result is not good.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yunjey/stargan/issues/108?email_source=notifications&email_token=AHQYPMAYK7LY2KBF3GTXW5TQT22LLA5CNFSM4JILK3VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEFVQCQ#issuecomment-554391562, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHQYPMCXL2MTSIVTFJFFJ2DQT22LLANCNFSM4JILK3VA .
Ujjawal, Could you tell me which package should i install to get the package 'model'?
I am not the supervisor in my server and I should request to install some models but when I try to install 'model' it fails.
import model doesnt work for me, so I tried pip install model but there is no matching distribution. Can u tell me what the package name is?
2019년 11월 16일 (토) 오전 2:36, 문원준 wjun0830@gmail.com님이 작성:
Oh thanks. Can I see the results? I thought stargan needs the picture with attributes array so this code may not work. when you see the torch code in its github, they preprocess image with the matching attributes. Did you consider that?
2019년 11월 15일 (금) 오후 11:59, Ujjawal Kumar Singh notifications@github.com님이 작성:
I checked with this code on another machine, but the result is not good.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yunjey/stargan/issues/108?email_source=notifications&email_token=AHQYPMAYK7LY2KBF3GTXW5TQT22LLA5CNFSM4JILK3VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEFVQCQ#issuecomment-554391562, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHQYPMCXL2MTSIVTFJFFJ2DQT22LLANCNFSM4JILK3VA .
You have whole folder of stargan-pytorch. In this folder there are 8-9 files. There are model.py,solver.py, data_loader.py etc. So you can these files as:- import solver import model import data_loader.py etc. model is not inbuilt package so it can't be installed by pip install model. It's just a python file.
On Sun 17 Nov, 2019, 11:04 wjun0830, notifications@github.com wrote:
Ujjawal, Could you tell me which package should i install to get the package 'model'?
I am not the supervisor in my server and I should request to install some models but when I try to install 'model' it fails.
import model doesnt work for me, so I tried pip install model but there is no matching distribution. Can u tell me what the package name is?
2019년 11월 16일 (토) 오전 2:36, 문원준 wjun0830@gmail.com님이 작성:
Oh thanks. Can I see the results? I thought stargan needs the picture with attributes array so this code may not work. when you see the torch code in its github, they preprocess image with the matching attributes. Did you consider that?
2019년 11월 15일 (금) 오후 11:59, Ujjawal Kumar Singh < notifications@github.com>님이 작성:
I checked with this code on another machine, but the result is not good.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub < https://github.com/yunjey/stargan/issues/108?email_source=notifications&email_token=AHQYPMAYK7LY2KBF3GTXW5TQT22LLA5CNFSM4JILK3VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEFVQCQ#issuecomment-554391562 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AHQYPMCXL2MTSIVTFJFFJ2DQT22LLANCNFSM4JILK3VA
.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/yunjey/stargan/issues/108?email_source=notifications&email_token=AH2BJCD6GWQRKCX3PSUH6K3QUDJW7A5CNFSM4JILK3VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEICUAA#issuecomment-554707456, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH2BJCAKH6VUFZHYSY52QHLQUDJW7ANCNFSM4JILK3VA .
Oh, I missed that. and also the tensor in the code. Sorry.. Sorry but I have no idea how to improve that. Maybe I will keep this issue open and wait..
Maybe You will wanna try this way. This result is also not good but maybe a hint for you. I changed the function test in original code in solver.py.
here is the code I utilized your code into the original code and I still do not know why this is not working. '''
def test(self):
"""Translate images using StarGAN trained on a single dataset."""
# Load the trained generator.
self.restore_model(self.test_iters)
# Set data loader.
if self.dataset == 'CelebA':
data_loader = self.celeba_loader
elif self.dataset == 'RaFD':
data_loader = self.rafd_loader
with torch.no_grad():
i = 0;
pilImg = Image.open("data/celeba/images/028136.jpg")
npImg = np.array(pilImg)
example_img = torch.from_numpy(npImg).float().unsqueeze(0)
example_img = example_img.permute(0,3,1,2)
example_img = example_img.div(255)
example_img = example_img.sub(0.5)
example_img = example_img.div(0.5)
x_real = example_img.cuda()
c_org = torch.cuda.FloatTensor([[1,-1,-1,1,1,-1,-1,-1]])
x_real = x_real.to(self.device)
x_fake_list = [x_real]
c_trg_list = self.create_labels(c_org, self.c_dim, self.dataset, self.selected_attrs)
for c_trg in c_trg_list:
x_fake_list.append(self.G(x_real, c_trg))
for num, k in enumerate(x_fake_list):
result_path = os.path.join(self.result_dir, '{}-images.jpg'.format((i)*9+num))
save_image(self.denorm(k.data.cpu()), result_path, nrow=1, padding=0)
print('Saved real and fake images into {}...'.format(result_path))
'''
c_org should be only a list of 5 items because the model is trained on 5 attributes only. You can put value 0 or 1 based on which attribute you wanna get as a result. For example [0,0,1,0,0] for brown hair and [0,1,0,0,0] for Blond hair.
On Mon, Nov 18, 2019 at 5:47 AM wjun0830 notifications@github.com wrote:
Maybe You will wanna try this way. This result is also not good but maybe a hint for you. I changed the function test in original code in solver.py.
here is the code I utilized your code into the original code and I still do not know why this is not working. '''
def test(self): """Translate images using StarGAN trained on a single dataset."""
Load the trained generator.
self.restore_model(self.test_iters) # Set data loader. if self.dataset == 'CelebA': data_loader = self.celeba_loader elif self.dataset == 'RaFD': data_loader = self.rafd_loader with torch.no_grad(): i = 0; pilImg = Image.open("data/celeba/images/028136.jpg") npImg = np.array(pilImg) example_img = torch.from_numpy(npImg).float().unsqueeze(0) example_img = example_img.permute(0,3,1,2) example_img = example_img.div(255) example_img = example_img.sub(0.5) example_img = example_img.div(0.5) x_real = example_img.cuda() c_org = torch.cuda.FloatTensor([[1,-1,-1,1,1,-1,-1,-1]]) x_real = x_real.to(self.device) x_fake_list = [x_real] c_trg_list = self.create_labels(c_org, self.c_dim, self.dataset, self.selected_attrs) for c_trg in c_trg_list: x_fake_list.append(self.G(x_real, c_trg)) for num, k in enumerate(x_fake_list): result_path = os.path.join(self.result_dir, '{}-images.jpg'.format((i)*9+num)) save_image(self.denorm(k.data.cpu()), result_path, nrow=1, padding=0) print('Saved real and fake images into {}...'.format(result_path))
'''
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/yunjey/stargan/issues/108?email_source=notifications&email_token=AH2BJCFU2N77RDRQ4EF74D3QUHNIHA5CNFSM4JILK3VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEI2MDY#issuecomment-554804751, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH2BJCDKFYWBERED4DEA7FDQUHNIHANCNFSM4JILK3VA .
Oh sorry didnt change that for you I trained with 8attributes and thats why the tensor shape is like that
2019년 11월 18일 (월) 오후 2:59, Ujjawal Kumar Singh notifications@github.com님이 작성:
c_org should be only a list of 5 items because the model is trained on 5 attributes only. You can put value 0 or 1 based on which attribute you wanna get as a result. For example [0,0,1,0,0] for brown hair and [0,1,0,0,0] for Blond hair.
On Mon, Nov 18, 2019 at 5:47 AM wjun0830 notifications@github.com wrote:
Maybe You will wanna try this way. This result is also not good but maybe a hint for you. I changed the function test in original code in solver.py.
here is the code I utilized your code into the original code and I still do not know why this is not working. '''
def test(self): """Translate images using StarGAN trained on a single dataset."""
Load the trained generator.
self.restore_model(self.test_iters)
Set data loader.
if self.dataset == 'CelebA': data_loader = self.celeba_loader elif self.dataset == 'RaFD': data_loader = self.rafd_loader
with torch.no_grad(): i = 0; pilImg = Image.open("data/celeba/images/028136.jpg") npImg = np.array(pilImg) example_img = torch.from_numpy(npImg).float().unsqueeze(0) example_img = example_img.permute(0,3,1,2) example_img = example_img.div(255) example_img = example_img.sub(0.5) example_img = example_img.div(0.5) x_real = example_img.cuda() c_org = torch.cuda.FloatTensor([[1,-1,-1,1,1,-1,-1,-1]]) x_real = x_real.to(self.device) x_fake_list = [x_real] c_trg_list = self.create_labels(c_org, self.c_dim, self.dataset, self.selected_attrs) for c_trg in c_trg_list: x_fake_list.append(self.G(x_real, c_trg)) for num, k in enumerate(x_fake_list): result_path = os.path.join(self.result_dir, '{}-images.jpg'.format((i)*9+num)) save_image(self.denorm(k.data.cpu()), result_path, nrow=1, padding=0) print('Saved real and fake images into {}...'.format(result_path))
'''
— You are receiving this because you commented. Reply to this email directly, view it on GitHub < https://github.com/yunjey/stargan/issues/108?email_source=notifications&email_token=AH2BJCFU2N77RDRQ4EF74D3QUHNIHA5CNFSM4JILK3VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEI2MDY#issuecomment-554804751 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AH2BJCDKFYWBERED4DEA7FDQUHNIHANCNFSM4JILK3VA
.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yunjey/stargan/issues/108?email_source=notifications&email_token=AHQYPMEWKM6UHWC5W2DVVZDQUIVNNA5CNFSM4JILK3VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEJJGUA#issuecomment-554865488, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHQYPMDHAGNTOBIOJYDOA6DQUIVNNANCNFSM4JILK3VA .
And also if you look at celeba attr file, it has 1 and -1 values and that is why I changed the value
2019년 11월 18일 (월) 오후 3:19, 문원준 wjun0830@gmail.com님이 작성:
Oh sorry didnt change that for you I trained with 8attributes and thats why the tensor shape is like that
2019년 11월 18일 (월) 오후 2:59, Ujjawal Kumar Singh notifications@github.com님이 작성:
c_org should be only a list of 5 items because the model is trained on 5 attributes only. You can put value 0 or 1 based on which attribute you wanna get as a result. For example [0,0,1,0,0] for brown hair and [0,1,0,0,0] for Blond hair.
On Mon, Nov 18, 2019 at 5:47 AM wjun0830 notifications@github.com wrote:
Maybe You will wanna try this way. This result is also not good but maybe a hint for you. I changed the function test in original code in solver.py.
here is the code I utilized your code into the original code and I still do not know why this is not working. '''
def test(self): """Translate images using StarGAN trained on a single dataset."""
Load the trained generator.
self.restore_model(self.test_iters)
Set data loader.
if self.dataset == 'CelebA': data_loader = self.celeba_loader elif self.dataset == 'RaFD': data_loader = self.rafd_loader
with torch.no_grad(): i = 0; pilImg = Image.open("data/celeba/images/028136.jpg") npImg = np.array(pilImg) example_img = torch.from_numpy(npImg).float().unsqueeze(0) example_img = example_img.permute(0,3,1,2) example_img = example_img.div(255) example_img = example_img.sub(0.5) example_img = example_img.div(0.5) x_real = example_img.cuda() c_org = torch.cuda.FloatTensor([[1,-1,-1,1,1,-1,-1,-1]]) x_real = x_real.to(self.device) x_fake_list = [x_real] c_trg_list = self.create_labels(c_org, self.c_dim, self.dataset, self.selected_attrs) for c_trg in c_trg_list: x_fake_list.append(self.G(x_real, c_trg)) for num, k in enumerate(x_fake_list): result_path = os.path.join(self.result_dir, '{}-images.jpg'.format((i)*9+num)) save_image(self.denorm(k.data.cpu()), result_path, nrow=1, padding=0) print('Saved real and fake images into {}...'.format(result_path))
'''
— You are receiving this because you commented. Reply to this email directly, view it on GitHub < https://github.com/yunjey/stargan/issues/108?email_source=notifications&email_token=AH2BJCFU2N77RDRQ4EF74D3QUHNIHA5CNFSM4JILK3VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEI2MDY#issuecomment-554804751 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AH2BJCDKFYWBERED4DEA7FDQUHNIHANCNFSM4JILK3VA
.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yunjey/stargan/issues/108?email_source=notifications&email_token=AHQYPMEWKM6UHWC5W2DVVZDQUIVNNA5CNFSM4JILK3VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEJJGUA#issuecomment-554865488, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHQYPMDHAGNTOBIOJYDOA6DQUIVNNANCNFSM4JILK3VA .
I have solved the problem.
https://github.com/wjun0830/stargan I have uploaded the code here. You will see the code in line 525 in solver2.py and will also need to include the header transforms.
I have solved the problem.
https://github.com/wjun0830/stargan I have uploaded the code here. You will see the code line 525 in solver2.py and will also need to include the header transforms.
thanks for your contribution. but my results are very bad. what are the results of you?
The result may depends on the pictures. When I tried another picture of old and bald man, the result was similar to your output.
Is it possible to test the data with pre-trained model?
I am curious if there is any way to test new images with the model I trained in the past such as training with only celebA but later testing with custom datasets.