PyTorch-CycleGAN
PyTorch-CycleGAN copied to clipboard
needs update utils.py by updating PyTorch0.4
Now if I run this utils.py and get this error
➜ python train --dataroot datasets/horse2zebra/
Namespace(batchSize=1, cuda=False, dataroot='datasets/horse2zebra/', decay_epoch=100, epoch=0, input_nc=3, lr=0.0002, n_cpu=8, n_epochs=200, output_nc=3, size=256)
/Users/tk/python_dir/pytorch_dir/Cycle/PyTorch-CycleGAN/utils.py:114: UserWarning: nn.init.normal is now deprecated in favor of nn.init.normal_.
torch.nn.init.normal(m.weight.data, 0.0, 0.02)
WARNING:root:Setting up a new session...
Epoch 001/200 [0001/1334] -- Traceback (most recent call last):
File "train", line 176, in <module>
images={'real_A': real_A, 'real_B': real_B, 'fake_A': fake_A, 'fake_B': fake_B})
File "/Users/tk/python_dir/pytorch_dir/ramen2zirou/PyTorch-CycleGAN/utils.py", line 39, in log
self.losses[loss_name] = losses[loss_name].data[0]
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
So utils.py update in line 39 and line 41
self.losses[loss_name] = losses[loss_name].data[0]
to
self.losses[loss_name] = losses[loss_name].item()
if you run train and get this error
input and target shapes do not match: input [1 x 1], target [1] at /pytorch/
you may change your code in train from
loss_GAN_B2A = criterion_GAN(pred_fake, target_real)
to
loss_GAN_B2A = criterion_GAN(pred_fake.squeeze(1), target_real)
other similar codes are also changed so.