From 88ac6ab1f00ea78a11de565b225dd2dab310496c Mon Sep 17 00:00:00 2001 From: woodywarhol9 Date: Sat, 23 Jul 2022 11:18:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[Test]=20:=20pytorch=5Fvision=5Fmeal=5Fv2.m?= =?UTF-8?q?d=20=EB=B2=88=EC=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pytorch_vision_meal_v2.md | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/pytorch_vision_meal_v2.md b/pytorch_vision_meal_v2.md index a5b36ff..c5eb047 100644 --- a/pytorch_vision_meal_v2.md +++ b/pytorch_vision_meal_v2.md @@ -17,7 +17,7 @@ order: 10 demo-model-link: https://huggingface.co/spaces/pytorch/MEAL-V2 --- -We require one additional Python dependency +추가로 1개의 파이썬 패키지를 설치해야 합니다. ```bash !pip install timm @@ -25,21 +25,18 @@ We require one additional Python dependency ```python import torch -# list of models: 'mealv1_resnest50', 'mealv2_resnest50', 'mealv2_resnest50_cutmix', 'mealv2_resnest50_380x380', 'mealv2_mobilenetv3_small_075', 'mealv2_mobilenetv3_small_100', 'mealv2_mobilenet_v3_large_100', 'mealv2_efficientnet_b0' -# load pretrained models, using "mealv2_resnest50_cutmix" as an example +# 모델 종류: 'mealv1_resnest50', 'mealv2_resnest50', 'mealv2_resnest50_cutmix', 'mealv2_resnest50_380x380', 'mealv2_mobilenetv3_small_075', 'mealv2_mobilenetv3_small_100', 'mealv2_mobilenet_v3_large_100', 'mealv2_efficientnet_b0' +# 사전에 학습된 "mealv2_resnest50_cutmix"을 로딩하는 예시입니다. model = torch.hub.load('szq0214/MEAL-V2','meal_v2', 'mealv2_resnest50_cutmix', pretrained=True) model.eval() ``` -All pre-trained models expect input images normalized in the same way, -i.e. mini-batches of 3-channel RGB images of shape `(3 x H x W)`, where `H` and `W` are expected to be at least `224`. -The images have to be loaded in to a range of `[0, 1]` and then normalized using `mean = [0.485, 0.456, 0.406]` -and `std = [0.229, 0.224, 0.225]`. +사전에 학습된 모든 모델은 동일한 방식으로 정규화된 입력 이미지, 즉, `H` 와 `W` 는 최소 `224` 이상인 `(3 x H x W)` 형태의 3-채널 RGB 이미지의 미니 배치를 요구합니다. 이미지를 `[0, 1]` 범위에서 로드한 다음 `mean = [0.485, 0.456, 0.406]` 과 `std = [0.229, 0.224, 0.225]` 를 통해 정규화합니다. -Here's a sample execution. +실행 예시입니다. ```python -# Download an example image from the pytorch website +# 파이토치 웹사이트에서 예제 이미지 다운로드 import urllib url, filename = ("https://github.com/pytorch/hub/raw/master/images/dog.jpg", "dog.jpg") try: urllib.URLopener().retrieve(url, filename) @@ -47,7 +44,7 @@ except: urllib.request.urlretrieve(url, filename) ``` ```python -# sample execution (requires torchvision) +# 실행 예시 (torchvision 필요) from PIL import Image from torchvision import transforms input_image = Image.open(filename) @@ -58,32 +55,32 @@ preprocess = transforms.Compose([ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), ]) input_tensor = preprocess(input_image) -input_batch = input_tensor.unsqueeze(0) # create a mini-batch as expected by the model +input_batch = input_tensor.unsqueeze(0) # 모델에서 요구하는 미니배치 생성 -# move the input and model to GPU for speed if available +# 가능하다면 속도를 위해 입력과 모델을 GPU로 옮깁니다. if torch.cuda.is_available(): input_batch = input_batch.to('cuda') model.to('cuda') with torch.no_grad(): output = model(input_batch) -# Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes +# shape이 1000이며 ImageNet의 1000개 클래스에 대한 신뢰도 점수(confidence score)가 있는 Tensor print(output[0]) -# The output has unnormalized scores. To get probabilities, you can run a softmax on it. +# output엔 정규화되지 않은 신뢰도 점수가 있습니다. 확률 값을 얻으려면 소프트맥스를 실행하세요. probabilities = torch.nn.functional.softmax(output[0], dim=0) print(probabilities) ``` ``` -# Download ImageNet labels +# ImageNet 레이블 다운로드 !wget https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt ``` ``` -# Read the categories +# 카테고리 읽기 with open("imagenet_classes.txt", "r") as f: categories = [s.strip() for s in f.readlines()] -# Show top categories per image +# 이미지별 Top5 카테고리 조회 top5_prob, top5_catid = torch.topk(probabilities, 5) for i in range(top5_prob.size(0)): print(categories[top5_catid[i]], top5_prob[i].item()) From 410e8cd5eb5add99f006b6e332d48464871f2574 Mon Sep 17 00:00:00 2001 From: woodywarhol9 Date: Wed, 27 Jul 2022 13:37:27 +0900 Subject: [PATCH 2/2] =?UTF-8?q?pytorch=5Fvision=5Fmeal=5Fv2.md=20=ED=94=BC?= =?UTF-8?q?=EB=93=9C=EB=B0=B1=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pytorch_vision_meal_v2.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pytorch_vision_meal_v2.md b/pytorch_vision_meal_v2.md index c5eb047..79bb1b2 100644 --- a/pytorch_vision_meal_v2.md +++ b/pytorch_vision_meal_v2.md @@ -17,7 +17,7 @@ order: 10 demo-model-link: https://huggingface.co/spaces/pytorch/MEAL-V2 --- -추가로 1개의 파이썬 패키지를 설치해야 합니다. +`timm` 종속 패키지 설치가 필요합니다. ```bash !pip install timm @@ -26,12 +26,12 @@ demo-model-link: https://huggingface.co/spaces/pytorch/MEAL-V2 ```python import torch # 모델 종류: 'mealv1_resnest50', 'mealv2_resnest50', 'mealv2_resnest50_cutmix', 'mealv2_resnest50_380x380', 'mealv2_mobilenetv3_small_075', 'mealv2_mobilenetv3_small_100', 'mealv2_mobilenet_v3_large_100', 'mealv2_efficientnet_b0' -# 사전에 학습된 "mealv2_resnest50_cutmix"을 로딩하는 예시입니다. +# 사전에 학습된 "mealv2_resnest50_cutmix"을 불러오는 예시입니다. model = torch.hub.load('szq0214/MEAL-V2','meal_v2', 'mealv2_resnest50_cutmix', pretrained=True) model.eval() ``` -사전에 학습된 모든 모델은 동일한 방식으로 정규화된 입력 이미지, 즉, `H` 와 `W` 는 최소 `224` 이상인 `(3 x H x W)` 형태의 3-채널 RGB 이미지의 미니 배치를 요구합니다. 이미지를 `[0, 1]` 범위에서 로드한 다음 `mean = [0.485, 0.456, 0.406]` 과 `std = [0.229, 0.224, 0.225]` 를 통해 정규화합니다. +사전에 학습된 모든 모델은 동일한 방식으로 정규화된 입력 이미지, 즉, `H` 와 `W` 는 최소 `224` 이상인 `(3 x H x W)` 형태의 3-채널 RGB 이미지의 미니 배치를 요구합니다. 이미지를 `[0, 1]` 범위에서 불러온 다음 `mean = [0.485, 0.456, 0.406]` 과 `std = [0.229, 0.224, 0.225]` 를 통해 정규화합니다. 실행 예시입니다. @@ -64,9 +64,9 @@ if torch.cuda.is_available(): with torch.no_grad(): output = model(input_batch) -# shape이 1000이며 ImageNet의 1000개 클래스에 대한 신뢰도 점수(confidence score)가 있는 Tensor +# 1000개의 ImageNet 클래스에 대한 신뢰도 점수(confidence score)를 가진 1000 크기의 Tensor print(output[0]) -# output엔 정규화되지 않은 신뢰도 점수가 있습니다. 확률 값을 얻으려면 소프트맥스를 실행하세요. +# output엔 정규화되지 않은 신뢰도 점수가 있습니다. 확률 값을 얻으려면 softmax를 실행하세요. probabilities = torch.nn.functional.softmax(output[0], dim=0) print(probabilities) ```