IyatomiLab / LeafGAN

Other
71 stars 21 forks source link

Test script leafgan #3

Closed BartvanMarrewijk closed 2 years ago

BartvanMarrewijk commented 2 years ago

I have succesfully trained the leaf gan model on a custom dataset but an error arise when using the test.py for the leaf_gan model.

The first error is that the threshold option is not defined in test_options.py. This was easily solved by copying from train_options.py.

The second error is that the netLFLseg is not defined in leaf_gan_model.py. This is caused by the if statements at line 80, why is the LFLSeg module in this if statement?

`

if self.isTrain:

      self.netD_A = networks.define_D(opt.output_nc, opt.ndf, opt.netD,                                         opt.n_layers_D, opt.norm, opt.init_type, opt.init_gain, self.gpu_ids)

      self.netD_B = networks.define_D(opt.input_nc, opt.ndf, opt.netD,                                          opt.n_layers_D, opt.norm, opt.init_type, opt.init_gain, self.gpu_ids)

      self.segResNet = models.resnet101()

      num_ftrs = self.segResNet.fc.in_features

      self.segResNet.fc = nn.Linear(num_ftrs, 3) 

      self.segResNet.load_state_dict(torch.load(load_path), strict=True)
      self.segResNet.to(self.device)
      self.segResNet.eval()
      # self.segResNet = torch.nn.DataParallel(self.segResNet, self.gpu_ids)

      self.netLFLSeg = GradCAM(model=self.segResNet)
      ######################################################

Is is safe to change it to this:

if self.isTrain:

    self.netD_A = networks.define_D(opt.output_nc, opt.ndf, opt.netD,                                           opt.n_layers_D, opt.norm, opt.init_type, opt.init_gain, self.gpu_ids)

    self.netD_B = networks.define_D(opt.input_nc, opt.ndf, opt.netD,                                            opt.n_layers_D, opt.norm, opt.init_type, opt.init_gain, self.gpu_ids)

self.segResNet = models.resnet101()

num_ftrs = self.segResNet.fc.in_features

self.segResNet.fc = nn.Linear(num_ftrs, 3) 

self.segResNet.load_state_dict(torch.load(load_path), strict=True)
self.segResNet.to(self.device)
self.segResNet.eval()
# self.segResNet = torch.nn.DataParallel(self.segResNet, self.gpu_ids)

self.netLFLSeg = GradCAM(model=self.segResNet)
        ######################################################

`

huuquan1994 commented 2 years ago

Hi @studentWUR,

Testing the LeafGAN model doesn't require loading the LFLSeg module nor setting the threshold value. In the test_option.py, the isTrain flag is set to False. So, the error you got above seems not to happen when you test the model.

Could you show me the bash command when you test your model? Also, could you check your test_option.py again?

BartvanMarrewijk commented 2 years ago

Hi @huuquan1994 ,

Thank you for the quick reply. The isTrain is indeed set to false while running test.py. My test-options.py is exactly the same as on the git. Further, I did not make any large changes. See output ofr the terminal below


python test.py --dataroot ./datasets/dataset_standard/valid/ --name dataset_standard_leaf --model leaf_gan
----------------- Options ---------------
             aspect_ratio: 1.0                           
               batch_size: 1                             
          checkpoints_dir: ./checkpoints                 
                crop_size: 256                           
                 dataroot: ./datasets/dataset_standard/valid/   [default: ./datasets/dataset_standard/train/]
             dataset_mode: unaligned                     
                direction: AtoB                          
          display_winsize: 256                           
                    epoch: latest                        
                     eval: False                         
                  gpu_ids: 0                             
                init_gain: 0.02                          
                init_type: normal                        
                 input_nc: 3                             
                  isTrain: False                            [default: None]
                load_iter: 0                                [default: 0]
                load_size: 256                           
         max_dataset_size: inf                           
                    model: leaf_gan                         [default: test]
               n_layers_D: 3                             
                     name: dataset_standard_leaf            [default: experiment_name]
                      ndf: 64                            
                     netD: basic                         
                     netG: resnet_9blocks                
                      ngf: 64                            
               no_dropout: True                          
                  no_flip: False                         
                     norm: instance                      
                    ntest: inf                           
                 num_test: 50                            
              num_threads: 4                             
                output_nc: 3                             
                    phase: test                          
               preprocess: resize_and_crop               
              results_dir: ./results/                    
           serial_batches: False                         
                   suffix:                               
                threshold: 0.35                          
                  verbose: False                         
----------------- End -------------------
dataset [UnalignedDataset] was created
initialize network with normal
initialize network with normal
model [LeafGANModel] was created
loading the model from ./checkpoints/dataset_standard_leaf/latest_net_G_A.pth
loading the model from ./checkpoints/dataset_standard_leaf/latest_net_G_B.pth
---------- Networks initialized -------------
[Network G_A] Total number of parameters : 11.378 M
[Network G_B] Total number of parameters : 11.378 M
-----------------------------------------------
Traceback (most recent call last):
  File "test.py", line 60, in <module>
    model.test()           # run inference
  File "/home/ubuntu16/domain_adaptation/LeafGAN/models/base_model.py", line 105, in test
    self.forward()
  File "/home/ubuntu16/domain_adaptation/LeafGAN/models/leaf_gan_model.py", line 166, in forward
    self.background_real_A, self.foreground_real_A = self.get_masking(self.real_A, self.opt.threshold)
  File "/home/ubuntu16/domain_adaptation/LeafGAN/models/leaf_gan_model.py", line 120, in get_masking
    probs, idx = self.netLFLSeg.forward(tensor.to(torch.device('cuda:{}'.format(1))))
AttributeError: 'LeafGANModel' object has no attribute 'netLFLSeg'
huuquan1994 commented 2 years ago

Hi @studentWUR,

Thanks for your detailed log and sorry for the trouble. I found that the instruction I wrote was wrong. When testing the LeafGAN, we should load it with the CycleGAN model. (Since we don't need the LFLSeg module, and the generator architecture of the CycleGAN model is the same as LeafGAN).

At the moment, please modify your command to this (i.e., load the trained LeafGAN model under CycleGAN architecture)

python test.py --dataroot ./datasets/dataset_standard/valid/ --name dataset_standard_leaf --model cycle_gan

Anyway, I'll modify the code of the leaf_gan_model.py so that we can run the test with the isTrain flag off. Please wait a bit.

huuquan1994 commented 2 years ago

Hi @studentWUR

I've updated the code of the leaf_gan_model.py to run on testing. Now the following two commands are equivalent. You can either run one of the followings

python test.py --dataroot ./datasets/dataset_standard/valid/ --name dataset_standard_leaf --model leaf_gan
# or
python test.py --dataroot ./datasets/dataset_standard/valid/ --name dataset_standard_leaf --model cycle_gan

If you find any problems, please feel free to ask me.

BartvanMarrewijk commented 2 years ago

Hi @huuquan1994,

Thanks a lot it works perfectly now :)

soundaryabc123 commented 2 years ago

Can you please share the complete source code. When I tried to execute what you have posted 1 of the package is missing. I hope you will share It will help for my academics. Thank you Mail Id; soundaryagowda166@gmail.com

huuquan1994 commented 2 years ago

@soundaryabc123 Hi there, the source code I have pushed is the full source code. You should be able to run it if you've installed all the required packages.

Could you send me your error logs?

soundaryabc123 commented 2 years ago

Okay, Thanks a lot for your help What are all the necessary packages I have to install?

On Fri, Dec 10, 2021, 9:14 AM Huu Quan, CAP @.***> wrote:

@soundaryabc123 https://github.com/soundaryabc123 Hi there, the source code I have pushed is the full source code. You should be able to run it if you've installed all the required packages.

Could you send me your error logs?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/IyatomiLab/LeafGAN/issues/3#issuecomment-990584100, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVPMJW3YBOBXFDP6BS6KZGDUQFZTTANCNFSM5AK2TMUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

soundaryabc123 commented 2 years ago

It's showing that 1 of the package is missing

On Fri, Dec 10, 2021, 10:02 AM SOUNDARYA B C @.***> wrote:

Okay, Thanks a lot for your help What are all the necessary packages I have to install?

On Fri, Dec 10, 2021, 9:14 AM Huu Quan, CAP @.***> wrote:

@soundaryabc123 https://github.com/soundaryabc123 Hi there, the source code I have pushed is the full source code. You should be able to run it if you've installed all the required packages.

Could you send me your error logs?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/IyatomiLab/LeafGAN/issues/3#issuecomment-990584100, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVPMJW3YBOBXFDP6BS6KZGDUQFZTTANCNFSM5AK2TMUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

huuquan1994 commented 2 years ago

@soundaryabc123 All required packages are in requirements.txt

You can install all of them via this command pip install -r requirements.txt

soundaryabc123 commented 2 years ago

Thanks, I'll check it out. But the thing am not getting which file to execute first since there are multiple files over there. Could you please help me with that? I'd u don't mind Can I get ur whatsapp number

On Fri, Dec 10, 2021, 7:34 PM Huu Quan, CAP @.***> wrote:

@soundaryabc123 https://github.com/soundaryabc123 All required packages are in requirements.txt https://github.com/IyatomiLab/LeafGAN/blob/master/requirements.txt

You can install all of them via this command pip install -r requirements.txt

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/IyatomiLab/LeafGAN/issues/3#issuecomment-991000004, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVPMJW4QSB3TAHWRMOSXEYDUQICHNANCNFSM5AK2TMUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

huuquan1994 commented 2 years ago

@soundaryabc123 What do you mean by "which file to execute first"? My code is based on the CycleGAN repository. If you're not sure how to run my code, it's better to take a look at the CycleGAN's notebook. After that, you should be able to run my code.

Next time, if you encounter any errors, make sure to post the error logs.

soundaryabc123 commented 2 years ago

Got it, thanks!

On Sat, Dec 11, 2021, 7:11 PM Huu Quan, CAP @.***> wrote:

@soundaryabc123 https://github.com/soundaryabc123 What do you mean by "which file to execute first"? My code is based on the CycleGAN https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix repository. If you're not sure how to run my code, it's better to take a look at the CycleGAN's notebook https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/blob/master/CycleGAN.ipynb . After that, you should be able to run my code.

Next time, if you encounter any errors, make sure to post the error logs.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/IyatomiLab/LeafGAN/issues/3#issuecomment-991648300, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVPMJW3GP3MV5T53OHEDE4LUQNIJTANCNFSM5AK2TMUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

soundaryabc123 commented 2 years ago

Hello, Could you please share the datasets. And send the format of execution. It will be great help for me. Looking forward for your reply.

On Fri, Dec 10, 2021, 9:36 PM SOUNDARYA B C @.***> wrote:

Thanks, I'll check it out. But the thing am not getting which file to execute first since there are multiple files over there. Could you please help me with that? I'd u don't mind Can I get ur whatsapp number

On Fri, Dec 10, 2021, 7:34 PM Huu Quan, CAP @.***> wrote:

@soundaryabc123 https://github.com/soundaryabc123 All required packages are in requirements.txt https://github.com/IyatomiLab/LeafGAN/blob/master/requirements.txt

You can install all of them via this command pip install -r requirements.txt

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/IyatomiLab/LeafGAN/issues/3#issuecomment-991000004, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVPMJW4QSB3TAHWRMOSXEYDUQICHNANCNFSM5AK2TMUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

soundaryabc123 commented 2 years ago

Since I'm beginner I'm not getting how to run it. Can we have 1 meeting If u are okay with it. Or can u please share Colab link.

On Mon, Jan 3, 2022, 4:31 PM SOUNDARYA B C @.***> wrote:

Hello, Could you please share the datasets. And send the format of execution. It will be great help for me. Looking forward for your reply.

On Fri, Dec 10, 2021, 9:36 PM SOUNDARYA B C @.***> wrote:

Thanks, I'll check it out. But the thing am not getting which file to execute first since there are multiple files over there. Could you please help me with that? I'd u don't mind Can I get ur whatsapp number

On Fri, Dec 10, 2021, 7:34 PM Huu Quan, CAP @.***> wrote:

@soundaryabc123 https://github.com/soundaryabc123 All required packages are in requirements.txt https://github.com/IyatomiLab/LeafGAN/blob/master/requirements.txt

You can install all of them via this command pip install -r requirements.txt

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/IyatomiLab/LeafGAN/issues/3#issuecomment-991000004, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVPMJW4QSB3TAHWRMOSXEYDUQICHNANCNFSM5AK2TMUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

huuquan1994 commented 2 years ago

Hi @soundaryabc123,

Sorry for the late reply! For the dataset, we are not allowed to share it because it belongs to a national project.

For executing the code, have you tried to run the Original CycleGAN code? I recommend you to try it first then come back hereafter. Sorry again but I can't do the meeting.

For the Colab link, I'll make it in my spare time (hopefully soon).

Anyway, if you encounter any problems, please raise a new issue.

soundaryabc123 commented 2 years ago

No worries, thanks for the update! Can I use my own datasets. Please share the colab link. I will train with my own datasets.

On Sun, Jan 9, 2022, 6:54 AM Huu Quan, CAP @.***> wrote:

Hi @soundaryabc123 https://github.com/soundaryabc123,

Sorry for the late reply! For the dataset, we are not allowed to share it because it belongs to a national project.

For executing the code, have you tried to run the Original CycleGAN code? I recommend you to try it first then come back hereafter. Sorry again but I can't do the meeting.

For the Colab link, I'll make it in my spare time (hopefully soon).

Anyway, if you encounter any problems, please raise a new issue.

— Reply to this email directly, view it on GitHub https://github.com/IyatomiLab/LeafGAN/issues/3#issuecomment-1008207030, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVPMJWYY7ZYSDRL5D6NGGATUVDPVXANCNFSM5AK2TMUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

soundaryabc123 commented 2 years ago

The thing is while running the code its showing error. So I am asking if u share the successful Cola link I will use my own data. Kindly share the complete Colab link it will help me a lot.

On Sun, Jan 9, 2022, 12:44 PM SOUNDARYA B C @.***> wrote:

No worries, thanks for the update! Can I use my own datasets. Please share the colab link. I will train with my own datasets.

On Sun, Jan 9, 2022, 6:54 AM Huu Quan, CAP @.***> wrote:

Hi @soundaryabc123 https://github.com/soundaryabc123,

Sorry for the late reply! For the dataset, we are not allowed to share it because it belongs to a national project.

For executing the code, have you tried to run the Original CycleGAN code? I recommend you to try it first then come back hereafter. Sorry again but I can't do the meeting.

For the Colab link, I'll make it in my spare time (hopefully soon).

Anyway, if you encounter any problems, please raise a new issue.

— Reply to this email directly, view it on GitHub https://github.com/IyatomiLab/LeafGAN/issues/3#issuecomment-1008207030, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVPMJWYY7ZYSDRL5D6NGGATUVDPVXANCNFSM5AK2TMUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

huuquan1994 commented 2 years ago

@soundaryabc123 Of course, you can train with your own datasets. I'll prepare the Colab or Notebook when I have time.

soundaryabc123 commented 2 years ago

Awesome, thanks!

On Tue, Jan 11, 2022, 6:23 AM Huu Quan, CAP @.***> wrote:

@soundaryabc123 https://github.com/soundaryabc123 Of course, you can train with your own datasets. I'll prepare the Colab or Notebook when I have time.

— Reply to this email directly, view it on GitHub https://github.com/IyatomiLab/LeafGAN/issues/3#issuecomment-1009494476, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVPMJW53LPMAQWV2AZFYRILUVN5QTANCNFSM5AK2TMUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

soundaryabc123 commented 2 years ago

Can u please share by this week. Since I'm a student I have to update to my guide.

On Tue, Jan 11, 2022, 7:57 AM SOUNDARYA B C @.***> wrote:

Awesome, thanks!

On Tue, Jan 11, 2022, 6:23 AM Huu Quan, CAP @.***> wrote:

@soundaryabc123 https://github.com/soundaryabc123 Of course, you can train with your own datasets. I'll prepare the Colab or Notebook when I have time.

— Reply to this email directly, view it on GitHub https://github.com/IyatomiLab/LeafGAN/issues/3#issuecomment-1009494476, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVPMJW53LPMAQWV2AZFYRILUVN5QTANCNFSM5AK2TMUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>