GAN 평가

PyTorch로 배우는 이미지 딥러닝

Michal Oleszak

Machine Learning Engineer

이미지 생성

num_images_to_generate = 9
noise = torch.randn(num_images_to_generate, 16)

with torch.no_grad(): fake = gen(noise)
print(f"Generated shape: {fake.shape}")
Generated shape: torch.Size([9, 3, 96, 96])
for i in range(num_images_to_generate):

image_tensor = fake[i, :, :, :]
image_permuted = image_tensor.permute(1, 2, 0)
plt.imshow(image_permuted) plt.show()
  • 무작위 노이즈 텐서 생성
  • 노이즈를 생성기에 전달
  • 이미지 수만큼 반복
  • fake에서 i번째 이미지 슬라이싱
  • 이미지 차원 재배열
  • 이미지 표시
PyTorch로 배우는 이미지 딥러닝

GAN 생성물

GAN이 생성한 포켓몬 이미지 샘플.

PyTorch로 배우는 이미지 딥러닝

프레셰 인셉션 거리

  • Inception: 이미지 분류 모델
  • 프레셰 거리: 두 확률분포 간 거리 측도
  • 프레셰 인셉션 거리(FID):
    1. Inception으로 실제/가짜 이미지에서 특성 추출
    2. 실제/가짜 특성의 평균과 공분산 계산
    3. 두 정규분포 간 프레셰 거리 계산
  • FID 낮음 = 가짜가 학습 데이터와 유사하고 다양함
  • FID < 10 = 우수
PyTorch로 배우는 이미지 딥러닝

PyTorch에서 FID

from torchmetrics.image.fid import \
FrechetInceptionDistance


fid = FrechetInceptionDistance(feature=64)
fid.update( (fake * 255).to(torch.uint8), real=False)
fid.update( (real * 255).to(torch.uint8), real=True)
fid.compute()
tensor(7.5159)
  • FrechetInceptionDistance 임포트
  • FID 메트릭 생성
  • 가짜 이미지로 메트릭 업데이트:
    • 255를 곱함
    • torch.uint8로 캐스팅
  • 실제 이미지로도 동일하게 업데이트
  • 메트릭 값 계산
PyTorch로 배우는 이미지 딥러닝

Let's practice!

PyTorch로 배우는 이미지 딥러닝

Preparing Video For Download...