RuntimeError: Found dtype Long but expected Float

前提

https://github.com/Natsu6767/DCGAN-PyTorch
を実装しようとしています。
celebaデータはダウンロードしてある。pathのルート設定もしてある。
なのに動きません

実現したいこと

実装したい。。。。。。。。

発生している問題・エラーメッセージ

エラーメッセージ Traceback (most recent call last): File "C:/Users/phanton/PycharmProjects/pythonProject1/DCGAN-PyTorch-master/DCGAN-PyTorch-master/train.py", line 106, in <module> errD_real = criterion(output, label) File "C:\Users\phanton\anaconda3\envs\deep\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "C:\Users\phanton\anaconda3\envs\deep\lib\site-packages\torch\nn\modules\loss.py", line 613, in forward return F.binary_cross_entropy(input, target, weight=self.weight, reduction=self.reduction) File "C:\Users\phanton\anaconda3\envs\deep\lib\site-packages\torch\nn\functional.py", line 2759, in binary_cross_entropy return torch._C._nn.binary_cross_entropy(input, target, weight, reduction_enum) RuntimeError: Found dtype Long but expected Float

該当のソースコード

for epoch in range(params['nepochs']): for i, data in enumerate(dataloader, 0): # Transfer data tensor to GPU/CPU (device) real_data = data[0].to(device) # Get batch size. Can be different from params['nbsize'] for last batch in epoch. b_size = real_data.size(0) # Make accumalated gradients of the discriminator zero. netD.zero_grad() # Create labels for the real data. (label=1) label = torch.full((b_size, ), real_label, device=device) output = netD(real_data).view(-1) errD_real = criterion(output, label) # Calculate gradients for backpropagation. errD_real.backward() D_x = output.mean().item() ~省略~

試したこと

調べた結果、対処法として「float型にする」ってこと???
https://pizza3900.hatenablog.com/entry/2021/09/07/080000

または
https://stackoverflow.com/questions/62726792/pytorch-runtimeerror-expected-dtype-float-but-got-dtype-long

変え方がおかしいのかまた違うエラーが出てしまいます。

助言お願いします。。。。

補足
READMEを読みながらやりましたが
環境設定の詳細が書かれていなかったので(私の見た範囲では)
torch 1.8
torch vision 0.9.0
numpy 1.23.5
matplotlib 3.6.2
で実装しようとしています。

コメントを投稿

0 コメント