이미지 · 비전 · 55분

ResNet 사전학습 분류

모델을 평가 모드로 만들고, 단일 이미지를 전처리해 추론한 뒤 top-5 라벨을 표시합니다.

Web에서 개념과 코드 학습운영체제 권한이 필요한 실행은 Local에서 이어집니다.
deepVision.classification
01

1단계. 모델 로드

torchvision.models.resnet18을 사전학습 가중치로 불러옵니다.

  • models.resnet18 한 줄로 사전학습 모델을 받습니다.
  • model.eval과 torch.inference_mode로 추론 모드를 정합니다.
  • logits에서 softmax 확률 top-5를 뽑는 패턴을 익힙니다.
직접 해보기모델의 총 파라미터 수를 계산하세요.
import torch
import torchvision
from torchvision.models import resnet18, ResNet18_Weights
from torchvision import transforms
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from sklearn.datasets import load_sample_image

weights = ResNet18_Weights.DEFAULT
model = resnet18(weights=weights)
type(model).__name__
편집기를 준비하고 있습니다.