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 |
MEAL_V2 |
Boosting Tiny and Efficient Models using Knowledge Distillation. |
researchers |
MEALV2.png |
Carnegie Mellon University |
|
szq0214/MEAL-V2 |
MEALV2_method.png |
MEALV2_results.png |
cuda |
10 |
timm
์ข
์ ํจํค์ง ์ค์น๊ฐ ํ์ํฉ๋๋ค.
!pip install timm
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"์ ๋ถ๋ฌ์ค๋ ์์์
๋๋ค.
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]
๋ฅผ ํตํด ์ ๊ทํํฉ๋๋ค.
์คํ ์์์ ๋๋ค.
# ํ์ดํ ์น ์น์ฌ์ดํธ์์ ์์ ์ด๋ฏธ์ง ๋ค์ด๋ก๋
import urllib
url, filename = ("https://github.com/pytorch/hub/raw/master/images/dog.jpg", "dog.jpg")
try: urllib.URLopener().retrieve(url, filename)
except: urllib.request.urlretrieve(url, filename)
# ์คํ ์์ (torchvision ํ์)
from PIL import Image
from torchvision import transforms
input_image = Image.open(filename)
preprocess = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
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) # ๋ชจ๋ธ์์ ์๊ตฌํ๋ ๋ฏธ๋๋ฐฐ์น ์์ฑ
# ๊ฐ๋ฅํ๋ค๋ฉด ์๋๋ฅผ ์ํด ์
๋ ฅ๊ณผ ๋ชจ๋ธ์ GPU๋ก ์ฎ๊น๋๋ค.
if torch.cuda.is_available():
input_batch = input_batch.to('cuda')
model.to('cuda')
with torch.no_grad():
output = model(input_batch)
# 1000๊ฐ์ ImageNet ํด๋์ค์ ๋ํ ์ ๋ขฐ๋ ์ ์(confidence score)๋ฅผ ๊ฐ์ง 1000 ํฌ๊ธฐ์ Tensor
print(output[0])
# output์ ์ ๊ทํ๋์ง ์์ ์ ๋ขฐ๋ ์ ์๊ฐ ์์ต๋๋ค. ํ๋ฅ ๊ฐ์ ์ป์ผ๋ ค๋ฉด softmax๋ฅผ ์คํํ์ธ์.
probabilities = torch.nn.functional.softmax(output[0], dim=0)
print(probabilities)
# ImageNet ๋ ์ด๋ธ ๋ค์ด๋ก๋
!wget https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt
# ์นดํ
๊ณ ๋ฆฌ ์ฝ๊ธฐ
with open("imagenet_classes.txt", "r") as f:
categories = [s.strip() for s in f.readlines()]
# ์ด๋ฏธ์ง๋ณ 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())
MEAL V2 ๋ชจ๋ธ๋ค์ MEAL V2: Boosting Vanilla ResNet-50 to 80%+ Top-1 Accuracy on ImageNet without Tricks ๋ ผ๋ฌธ์ ๊ธฐ๋ฐํฉ๋๋ค.
MEAL V2์ ์ฃผ์ ๊ด์ ์ distillation ๊ณผ์ ์ One-Hot ๋ ์ด๋ธ์ ์ฌ์ฉํ์ง ์๋๋ค๋ ๊ฒ์ ๋๋ค. MEAL V2๋ ํ๋ณ์๋ฅผ ์ด์ฉํ knowledge distillation ์์๋ธ ๊ธฐ๋ฒ์ธ MEAL์ ๊ธฐ์ดํ๋ฉฐ, MEAL์ ๋จ์ํํ๊ธฐ ์ํด ๋ค์์ ์์ ์ ๊ฑฐ์ณค์ต๋๋ค. 1) ํ๋ณ์ ์ ๋ ฅ, ์ ์ฌ๋ ์์ค ๊ณ์ฐ์ ์ต์ข ์ถ๋ ฅ๋ง์ ํ์ฉํฉ๋๋ค. 2) ๋ชจ๋ teacher๋ค์ ์์ธก ํ๋ฅ ์ ํ๊ท ๋ด์ด distillation์ ํ์ฉํฉ๋๋ค. ์ด๋ฅผ ํตํด MEAL V2๋ ์ด๋ ํ ํธ๋ฆญ ์ฌ์ฉ ์์ด๋ ResNet-50์ ImageNet Top-1 ์ ํ๋๋ฅผ 80% ์ด์ ๊ธฐ๋กํ ์ ์์ต๋๋ค. (ํธ๋ฆญ : 1) ๋ชจ๋ธ ๊ตฌ์กฐ ๋ณ๊ฒฝ; 2) ImageNet ์ธ ์ถ๊ฐ ๋ฐ์ดํฐ ํ์ฉ; 3) autoaug/randaug; 4) cosine learning rate; 5) mixup/cutmix; 6) label smoothing; etc)
| Models | Resolution| #Parameters | Top-1/Top-5 | | :---: | :-: | :-: | :------:| :------: | | MEAL-V1 w/ ResNet50 | 224 | 25.6M |78.21/94.01 | GitHub | | MEAL-V2 w/ ResNet50 | 224 | 25.6M | 80.67/95.09 | | MEAL-V2 w/ ResNet50| 380 | 25.6M | 81.72/95.81 | | MEAL-V2 + CutMix w/ ResNet50| 224 | 25.6M | 80.98/95.35 | | MEAL-V2 w/ MobileNet V3-Small 0.75| 224 | 2.04M | 67.60/87.23 | | MEAL-V2 w/ MobileNet V3-Small 1.0| 224 | 2.54M | 69.65/88.71 | | MEAL-V2 w/ MobileNet V3-Large 1.0 | 224 | 5.48M | 76.92/93.32 | | MEAL-V2 w/ EfficientNet-B0| 224 | 5.29M | 78.29/93.95 |
์์ธํ ์ฌํญ์ MEAL V2, MEAL์ ํตํด ํ์ธํ ์ ์์ต๋๋ค.
@article{shen2020mealv2,
title={MEAL V2: Boosting Vanilla ResNet-50 to 80%+ Top-1 Accuracy on ImageNet without Tricks},
author={Shen, Zhiqiang and Savvides, Marios},
journal={arXiv preprint arXiv:2009.08453},
year={2020}
}
@inproceedings{shen2019MEAL,
title = {MEAL: Multi-Model Ensemble via Adversarial Learning},
author = {Shen, Zhiqiang and He, Zhankui and Xue, Xiangyang},
booktitle = {AAAI},
year = {2019}
}