sergeywong / cp-vton

Reimplemented code for "Toward Characteristic-Preserving Image-based Virtual Try-On Network"
MIT License
474 stars 182 forks source link

Training gives runtime shape error on first image #26

Open Mi5ke opened 4 years ago

Mi5ke commented 4 years ago

Hi,

I have downloaded all the data with data_download.py, but...

When I try to train CP-VTON GMM stage, I get this error immediately:

RuntimeError: output with shape [1, 256, 192] doesn't match the broadcast shape [3, 256, 192]

See the full log below. Any help much appreciated! (I get the same error if I run cp_dataset.py alone.)

Thanks,

Mike

C:\Users\Mike\AppData\Local\Programs\Python\Python36\python.exe M:/VITON/cp-vton-master/train.py --name gmm_train_new --stage GMM --save_count 5000 --shuffle
Namespace(batch_size=4, checkpoint='', checkpoint_dir='checkpoints', data_list='train_pairs.txt', datamode='train', dataroot='data', decay_step=100000, display_count=20, fine_height=256, fine_width=192, gpu_ids='', grid_size=5, keep_step=100000, lr=0.0001, name='gmm_train_new', radius=5, save_count=5000, shuffle=True, stage='GMM', tensorboard_dir='tensorboard', workers=1)
Start to train stage: GMM, named: gmm_train_new!
initialization method [normal]
initialization method [normal]
Traceback (most recent call last):
  File "M:/VITON/cp-vton-master/train.py", line 191, in <module>
    main()
  File "M:/VITON/cp-vton-master/train.py", line 176, in main
    train_gmm(opt, train_loader, model, board)
  File "M:/VITON/cp-vton-master/train.py", line 58, in train_gmm
    inputs = train_loader.next_batch()
  File "M:\VITON\cp-vton-master\cp_dataset.py", line 166, in next_batch
    batch = self.data_iter.__next__()
  File "C:\Users\Mike\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\utils\data\dataloader.py", line 819, in __next__
    return self._process_data(data)
  File "C:\Users\Mike\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\utils\data\dataloader.py", line 846, in _process_data
    data.reraise()
  File "C:\Users\Mike\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\_utils.py", line 369, in reraise
    raise self.exc_type(msg)
RuntimeError: Caught RuntimeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "C:\Users\Mike\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\utils\data\_utils\worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "C:\Users\Mike\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "C:\Users\Mike\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "M:\VITON\cp-vton-master\cp_dataset.py", line 86, in __getitem__
    shape = self.transform(parse_shape) # [-1,1]
  File "C:\Users\Mike\AppData\Local\Programs\Python\Python36\lib\site-packages\torchvision\transforms\transforms.py", line 61, in __call__
    img = t(img)
  File "C:\Users\Mike\AppData\Local\Programs\Python\Python36\lib\site-packages\torchvision\transforms\transforms.py", line 166, in __call__
    return F.normalize(tensor, self.mean, self.std, self.inplace)
  File "C:\Users\Mike\AppData\Local\Programs\Python\Python36\lib\site-packages\torchvision\transforms\functional.py", line 217, in normalize
    tensor.sub_(mean[:, None, None]).div_(std[:, None, None])
RuntimeError: output with shape [1, 256, 192] doesn't match the broadcast shape [3, 256, 192]

Process finished with exit code 1
HFVladimir commented 4 years ago

Hi! This happens in latest versions of pytorch. You need to change transform function in dataset class from self.transform = transforms.Compose([ \ transforms.ToTensor(), \ transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]) to self.transform = transforms.Compose([ \ transforms.ToTensor(), \ transforms.Normalize((0.5,), (0.5,))])