inflearn logo
강의

Course

Instructor

[PyTorch] Learn GAN easily and quickly

[Practice] DCGAN/LSGAN

runtime error : Found dtype Long but expected Float

1531

kimkim1029

17 asked

0

안녕하세요~ 실습 DCGAN 부분에서 D 네트워크를 업데이트 하는 부분에서 에러가 나는데, 라인별로 타입을 확인하면서 수정하려 했는데, 왜 에러가 나는지 모르겠네요 ㅠㅠ 도움 부탁 드립니다. 

인공신경망 딥러닝 pytorch

Answer 3

2

gibiee0431

output, label 둘 다 추가해주니 실행되네요.

---------------------------------------------------------------------------

output = netD(real_cpu).view(-1)

(추가) output = output.type(torch.FloatTensor).cuda()

(추가) label = label.type(torch.FloatTensor).cuda()

errD_real = criterion(output, label)

---------------------------------------------------------------------------

cuda 안 쓰시면 뒤에 .cuda()는 빼셔야 하구요.

1

kimkim1029

아~! 답을 찾았습니다. 아래 처럼 바꾸니 되네요 ^^

output = netD(real_cpu).view(-1)

#추가하는 줄 

output = output.type(torch.FloatTensor)

0

ssungw72674

        real_cpu = data[0].to(device)
        b_size = real_cpu.size(0)
        label = torch.full((b_size,), real_label, device=device)
        output = netD(real_cpu).view(-1)
        
        output = output.type(torch.FloatTensor)
추가해도 저는 똑같네요
Starting Training Loop...
--------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-16-7c0f18f95470> in <module> 23 output = output.type(torch.FloatTensor) 24 ---> 25 errD_real = criterion(output, label) 26 errD_real.backward() 27 D_x = output.mean().item() ~\anaconda3\envs\pytorch3.7\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs) 725 result = self._slow_forward(*input, **kwargs) 726 else: --> 727 result = self.forward(*input, **kwargs) 728 for hook in itertools.chain( 729 _global_forward_hooks.values(), ~\anaconda3\envs\pytorch3.7\lib\site-packages\torch\nn\modules\loss.py in forward(self, input, target) 528 529 def forward(self, input: Tensor, target: Tensor) -> Tensor: --> 530 return F.binary_cross_entropy(input, target, weight=self.weight, reduction=self.reduction) 531 532 ~\anaconda3\envs\pytorch3.7\lib\site-packages\torch\nn\functional.py in binary_cross_entropy(input, target, weight, size_average, reduce, reduction) 2524 2525 return torch._C._nn.binary_cross_entropy( -> 2526 input, target, weight, reduction_enum) 2527 2528 RuntimeError: Found dtype Long but expected Float

import torch가 안되는 경우는 어떻게 하나요?

0

15

1

DCGAN 실습에 있는 celba 이미지 다운로드 권한 요청

0

381

0

GAN의 베이스코드에 대하여

0

324

0

(Pdata + Pg) / 2 가 왜 Q인가요?

0

257

0

z의 x 변환

0

297

0

cuda 버전 질문입니다!

0

238

0

결과를 다운받는 방법이 궁금합니다.

0

234

0

DCGAN Generator 질문

0

269

0

DCGAN 실습 Generator 질문

0

475

1

LSGAN 파트 질문입니다

0

359

0

output with shape [1, 28, 28] doesn't match the broadcast shape [3, 28, 28]

0

677

1

runtime error : Found dtype Long but expected Float

0

389

1

컴퓨터 사양 문의 드립니다.

0

465

2

runtime_Found 0 files

0

227

1

transforms.Normalize

0

426

2

cpu로 돌릴 경우, 코드 수정

1

303

1

GAN - Audio 관련 연구

0

261

1

강의자료 문의

0

338

2

문의사항

0

251

1

데이터

0

240

1

GAN

0

213

1

GAN 프로젝트

0

271

1

celeba 이미지 불러오기 실패

0

621

2

dcgan, lsgan 질문

0

305

2