pytorch-simple-gan icon indicating copy to clipboard operation
pytorch-simple-gan copied to clipboard

ValueError: Using a target size (torch.Size([16])) that is different to the input size (torch.Size([16, 1])) is deprecated. Please ensure they have the same size.

Open vwoloszyn opened this issue 3 years ago • 2 comments

I'm getting the following error when trying to execute train.py


ValueError Traceback (most recent call last) in 46 discriminator_loss.backward() 47 discriminator_optimizer.step() ---> 48 train()

in train(max_int, batch_size, training_steps) 31 # to make things the discriminator classifies as true. 32 generator_discriminator_out = discriminator(generated_data) ---> 33 generator_loss = loss(generator_discriminator_out, true_labels) 34 generator_loss.backward() 35 generator_optimizer.step()

/usr/local/lib/python3.9/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs) 887 result = self._slow_forward(*input, **kwargs) 888 else: --> 889 result = self.forward(*input, **kwargs) 890 for hook in itertools.chain( 891 _global_forward_hooks.values(),

/usr/local/lib/python3.9/site-packages/torch/nn/modules/loss.py in forward(self, input, target) 611 def forward(self, input: Tensor, target: Tensor) -> Tensor: 612 assert self.weight is None or isinstance(self.weight, Tensor) --> 613 return F.binary_cross_entropy(input, target, weight=self.weight, reduction=self.reduction) 614 615

/usr/local/lib/python3.9/site-packages/torch/nn/functional.py in binary_cross_entropy(input, target, weight, size_average, reduce, reduction) 2748 reduction_enum = _Reduction.get_enum(reduction) 2749 if target.size() != input.size(): -> 2750 raise ValueError( 2751 "Using a target size ({}) that is different to the input size ({}) is deprecated. " 2752 "Please ensure they have the same size.".format(target.size(), input.size())

ValueError: Using a target size (torch.Size([16])) that is different to the input size (torch.Size([16, 1])) is deprecated. Please ensure they have the same size.

[-]

vwoloszyn avatar Mar 09 '21 08:03 vwoloszyn

I got this error as well

reneelin1712 avatar Jul 26 '21 03:07 reneelin1712

Hello! I have fixed this error in the following patch. https://github.com/CAPTAIN320/pytorch-simple-gan/tree/CAPTAIN320-patch

CAPTAIN320 avatar Oct 02 '21 11:10 CAPTAIN320