Skip to content

Latest commit

Β 

History

History
112 lines (86 loc) Β· 5.1 KB

nvidia_deeplearningexamples_resnet50.md

File metadata and controls

112 lines (86 loc) Β· 5.1 KB
layout background-class body-class title summary category image author tags github-link github-id featured_image_1 featured_image_2 accelerator order demo-model-link
hub_detail
hub-background
hub
ResNet50
ResNet50 model trained with mixed precision using Tensor Cores.
researchers
nvidia_logo.png
NVIDIA
vision
NVIDIA/DeepLearningExamples
classification.jpg
no-image
cuda
10

λͺ¨λΈ μ„€λͺ…

ResNet50 v1.5λͺ¨λΈμ€ original ResNet50 v1 model의 μˆ˜μ •λœ λ²„μ „μž…λ‹ˆλ‹€.

v1κ³Ό v1.5의 차이점은 λ‹€μš΄μƒ˜ν”Œλ§μ΄ ν•„μš”ν•œ 병λͺ© λΈ”λ‘μ—μ„œ v1은 첫 번째 1x1 μ»¨λ³Όλ£¨μ…˜μ—μ„œ μŠ€νŠΈλΌμ΄λ“œ = 2λ₯Ό κ°–λŠ” 반면 v1.5λŠ” 3x3 μ»¨λ³Όλ£¨μ…˜μ—μ„œ μŠ€νŠΈλΌμ΄λ“œ = 2λ₯Ό κ°–λŠ”λ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€.

μ΄λŸ¬ν•œ μ°¨μ΄λŠ” ResNet50 v1.5λ₯Ό v1보닀 쑰금 더 μ •ν™•ν•˜κ²Œ λ§Œλ“€μ§€λ§Œ(~0.5% top1) μ•½κ°„μ˜ μ„±λŠ₯적인 단점(~5% imgs/sec)이 μžˆμŠ΅λ‹ˆλ‹€.

λͺ¨λΈμ€ Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification에 μ„€λͺ…λœ λŒ€λ‘œ μ΄ˆκΈ°ν™”λ©λ‹ˆλ‹€.

이 λͺ¨λΈμ€ Volta, Turing 및 NVIDIA Ampere GPU μ•„ν‚€ν…μ²˜μ˜ Tensor μ½”μ–΄λ₯Ό μ‚¬μš©ν•˜μ—¬ ν˜Όν•© 정밀도(mixed precision)둜 ν•™μŠ΅λ©λ‹ˆλ‹€. λ”°λΌμ„œ μ—°κ΅¬μžλ“€μ€ ν˜Όν•© μ •λ°€ ꡐ윑의 이점을 κ²½ν—˜ν•˜λ©΄μ„œ Tensor Core 없이 ν•™μŠ΅ν•˜λŠ” 것보닀 2λ°° 이상 λΉ λ₯Έ κ²°κ³Όλ₯Ό 얻을 수 μžˆμŠ΅λ‹ˆλ‹€. 이 λͺ¨λΈμ€ μ‹œκ°„μ΄ 지남에 따라 μΌκ΄€λœ μ •ν™•μ„±κ³Ό μ„±λŠ₯을 보μž₯ν•˜κΈ° μœ„ν•΄ 각 NGC 월별 μ»¨ν…Œμ΄λ„ˆ λ¦΄λ¦¬μŠ€μ— λŒ€ν•΄ ν…ŒμŠ€νŠΈλ©λ‹ˆλ‹€.

ResNet50 v1.5 λͺ¨λΈμ€ TorchScript, ONNX Runtime λ˜λŠ” TensorRTλ₯Ό μ‹€ν–‰ λ°±μ—”λ“œλ‘œ μ‚¬μš©ν•˜μ—¬ NVIDIA Triton Inference Serverμ—μ„œ 좔둠을 μœ„ν•΄ 배치될 수 μžˆμŠ΅λ‹ˆλ‹€. μžμ„Έν•œ λ‚΄μš©μ€ NGCλ₯Ό ν™•μΈν•˜μ‹­μ‹œμ˜€.

μ˜ˆμ‹œ 사둀

μ•„λž˜ μ˜ˆμ œμ—μ„œλŠ” 사전 ν›ˆλ ¨λœ ResNet50 v1.5 λͺ¨λΈμ„ μ‚¬μš©ν•˜μ—¬ 이미지에 λŒ€ν•œ 좔둠을 μˆ˜ν–‰ ν•˜κ³  κ²°κ³Όλ₯Ό μ œμ‹œν•  κ²ƒμž…λ‹ˆλ‹€.

예제λ₯Ό μ‹€ν–‰ν•˜λ €λ©΄ λͺ‡ 가지 μΆ”κ°€ 파이썬 νŒ¨ν‚€μ§€κ°€ μ„€μΉ˜λ˜μ–΄ μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€. μ΄λŠ” 이미지λ₯Ό μ „μ²˜λ¦¬ν•˜κ³  μ‹œκ°ν™”ν•˜λŠ” 데 ν•„μš”ν•©λ‹ˆλ‹€.

!pip install validators matplotlib
import torch
from PIL import Image
import torchvision.transforms as transforms
import numpy as np
import json
import requests
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline

device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
print(f'Using {device} for inference')

IMAGENET λ°μ΄ν„°μ…‹μ—μ„œ 사전 ν›ˆλ ¨λœ λͺ¨λΈμ„ λ‘œλ“œν•©λ‹ˆλ‹€.

resnet50 = torch.hub.load('NVIDIA/DeepLearningExamples:torchhub', 'nvidia_resnet50', pretrained=True)
utils = torch.hub.load('NVIDIA/DeepLearningExamples:torchhub', 'nvidia_convnets_processing_utils')

resnet50.eval().to(device)

μƒ˜ν”Œ μž…λ ₯ 데이터λ₯Ό μ€€λΉ„ν•©λ‹ˆλ‹€.

uris = [
    'http://images.cocodataset.org/test-stuff2017/000000024309.jpg',
    'http://images.cocodataset.org/test-stuff2017/000000028117.jpg',
    'http://images.cocodataset.org/test-stuff2017/000000006149.jpg',
    'http://images.cocodataset.org/test-stuff2017/000000004954.jpg',
]

batch = torch.cat(
    [utils.prepare_input_from_uri(uri) for uri in uris]
).to(device)

좔둠을 μ‹€ν–‰ν•©λ‹ˆλ‹€. pick_n_best(predictions=output, n=topN) helper ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•˜μ—¬ λͺ¨λΈμ— 따라 κ°€μž₯ κ°€λŠ₯성이 높은 가섀을 N개 μ„ νƒν•©λ‹ˆλ‹€.

with torch.no_grad():
    output = torch.nn.functional.softmax(resnet50(batch), dim=1)
    
results = utils.pick_n_best(predictions=output, n=5)

κ²°κ³Όλ₯Ό ν‘œμ‹œν•©λ‹ˆλ‹€.

for uri, result in zip(uris, results):
    img = Image.open(requests.get(uri, stream=True).raw)
    img.thumbnail((256,256), Image.ANTIALIAS)
    plt.imshow(img)
    plt.show()
    print(result)

세뢀사항

λͺ¨λΈ μž…λ ₯ 및 좜λ ₯, ν•™μŠ΅ 방법, μΆ”λ‘  및 μ„±λŠ₯ 등에 λŒ€ν•œ 더 μžμ„Έν•œ μ •λ³΄λŠ” github 및 and/or NGCμ—μ„œ λ³Ό 수 μžˆμŠ΅λ‹ˆλ‹€.

μ°Έκ³ λ¬Έν—Œ