λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
μ—λŸ¬ 및 이슈

[PyTorch] NotImplementedError: "normal_kernel_cpu" not implemented for 'Byte'

by kaizen_bh 2025. 9. 4.

 

λ°°κ²½ 및 μ—λŸ¬ λ‚΄μš©

PyTorch둜 이미지λ₯Ό ν•Έλ“€λ§ν•˜λ˜ 쀑 λ…Έμ΄μ¦ˆλ₯Ό μΆ”κ°€ν•˜μ—¬ augmentation ν•˜λ €ν–ˆλ‹€

이미지 μ‚¬μ΄μ¦ˆμ™€ 같은 ν‘œμ€€μ •κ·œλΆ„ν¬ λ‚œμˆ˜ ν…μ„œλ‘œ λ³€ν™˜μ‹œ λ°œμƒν•œ μ—λŸ¬μ΄λ‹€

 

img_t.shape
torch.Size([720, 1280, 3])
---
random_noise = torch.randn_like(img_t)
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
/tmp/ipython-input-120581056.py in <cell line: 0>()
----> 1 random_noise = torch.randn_like(img_t)

NotImplementedError: "normal_kernel_cpu" not implemented for 'Byte'

 

 

 

원인은 데이터 νƒ€μž… 뢈일치

img_t.shape
=> torch.Size([720, 1280, 3])
  • img_tλŠ” dtype이 torch.uint8 (Byte)인 이미지 → 0~255 μ •μˆ˜κ°’
  • torch.randn_likeλŠ” λΆ€λ™μ†Œμˆ˜μ  ν…μ„œ(float)λ₯Ό ν•„μš”λ‘œ 함
  • uint8μ—λŠ” normal_kernel_cpuκ°€ κ΅¬ν˜„λ˜μ–΄ μžˆμ§€ μ•Šμ•„μ„œ NotImplementedError λ°œμƒ

μ •μˆ˜ν˜• ν…μ„œμ—λŠ” λ°”λ‘œ randn_likeλ₯Ό μ‚¬μš©ν•  수 μ—†λ‹€

 

 

 

 

 

 

ν•΄κ²° 방법

 

1. float으둜 λ³€ν™˜ ν›„ noise 생성

random_noise = torch.randn_like(img_t.float())  # float으둜 λ³€ν™˜

 

 

2. 0~1 λ²”μœ„λ‘œ μ •κ·œν™” ν›„ noise 생성

img_float = img_t.float() / 255.0
random_noise = torch.randn_like(img_float)

 

 

3. νŠΉμ • dtype μ§€μ •

random_noise = torch.randn(img_t.shape, dtype=torch.float32)
random_noise = torch.randn_like(img_t, dtype=torch.float)

 

 

 

 

 

 


 

 

 

κ³΅λΆ€ν•˜λ©΄μ„œ 데이터 νƒ€μž…κ³Ό κ΄€λ ¨λœ μ—λŸ¬λ“€μ„ μ’…μ’… λ§ˆμ£Όν•˜λŠ” 쀑.

데이터 λ³€ν™˜ 및 μ „μ²˜λ¦¬ μ‹œ 늘 νƒ€μž…μ— μ£Όμ˜ν•˜μž