gouayao / MCL

2 stars 0 forks source link

RuntimeError: shape '[-1, 30]' is invalid for input of size 3844 #1

Closed Bananaspirit closed 5 months ago

Bananaspirit commented 5 months ago

@gouayao Hello! Thanks for this repository! I'm trying to run training with these parameters:

python train.py --dataroot ./datasets/kromka1624x1240CUT --name kromka1624x1240MCL_crop-size512 \
    --model imcl --display_id -1 --gpu_ids 0 --batch_size 1 \
    --preprocess crop --crop_size 512

but I get this error:

----------------- Options ---------------
                IMCL_mode: IMCL                          
               batch_size: 1                             
                    beta1: 0.5                           
                    beta2: 0.999                         
          checkpoints_dir: ./checkpoints                 
           continue_train: False                         
                crop_size: 512                                  [default: 256]
                 dataroot: ./datasets/kromka1624x1240CUT        [default: placeholder]
             dataset_mode: unaligned                     
                direction: AtoB                          
              display_env: main                          
             display_freq: 400                           
               display_id: -1                                   [default: None]
            display_ncols: 4                             
             display_port: 8097                          
           display_server: http://localhost              
          display_winsize: 256                           
               easy_label: experiment_name               
                    epoch: latest                        
              epoch_count: 1                             
          evaluation_freq: 5000                          
        flip_equivariance: False                         
                 gan_mode: lsgan                         
                  gpu_ids: 0                             
                init_gain: 0.02                          
                init_type: xavier                        
                 input_nc: 3                             
                  isTrain: True                                 [default: None]
               lambda_GAN: 1.0                           
               lambda_NCE: 1.0                           
                      lbd: 0.01                          
                load_size: 286                           
                       lr: 0.0002                        
           lr_decay_iters: 50                            
                lr_policy: linear                        
         max_dataset_size: inf                           
                    model: imcl                                 [default: cut]
                 n_epochs: 200                           
           n_epochs_decay: 200                           
               n_layers_D: 3                             
                     name: kromka1624x1240MCL_crop-size512      [default: experiment_name]
                    nce_T: 0.07                          
                  nce_idt: True                          
nce_includes_all_negatives_from_minibatch: False                         
               nce_layers: 0,4,8,12,16                   
                      ndf: 64                            
                     netD: basic                         
                     netF: mlp_sample                    
                  netF_nc: 256                           
                     netG: resnet_9blocks                
                      ngf: 64                            
             no_antialias: False                         
          no_antialias_up: False                         
               no_dropout: True                          
                  no_flip: False                         
                  no_html: False                         
                    normD: instance                      
                    normG: instance                      
              num_patches: 256                           
              num_threads: 4                             
                output_nc: 3                             
                    phase: train                         
                pool_size: 0                             
               preprocess: crop                                 [default: resize_and_crop]
          pretrained_name: None                          
               print_freq: 100                           
         random_scale_max: 3.0                           
             save_by_iter: False                         
          save_epoch_freq: 5                             
         save_latest_freq: 5000                          
           serial_batches: False                         
stylegan2_G_num_downsampling: 1                             
                   suffix:                               
                     temp: 0.1                           
         update_html_freq: 1000                          
                  verbose: False                         
----------------- End -------------------
dataset [UnalignedDataset] was created
model [IMCLModel] was created
The number of training images = 15921
create web directory ./checkpoints/kromka1624x1240MCL_crop-size512/web...
Traceback (most recent call last):
  File "/scratch/train.py", line 43, in <module>
    model.data_dependent_initialize(data)
  File "/scratch/models/imcl_model.py", line 118, in data_dependent_initialize
    self.compute_D_loss().backward()                  # calculate gradients for D
  File "/scratch/models/imcl_model.py", line 182, in compute_D_loss
    mcl_fake = F.normalize(pred_fake.view(-1, 30))
RuntimeError: shape '[-1, 30]' is invalid for input of size 3844
gouayao commented 5 months ago

Thanks for your support of our work. This error may be due to the size of the input image, you could try using a 256 × 256 resolution. Alternatively, you could modify the size of the discriminator output layer matrix (which is set to 30 × 30 in this paper).

At 2024-05-07 21:33:59, "Дмитрий Насонов" @.***> wrote:

@gouayao Hello! Thanks for this repository! I'm trying to run training with these parameters:

python train.py --dataroot ./datasets/kromka1624x1240CUT --name kromka1624x1240MCL_crop-size512 \ --model imcl --display_id -1 --gpu_ids 0 --batch_size 1 \ --preprocess crop --crop_size 512

but I get this error:

----------------- Options --------------- IMCL_mode: IMCL
batch_size: 1
beta1: 0.5
beta2: 0.999
checkpoints_dir: ./checkpoints
continue_train: False
crop_size: 512 [default: 256] dataroot: ./datasets/kromka1624x1240CUT [default: placeholder] dataset_mode: unaligned
direction: AtoB
display_env: main
display_freq: 400
display_id: -1 [default: None] display_ncols: 4
display_port: 8097
display_server: http://localhost
display_winsize: 256
easy_label: experiment_name
epoch: latest
epoch_count: 1
evaluation_freq: 5000
flip_equivariance: False
gan_mode: lsgan
gpu_ids: 0
init_gain: 0.02
init_type: xavier
input_nc: 3
isTrain: True [default: None] lambda_GAN: 1.0
lambda_NCE: 1.0
lbd: 0.01
load_size: 286
lr: 0.0002
lr_decay_iters: 50
lr_policy: linear
max_dataset_size: inf
model: imcl [default: cut] n_epochs: 200
n_epochs_decay: 200
n_layers_D: 3
name: kromka1624x1240MCL_crop-size512 [default: experiment_name] nce_T: 0.07
nce_idt: True
nce_includes_all_negatives_from_minibatch: False
nce_layers: 0,4,8,12,16
ndf: 64
netD: basic
netF: mlp_sample
netF_nc: 256
netG: resnet_9blocks
ngf: 64
no_antialias: False
no_antialias_up: False
no_dropout: True
no_flip: False
no_html: False
normD: instance
normG: instance
num_patches: 256
num_threads: 4
output_nc: 3
phase: train
pool_size: 0
preprocess: crop [default: resize_and_crop] pretrained_name: None
print_freq: 100
random_scale_max: 3.0
save_by_iter: False
save_epoch_freq: 5
save_latest_freq: 5000
serial_batches: False
stylegan2_G_num_downsampling: 1
suffix:
temp: 0.1
update_html_freq: 1000
verbose: False
----------------- End ------------------- dataset [UnalignedDataset] was created model [IMCLModel] was created The number of training images = 15921 create web directory ./checkpoints/kromka1624x1240MCL_crop-size512/web... Traceback (most recent call last): File "/scratch/train.py", line 43, in model.data_dependent_initialize(data) File "/scratch/models/imcl_model.py", line 118, in data_dependent_initialize self.compute_D_loss().backward() # calculate gradients for D File "/scratch/models/imcl_model.py", line 182, in compute_D_loss mcl_fake = F.normalize(pred_fake.view(-1, 30)) RuntimeError: shape '[-1, 30]' is invalid for input of size 3844

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

Bananaspirit commented 5 months ago

@gouayao Thank you for your quick response, I’ll try to do as you say!

Bananaspirit commented 5 months ago

@gouayao I managed to start training with the crop_size 256 flag, but training does not start with values other than 256. Tell me if it is possible to make the code more universal so that the values 512, 128, 64, etc. can be used.

gouayao commented 5 months ago

You could modify the size of the discriminator output layer matrix to fit the input image.

At 2024-05-16 15:28:43, "Дмитрий Насонов" @.***> wrote:

@gouayao I managed to start training with the crop_size 256 flag, but training does not start with values other than 256. Tell me if it is possible to make the code more universal so that the values 512, 128, 64, etc. can be used.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>