Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: output with shape [1, 300, 200] doesn't match the broadcast shape [3, 300, 200] #36

Closed
raitmoon opened this issue Oct 19, 2019 · 7 comments

Comments

@raitmoon
Copy link

raitmoon commented Oct 19, 2019

Hello, I'm following the instruction but faced the error while training.
I ran the script on Macbook Pro.
Do you have any idea to fix this issue?

$ python train.py --dataroot ./datasets/jeans2skirt_ccp --model insta_gan --name jeans2skirt_ccp_instagan --loadSizeH 330 --loadSizeW 220 --fineSizeH 300 --fineSizeW 200 --niter 400 --niter_decay 200 --gpu_ids -1
----------------- Options ---------------
               batch_size: 1                             
                    beta1: 0.5                           
          checkpoints_dir: ./checkpoints                 
           continue_train: False                         
                 dataroot: ./datasets/jeans2skirt_ccp    	[default: None]
             dataset_mode: unaligned_seg                 
                direction: AtoB                          
              display_env: main                          
             display_freq: 400                           
               display_id: 1                             
            display_ncols: 6                             
             display_port: 8097                          
           display_server: http://localhost              
          display_winsize: 256                           
                    epoch: latest                        
              epoch_count: 1                             
                fineSizeH: 300                           	[default: 200]
                fineSizeW: 200                           
                  gpu_ids: -1                            	[default: 0]
                init_gain: 0.02                          
                init_type: normal                        
                 input_nc: 3                             
                  ins_max: 4                             
                  ins_per: 2                             
                  isTrain: True                          	[default: None]
                 lambda_A: 10.0                          
                 lambda_B: 10.0                          
               lambda_ctx: 1.0                           
               lambda_idt: 1.0                           
                loadSizeH: 330                           	[default: 220]
                loadSizeW: 220                           
                load_iter: 0                             	[default: 0]
                       lr: 0.0002                        
           lr_decay_iters: 50                            
                lr_policy: lambda                        
         max_dataset_size: inf                           
                    model: insta_gan                     
               n_layers_D: 3                             
                     name: jeans2skirt_ccp_instagan      	[default: experiment_name]
                      ndf: 64                            
                     netD: set                           
                     netG: set                           
                      ngf: 64                            
                    niter: 400                           	[default: 100]
              niter_decay: 200                           	[default: 100]
               no_dropout: True                          
                  no_flip: False                         
                  no_html: False                         
                 no_lsgan: False                         
                     norm: instance                      
              num_threads: 4                             
                output_nc: 3                             
                    phase: train                         
                pool_size: 50                            
               print_freq: 100                           
           resize_or_crop: resize_and_crop               
             save_by_iter: False                         
          save_epoch_freq: 5                             
         save_latest_freq: 5000                          
           serial_batches: False                         
                set_order: decreasing                    
                   suffix:                               
         update_html_freq: 1000                          
                  verbose: False                         
----------------- End -------------------
dataset [UnalignedSegDataset] was created
#training images = 167
initialize network with normal
initialize network with normal
initialize network with normal
initialize network with normal
model [InstaGANModel] was created
---------- Networks initialized -------------
[Network G_A] Total number of parameters : 26.815 M
[Network G_B] Total number of parameters : 26.815 M
[Network D_A] Total number of parameters : 9.754 M
[Network D_B] Total number of parameters : 9.754 M
-----------------------------------------------
Setting up a new session...
create web directory ./checkpoints/jeans2skirt_ccp_instagan/web...
Traceback (most recent call last):
  File "train.py", line 24, in <module>
    for i, data in enumerate(dataset):
  File "/Users/tomo/Documents/GitHub/instagan/data/__init__.py", line 72, in __iter__
    for i, data in enumerate(self.dataloader):
  File "/Users/tomo/.pyenv/versions/3.7.4/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 819, in __next__
    return self._process_data(data)
  File "/Users/tomo/.pyenv/versions/3.7.4/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data
    data.reraise()
  File "/Users/tomo/.pyenv/versions/3.7.4/lib/python3.7/site-packages/torch/_utils.py", line 385, in reraise
    raise self.exc_type(msg)
RuntimeError: Caught RuntimeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/Users/tomo/.pyenv/versions/3.7.4/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/Users/tomo/.pyenv/versions/3.7.4/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/Users/tomo/.pyenv/versions/3.7.4/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/Users/tomo/Documents/GitHub/instagan/data/unaligned_seg_dataset.py", line 71, in __getitem__
    A_segs = self.read_segs(A_seg_path, seed)
  File "/Users/tomo/Documents/GitHub/instagan/data/unaligned_seg_dataset.py", line 42, in read_segs
    seg = self.fixed_transform(seg, seed)
  File "/Users/tomo/Documents/GitHub/instagan/data/unaligned_seg_dataset.py", line 34, in fixed_transform
    return self.transform(image)
  File "/Users/tomo/.pyenv/versions/3.7.4/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 61, in __call__
    img = t(img)
  File "/Users/tomo/.pyenv/versions/3.7.4/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 166, in __call__
    return F.normalize(tensor, self.mean, self.std, self.inplace)
  File "/Users/tomo/.pyenv/versions/3.7.4/lib/python3.7/site-packages/torchvision/transforms/functional.py", line 217, in normalize
    tensor.sub_(mean[:, None, None]).div_(std[:, None, None])
RuntimeError: output with shape [1, 300, 200] doesn't match the broadcast shape [3, 300, 200]

I tried the other one, pants2skirt_mhp_instagan but almost same result.
RuntimeError: output with shape [1, 240, 160] doesn't match the broadcast shape [3, 240, 160]
I'm sorry if this is not the right place to ask.
Thanks in advance.

@sangwoomo
Copy link
Owner

sangwoomo commented Oct 21, 2019

Hi, it seems that the image type (RGB vs black/white) does not match in some reason.
Please see ./data/unaligned_seg_dataset.py to check if the loaded image is 1-channel and 3-channel, and also check the required channel for models.

@raitmoon
Copy link
Author

Thank you for your suggestion.

I searched on the internet and finally got solved by downgrading torchvision from 0.4.1 to 0.2.1.

pip3 uninstall torchvision
pip3 install torchvision=0.2.1

Many of them suggest transforms.Normalize((0.5,), (0.5,)) but didn't help.
https://stackoverflow.com/questions/55124407/output-and-broadcast-shape-mismatch-in-mnist-torchvision
I'm not sure what was the original problem though..

@bboynton97
Copy link

I ran into the same issue. The torchvision version should be specified in requirements.txt and the conda script.

@sangwoomo
Copy link
Owner

Hi, thank you for your suggestion. I modified requirements.txt to use == instead of >=.

@bboynton97
Copy link

Thanks for the super quick response! Great job on the paper btw. I'm using it for a class project.

@sangwoomo
Copy link
Owner

Thanks for your interest! :)

@sangwoomo sangwoomo mentioned this issue Dec 4, 2019
@VicZlq
Copy link

VicZlq commented Dec 5, 2019

Hi, thank you for your suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants