HenriquesLab / ZeroCostDL4Mic

ZeroCostDL4Mic: A Google Colab based no-cost toolbox to explore Deep-Learning in Microscopy
MIT License
557 stars 129 forks source link

Error: pix2pix Section 5.2 Run Quality Control #297

Closed LuciaSchmidt29 closed 9 months ago

LuciaSchmidt29 commented 1 year ago

Hello!

I am currently working on an Image-to-Image transformation task, where I am trying to generate H&E images from IHC ones. The training step was successfully completed but I am getting some errors in the Quality Control step that I do not understand and I would appreciate some help.

This is the error I am getting:

[fold_A] =  /content/pytorch-CycleGAN-and-pix2pix/my_model_images/QC/A
[fold_B] =  /content/pytorch-CycleGAN-and-pix2pix/my_model_images/QC/B
[fold_AB] =  /content/pytorch-CycleGAN-and-pix2pix/my_model_images/QC/AB
[num_imgs] =  1000000
[use_AB] =  False
[no_multiprocessing] =  False
split = test, use 6/6 images
split = test, number of images = 6
The checkpoint currently analysed is =5
----------------- Options ---------------
             aspect_ratio: 1.0                           
               batch_size: 1                             
          checkpoints_dir: /content/gdrive/MyDrive/Colab Notebooks/TFM/pix2pix  [default: ./checkpoints]
                crop_size: 1024                             [default: 256]
                 dataroot: /content/pytorch-CycleGAN-and-pix2pix/my_model_images/QC/AB  [default: None]
             dataset_mode: aligned                       
                direction: AtoB                          
          display_winsize: 256                           
                    epoch: 5                                [default: 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: 1024                             [default: 256]
         max_dataset_size: inf                           
                    model: pix2pix                          [default: test]
               n_layers_D: 3                             
                     name: my_model                         [default: experiment_name]
                      ndf: 64                            
                     netD: basic                         
                     netG: unet_256                      
                      ngf: 64                            
               no_dropout: True                             [default: False]
                  no_flip: False                         
                     norm: batch                         
                 num_test: 6                                [default: 50]
              num_threads: 4                             
                output_nc: 3                             
                    phase: test                          
               preprocess: scale_width                      [default: resize_and_crop]
              results_dir: /content/gdrive/MyDrive/Colab Notebooks/TFM/pix2pix/my_model/Quality Control/5   [default: ./results/]
           serial_batches: False                         
                   suffix:                               
                use_wandb: False                         
                  verbose: False                         
       wandb_project_name: CycleGAN-and-pix2pix          
----------------- End -------------------
dataset [AlignedDataset] was created
initialize network with normal
model [Pix2PixModel] was created
loading the model from /content/gdrive/MyDrive/Colab Notebooks/TFM/pix2pix/my_model/5_net_G.pth
---------- Networks initialized -------------
[Network G] Total number of parameters : 54.414 M
-----------------------------------------------
creating web directory /content/gdrive/MyDrive/Colab Notebooks/TFM/pix2pix/my_model/Quality Control/5/my_model/test_5
processing (0000)-th image... ['/content/pytorch-CycleGAN-and-pix2pix/my_model_images/QC/AB/test/image064.png']
processing (0005)-th image... ['/content/pytorch-CycleGAN-and-pix2pix/my_model_images/QC/AB/test/image069.png']
Running QC on: image064.png
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-13-1476b1cdf1a3>](https://localhost:8080/#) in <cell line: 33>()
     70     if number_channels == "3":
     71 
---> 72         Average_SSIM_checkpoint, Average_lpips_checkpoint = QC_RGB(Source_QC_folder, QC_prediction_results)
     73 
     74         Average_ssim_score_list.append(Average_SSIM_checkpoint)

3 frames
[<ipython-input-3-38de77521a19>](https://localhost:8080/#) in QC_RGB(Source_QC_folder, QC_folder)
    283                 # -------------------------------- Calculate the metric maps and save them --------------------------------
    284                 # Calculate the SSIM maps
--> 285                 index_SSIM_GTvsPrediction, img_SSIM_GTvsPrediction = ssim(test_GT, test_prediction_matched)
    286                 index_SSIM_GTvsSource, img_SSIM_GTvsSource = ssim(test_GT, test_source_matched)
    287                 ssim_score_list.append(index_SSIM_GTvsPrediction)

[<ipython-input-3-38de77521a19>](https://localhost:8080/#) in ssim(img1, img2)
    123     return sum(lst) / len(lst)
    124 def ssim(img1, img2):
--> 125     return structural_similarity(img1,img2,data_range=1.,full=True, gaussian_weights=True, use_sample_covariance=False, sigma=1.5)
    126 
    127 

[/usr/local/lib/python3.10/dist-packages/skimage/_shared/utils.py](https://localhost:8080/#) in fixed_func(*args, **kwargs)
    346 
    347             # Call the function with the fixed arguments
--> 348             return func(*args, **kwargs)
    349 
    350         if func.__doc__ is not None:

[/usr/local/lib/python3.10/dist-packages/skimage/metrics/_structural_similarity.py](https://localhost:8080/#) in structural_similarity(im1, im2, win_size, gradient, data_range, channel_axis, multichannel, gaussian_weights, full, **kwargs)
    166 
    167     if np.any((np.asarray(im1.shape) - win_size) < 0):
--> 168         raise ValueError(
    169             'win_size exceeds image extent. '
    170             'Either ensure that your images are '

ValueError: win_size exceeds image extent. Either ensure that your images are at least 7x7; or pass win_size explicitly in the function call, with an odd value less than or equal to the smaller side of your images. If your images are multichannel (with color channels), set channel_axis to the axis number corresponding to the channels.

Thank you in advance!

Best,

Lucía.

my_model_training_report.pdf

esgomezm commented 9 months ago

Dear @LuciaSchmidt29

My apologies for the delayed response. I have corrected the notebook for RGB images. It should work now. Please, double-check if it works for you now. If it does not work, please, reopen the notebook and show us screenshots of the errors.

Esti