I'll be in the chat during the premiere to chat or if anyone has questions regarding the implementation! I've uploaded all the code to Github now with pretrained weights if you wanna evaluate the results: bit.ly/2OdZX75. If you have recommendations on GANs you think would make this into an even better resource for people wanting to learna bout GANs let me know in the comments below and I'll try to do it! Also a friendly remainder to please like the video if you want to see more of these from scratch videos :) I learned a lot and was inspired to make these GAN videos by the GAN specialization on coursera which I recommend. Below you'll find both affiliate and non-affiliate links, the pricing for you is the same but a small commission goes back to the channel if you buy it through the affiliate link. affiliate: bit.ly/2OECviQ non-affiliate: bit.ly/3bvr9qy Timestamps: 0:00 - Introduction 0:32 - CycleGAN summary 7:45 - Results paper vs our 8:49 - Outline for implementation 9:25 - Discriminator 17:00 - Generator 28:15 - Dataset 38:00 - Train function 57:55 - Ending
Hey bro.. just wondering. Whenever we start defining complex network (just now i inplemented ResNext), we start with the naive one and then we can optimize further later on. Is it alright it to do it? As for data Science concern, do they more focus on code optimization?
Aladdin Persson ! Can you make a video about StarGAN on scratch regarding multiple-domain style transfer? (a improved version of this). I highly appreciate it!
It seems that you are urnning this implementation locally on your own PC with a reasonable GPU? Do you have a clip about how to setup your software environment to be able to run your code? I hope I can re-produce your implementation first, then I may be able to modify it a bit to do something a bit (or quite) different. Thanks a lot
Amazing Job! I am learning a lot from your videos and using them on a daily basis in my Research! Have a bunch of papers in submission will reach out to you and share incase they get accepted!
Coding is a lot harder than he makes it look :) I think he implemented all of these before and is just rewriting them while looking at his previous implementation. Don't be discouraged.
Ngl the official implementation of CycleGAN throws me an error everytime. I saw this implementation. Went through the complete video. Replicated this implementation and boi it works so well. Thanks a lot. Great Channel definitely deserves a sub and a like
Dear Mr Aladdin, Thank you so much for the video and our work is amazing. Please pardon me asking but I could not find the code to test the trained model. After training the CycleGAN model, how do we perform a real life test on another set of images. Hope to hear from you and please continue your work. Thank you
I was planning to learn cycleGANs for my thesis and your code literally saved my ass. Until I saw this video I honeslty had a really hard time understanding the codes. Thank you soo much for this video
A_img = self.A_images[index % self.A_len if self.length_dataset==self.B_len else index] B_img = self.B_images[index % self.B_len if self.length_dataset==self.A_len else index] i belive this would fix the issue you mentioned during the implementation of the dataset class
Hi Aladdin, I found out that in the same loop, if the image is from the end of that loop, it will become better. But why? shouldn't it become better because of the end of epoch.
Great work explaining the paper and then implementing it. I have one request. As you have gone through the YOLO implementation already. Can you kindly explain DeepSORT and its implementation with YOlO?
Hi Aladdin, thank you for this tutorial! I have a question on 5:30, it is written Identity Loss is "H->Z", but what I see in the implementation is "H->H". Am I missing something?
H->Z here is just the Generator that's supposed to convert horse to zebra, so it's an identity loss where if we already have the convert image then it shouldn't do anything to the original image. Perhaps it's a confusing detail but it seems like you get the idea
Did you succeed eventually? In the paper, the writers say they used 100 epochs under constant learning rate and then linearly decayed it to 0 in the next 100 epochs.
Excuse me, I have the same question with you. I directly download the code from github, and when I run it , horse_0 and zebra_0 are black pixels, the same to horse_200 and zebra_200. But in the video, I see these pictures are full of color and content since the begining. Whether do I ignore or forget something important? In pycharm it runs showing 18%|█▊ | 239/1334 [11:53
It seems that you are urnning this implementation locally on your own PC with a reasonable GPU? Do you have a clip about how to setup your software environment to be able to run your code? I hope I can re-produce your implementation first, then I may be able to modify it a bit to do something a bit (or quite) different. Thanks a lot
Thanks for this video. I really had hard time reproducing CycleGAN paper and came here. There are several questions though.. 1. For the fourth convolution layer in the discriminator(256->512 channels), I thought this was also stride=2 in paper. 2. For the residual blocks, isn't the output should be ReLU(x+y)? I wanted to know if it meant something or was a mistake. 3. In the training, you didn't implement learning rate decay nor image buffer. Did your model performed well without these? Thank you. I just spent a lot of time struggling with this and I didn't want to miss smallest reasons to my failure
Hi there, just saw your video as well as the code from your github. I am new to coding so I am bit confused on the configuration part. For the train and val directory is it the pathway of the image from the dataset? As the TRAIN_DIR and VAL_DIR is used later in the training module of the python
This was great thanks, I leanrn't a lot. I was thinking that at the end you could have made coded an eval.py that could evaluate the model on the trained weights instead of modifying code.
Hi, I have followed your implementation of CycleGAN just with no transformation other than resizing. I trained for 190 epochs and still couldn't get good results, what can I try to do to make the model perform better, do you think horizontal flip makes a significant difference?
Hi, just started the training. Saw that in the paper the writers say that they trained the network for 200 epochs (I think), with the first epochs with the constant learning rate and then another with linear decay. Did it work for you? What did you do eventually?
@@DuduHarar1 I didn't train it again since the time I can use GPU is limited. Maybe, this is a good point, I didn't read the paper, can you try using the same training approach like mentioned in the paper and check if you get good results if you can?
@@eltonlobo8697, ok so the network has been trained for two days, it didn't achieve results as in the paper nor as Alladin's, far from it. Maybe something wasn't right, maybe will try again next week..
Can someone please help me on how to add summary() to the code? at 16:17, I tried to add summary(model, (5,3,256,256)) but got the error "Only 2D, 3D, 4D, 5D padding with non-constant padding are supported for now", then I tried summary(model, (3,256,256)) and got "Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same". I really want to figure out how a (5,3,256,256) matrix can be transformed into (5,1,30,30). Thank you in advance ^^
Hello Aladdin! A quick question. While computing the loss you compare the output of the discrimination with a matrix of 1's and 0's. Does the PatchGan output a Grid where each cell has 1 and 0?
Hello Guys, how can I train this without cuda and autocast? because there is only cpu in my computer. sorry I'm new to this CycleGan so really appreciate to get your help.
I believe you can replicate this code and it will still run. He has set up the config.DEVICE variable taking both conditions (if cuda is present or not) into account. I guess you'll just get a warning on the autocast line , won't get an error
nếu laptop của bạn ko có GPU. mình nói thiệt là bạn nên từ bỏ việc train trên lap nha. kể cả laptop có GPU thì cũng ko nên. model này thực sự nặng. mình lo cho cái laptop của bạn hơn. Bạn thử qua sử dụng google Colab nha.
I wrote the code like you exactly but when i run it. I got an error ( a GPU error ) is CoLab useful for training a cycleGAN ? Could you run your code on colab, please? If anyone train his own CycleGAN on colab and it's running please leave a comment?
I ended up figuring this out, you should just be able to use the generation method used in the train function, but make sure you unsqueeze your tensors so that the tensor has a proper padding size
Hi :) thank you for the Tutorial! Can I somehow train my own models without using Cuda? I only habe a MacBook Pro with a 2,8 GHz Quad-Core Intel Core i7 processor.
Nice and simple implementation. Guys, the least we can do is subscribe to this channel, please subscribe. One question I have with the implementation is that the residual block contains two Conv blocks (with ReLU and without ReLU). If you use this ResidualBlock in the generator class using the for loop, won't it generate 18 Conv blocks instead of 9? Because it will generate two Conv blocks in each loop.
3 года назад
Thanks for a great video. I was just wondering if I'm using py files, I guess I can change loading images from PIL to cv2, right? Because PIL is not supporting the py format. Or at least that is my guess why I'm getting this error: PIL.UnidentifiedImageError: cannot identify image file '/home/anya/Documents/ct/data/train/quarter_dose/1933.npy'
I do not think your dataset is correct. If getitem asks for index 6 as an example it will give the 6th horse picture AND the 6th zebra picture. In other words it compares the same horse with the same zebra every time. Surely you want a different match every time? You could shuffle the lists every epoch. I do not think the shuffle = True in the Dataloader has the desired effect as it just shuffles the order that indexes are requested. It may not matter too much if you have a largish batch size as the individual horse/zebra are not compared but if you had a batch size of one as in the paper you certainly would have a problem.
However, in the cycleGAN paper, the author set batch_size to 1. So we must use a different way to handle the shuffle instead of the dataloader built-in shuffle=True. Just like what you said, it always compared two same pictures.
Excuse me, why the images I generated are whole black pixels in each epoch? Whether something need to change since I just simply follow the video's code? I have been trapped in this question for 2 days but no way to solve. I am so upset.
Sorry, my computer's gpu is not capable to carry this task, so the generated images are whole black. When I train it on our lab's platform, it works well!
I am getting following errors when I load a model with weights given in the github: raise RuntimeError('Error(s) in loading state_dict for {}: \t{}'.format( RuntimeError: Error(s) in loading state_dict for Generator: Missing key(s) in state_dict: "initial.0.weight", "initial.0.bias". Unexpected key(s) in state_dict: "initial.weight", "initial.bias". I am using python3.Can someone tell me how to solve this?Thankyou
In the file config.py, set the 'LOAD_MODEL = False; the error is telling you that the pretrained weights are not in the file. That is because you have run the model yet. This error will go away after the values has been saved.
This is definitely a stupid question, but I am gonna ask anyway. In train.py , there is a command "torch.cuda.amp.autocast() " I do not have a GPU, but will that command still run ? Thanks.
Yes, the program will still run it will just be run on the CPU instead and take 50x longer. In the file 'config.py' Aladdin even has a line of code on line 8, stating the DEVICE CPU or GPU it should run on: DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
I'll be in the chat during the premiere to chat or if anyone has questions regarding the implementation! I've uploaded all the code to Github now with pretrained weights if you wanna evaluate the results: bit.ly/2OdZX75. If you have recommendations on GANs you think would make this into an even better resource for people wanting to learna bout GANs let me know in the comments below and I'll try to do it! Also a friendly remainder to please like the video if you want to see more of these from scratch videos :)
I learned a lot and was inspired to make these GAN videos by the GAN specialization on coursera which I recommend. Below you'll find both affiliate and non-affiliate links, the pricing for you is the same but a small commission goes back to the channel if you buy it through the affiliate link.
affiliate: bit.ly/2OECviQ
non-affiliate: bit.ly/3bvr9qy
Timestamps:
0:00 - Introduction
0:32 - CycleGAN summary
7:45 - Results paper vs our
8:49 - Outline for implementation
9:25 - Discriminator
17:00 - Generator
28:15 - Dataset
38:00 - Train function
57:55 - Ending
Hey bro.. just wondering. Whenever we start defining complex network (just now i inplemented ResNext), we start with the naive one and then we can optimize further later on. Is it alright it to do it? As for data Science concern, do they more focus on code optimization?
Aladdin Persson ! Can you make a video about StarGAN on scratch regarding multiple-domain style transfer? (a improved version of this). I highly appreciate it!
It seems that you are urnning this implementation locally on your own PC with a reasonable GPU? Do you have a clip about how to setup your software environment to be able to run your code? I hope I can re-produce your implementation first, then I may be able to modify it a bit to do something a bit (or quite) different. Thanks a lot
One after another this playlist keeps getting better! Kudos this is hands down one of the best playlist on GAN's
Appreciate the kind words Divy, will work hard to always improve this playlist :)
This guy is the best. Giving out gold content out for free
Amazing Job! I am learning a lot from your videos and using them on a daily basis in my Research! Have a bunch of papers in submission will reach out to you and share incase they get accepted!
I am curious about your papers! what happened next?
Amazing!!! I am a fresh learner of coding actually... I wish I can code freely just like you do
Coding is a lot harder than he makes it look :) I think he implemented all of these before and is just rewriting them while looking at his previous implementation. Don't be discouraged.
You don't learn coding my friend. First learn the concepts and learn how to write it programmatically and learn typing.
Thanks! I have been watching your videos for a while and you have a great content! You deserve a lot more subs and views. Keep it up!
I used to same code and same dataset but when I try to see the saved images, I can just see a whole black image. Can anyone tell me what am I missing?
I have the same question with you. Have you solved it? May you teach me how to fix it? Thank you very much!
Maybe your computer is not capable of dealing with this task. I have met the same problem, but when I try on our lab's platform, it works well.
Ngl the official implementation of CycleGAN throws me an error everytime. I saw this implementation. Went through the complete video. Replicated this implementation and boi it works so well. Thanks a lot. Great Channel definitely deserves a sub and a like
Dear Mr Aladdin,
Thank you so much for the video and our work is amazing. Please pardon me asking but I could not find the code to test the trained model. After training the CycleGAN model, how do we perform a real life test on another set of images. Hope to hear from you and please continue your work.
Thank you
Howdy! Your videos are so awesome, which help me a lot and from which I've learned a lot. Thanks a lot.
Great Content!! Thank you so much!
This is really helpful, thanks
dude you are so awesome. thanx for the great content!
Great work, thank you so much
I was planning to learn cycleGANs for my thesis and your code literally saved my ass. Until I saw this video I honeslty had a really hard time understanding the codes. Thank you soo much for this video
Awesome job!
27:10 can someone explain me why he didnt use sequential and instead chose to use module list when all that does is the same thing in the end?
A_img = self.A_images[index % self.A_len if self.length_dataset==self.B_len else index]
B_img = self.B_images[index % self.B_len if self.length_dataset==self.A_len else index]
i belive this would fix the issue you mentioned during the implementation of the dataset class
Hi Aladdin, I found out that in the same loop, if the image is from the end of that loop, it will become better. But why? shouldn't it become better because of the end of epoch.
Thanks so much for your video, please more from scratch video!
RUclips caption went mad at 17:05.
I like your video very much! I like the way you teach. I can lean a lot from your videos. Hope you could make videos about Faster RCNN! Best wishes!
Great vid. Q: why have a Sequential inside the Block, instead of the three layers directly?
Great work, thank you so much! This is really helpful! How to save the trained model in cyclegan?
Great work explaining the paper and then implementing it. I have one request. As you have gone through the YOLO implementation already. Can you kindly explain DeepSORT and its implementation with YOlO?
Great, thx a lot :)
sir,can you explain about the maths models and formulae that has been used in cyclegan and also how it is implemented in codes.
Hi Aladdin, thank you for this tutorial!
I have a question on 5:30, it is written Identity Loss is "H->Z", but what I see in the implementation is "H->H". Am I missing something?
H->Z here is just the Generator that's supposed to convert horse to zebra, so it's an identity loss where if we already have the convert image then it shouldn't do anything to the original image. Perhaps it's a confusing detail but it seems like you get the idea
@@AladdinPersson oh, now I see, thank you!
At 1:24 two generators F and G right??
That is correct
How long time (how many epochs) it takes to train the cycleGAN? Is it ok if I have a lot of black pixels at the beginning of training?
Did you succeed eventually? In the paper, the writers say they used 100 epochs under constant learning rate and then linearly decayed it to 0 in the next 100 epochs.
Excuse me, I have the same question with you. I directly download the code from github, and when I run it , horse_0 and zebra_0 are black pixels, the same to horse_200 and zebra_200. But in the video, I see these pictures are full of color and content since the begining. Whether do I ignore or forget something important? In pycharm it runs showing 18%|█▊ | 239/1334 [11:53
Where is the dataset?
It seems that you are urnning this implementation locally on your own PC with a reasonable GPU? Do you have a clip about how to setup your software environment to be able to run your code? I hope I can re-produce your implementation first, then I may be able to modify it a bit to do something a bit (or quite) different. Thanks a lot
Thanks for this video. I really had hard time reproducing CycleGAN paper and came here. There are several questions though..
1. For the fourth convolution layer in the discriminator(256->512 channels), I thought this was also stride=2 in paper.
2. For the residual blocks, isn't the output should be ReLU(x+y)? I wanted to know if it meant something or was a mistake.
3. In the training, you didn't implement learning rate decay nor image buffer. Did your model performed well without these?
Thank you. I just spent a lot of time struggling with this and I didn't want to miss smallest reasons to my failure
Did u make all these changes and try training the model? Did u get better results?
Hi there, just saw your video as well as the code from your github. I am new to coding so I am bit confused on the configuration part. For the train and val directory is it the pathway of the image from the dataset? As the TRAIN_DIR and VAL_DIR is used later in the training module of the python
at 55.56, after getting the result, how to find those picture in dataset, like from which picture it turned into horse to zebra and zebra to horse?
This was great thanks, I leanrn't a lot. I was thinking that at the end you could have made coded an eval.py that could evaluate the model on the trained weights instead of modifying code.
Hi,
I have followed your implementation of CycleGAN just with no transformation other than resizing. I trained for 190 epochs and still couldn't get good results, what can I try to do to make the model perform better, do you think horizontal flip makes a significant difference?
Hi, just started the training. Saw that in the paper the writers say that they trained the network for 200 epochs (I think), with the first epochs with the constant learning rate and then another with linear decay.
Did it work for you? What did you do eventually?
@@DuduHarar1 I didn't train it again since the time I can use GPU is limited. Maybe, this is a good point, I didn't read the paper, can you try using the same training approach like mentioned in the paper and check if you get good results if you can?
@@eltonlobo8697 yes sure, started this morning, hopefully my pc won’t die and finish this evening then I will be able to update about performance.
@@eltonlobo8697, ok so the network has been trained for two days, it didn't achieve results as in the paper nor as Alladin's, far from it. Maybe something wasn't right, maybe will try again next week..
@@DuduHarar1 What changes are you going to do when you train again?
Can someone please help me on how to add summary() to the code? at 16:17, I tried to add summary(model, (5,3,256,256)) but got the error "Only 2D, 3D, 4D, 5D padding with non-constant padding are supported for now", then I tried summary(model, (3,256,256)) and got "Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same". I really want to figure out how a (5,3,256,256) matrix can be transformed into (5,1,30,30). Thank you in advance ^^
problem solved, I used torchinfo instead of torchsummary
Hello, can you do a video about StyleGan!!
Why do you use nn.ModuleList in Generator class instead of nn.Sequential?
Hello Aladdin! A quick question. While computing the loss you compare the output of the discrimination with a matrix of 1's and 0's. Does the PatchGan output a Grid where each cell has 1 and 0?
the patchGAN model has a sigmoid activation at the end which make the output in the range (0,1). Not just 0s or 1s.
Hi, how to train it further for domain adaptation...since I can not change the cityscapes to dataset with binary masks
expecting for that
From where can I get dataset?
What is the difference between using nn.ModuleList(*[...]) and doing this: nn.Sequential([ .... ])?
Hello Guys, how can I train this without cuda and autocast? because there is only cpu in my computer. sorry I'm new to this CycleGan so really appreciate to get your help.
I believe you can replicate this code and it will still run. He has set up the config.DEVICE variable taking both conditions (if cuda is present or not) into account.
I guess you'll just get a warning on the autocast line , won't get an error
@@atharvachoudhary6974 yes thank you for your help, I did resolve the problem by just removing the autocast!
@@datdat7919 hi how did you do that? I have the same problem that Cuda is not working on my laptop :)
nếu laptop của bạn ko có GPU. mình nói thiệt là bạn nên từ bỏ việc train trên lap nha. kể cả laptop có GPU thì cũng ko nên. model này thực sự nặng. mình lo cho cái laptop của bạn hơn. Bạn thử qua sử dụng google Colab nha.
@@boquangdong please sir can u help me?
Hi I tried your code by my dataset, but the generator seems like only can generated the same image as input. what should I do? thanks
I wrote the code like you exactly but when i run it. I got an error ( a GPU error ) is CoLab useful for training a cycleGAN ?
Could you run your code on colab, please?
If anyone train his own CycleGAN on colab and it's running please leave a comment?
have you got for colab?
Hello Sir I have question about cycleGAN that how we can fined tuned the cycleGAN for own data.
if you could teach Bayesian neural network, it will be greatly appreciated!
so like... how would you generate an image if you were to import this as a library in a script and send an image through a function
I ended up figuring this out, you should just be able to use the generation method used in the train function, but make sure you unsqueeze your tensors so that the tensor has a proper padding size
Hi :) thank you for the Tutorial! Can I somehow train my own models without using Cuda? I only habe a MacBook Pro with a 2,8 GHz Quad-Core Intel Core i7 processor.
You can train it on google colab
Nice and simple implementation. Guys, the least we can do is subscribe to this channel, please subscribe. One question I have with the implementation is that the residual block contains two Conv blocks (with ReLU and without ReLU). If you use this ResidualBlock in the generator class using the for loop, won't it generate 18 Conv blocks instead of 9? Because it will generate two Conv blocks in each loop.
Thanks for a great video. I was just wondering if I'm using py files, I guess I can change loading images from PIL to cv2, right? Because PIL is not supporting the py format. Or at least that is my guess why I'm getting this error: PIL.UnidentifiedImageError: cannot identify image file '/home/anya/Documents/ct/data/train/quarter_dose/1933.npy'
I do not think your dataset is correct. If getitem asks for index 6 as an example it will give the 6th horse picture AND the 6th zebra picture. In other words it compares the same horse with the same zebra every time. Surely you want a different match every time?
You could shuffle the lists every epoch. I do not think the shuffle = True in the Dataloader has the desired effect as it just shuffles the order that indexes are requested.
It may not matter too much if you have a largish batch size as the individual horse/zebra are not compared but if you had a batch size of one as in the paper you certainly would have a problem.
However, in the cycleGAN paper, the author set batch_size to 1. So we must use a different way to handle the shuffle instead of the dataloader built-in shuffle=True. Just like what you said, it always compared two same pictures.
what is padding mode ?
did you figure it out? :))
Excuse me, why the images I generated are whole black pixels in each epoch? Whether something need to change since I just simply follow the video's code? I have been trapped in this question for 2 days but no way to solve. I am so upset.
Sorry, my computer's gpu is not capable to carry this task, so the generated images are whole black. When I train it on our lab's platform, it works well!
I am getting following errors when I load a model with weights given in the github:
raise RuntimeError('Error(s) in loading state_dict for {}:
\t{}'.format(
RuntimeError: Error(s) in loading state_dict for Generator:
Missing key(s) in state_dict: "initial.0.weight", "initial.0.bias".
Unexpected key(s) in state_dict: "initial.weight", "initial.bias".
I am using python3.Can someone tell me how to solve this?Thankyou
In the file config.py, set the 'LOAD_MODEL = False; the error is telling you that the pretrained weights are not in the file. That is because you have run the model yet. This error will go away after the values has been saved.
Why not random sample a horse and a zebra instead of wrapping on dataset around itself?
This is definitely a stupid question, but I am gonna ask anyway.
In train.py , there is a command "torch.cuda.amp.autocast() "
I do not have a GPU, but will that command still run ?
Thanks.
Yes, the program will still run it will just be run on the CPU instead and take 50x longer. In the file 'config.py' Aladdin even has a line of code on line 8, stating the DEVICE CPU or GPU it should run on: DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
Because I doesn't have much amount of data.
I was following the video fully focused and eating some snacks until I saw "disc_h(fake_hoes)" @44:35 second, I choked on my chips