| layout | hub_detail | |
|---|---|---|
| background-class | hub-background | |
| body-class | hub | |
| title | IBN-Net | |
| summary | Networks with domain/appearance invariance | |
| category | researchers | |
| image | ibnnet.png | |
| author | Xingang Pan | |
| tags |
|
|
| github-link | https://github.com/XingangPan/IBN-Net | |
| github-id | XingangPan/IBN-Net | |
| featured_image_1 | ibnnet.png | |
| featured_image_2 | no-image | |
| accelerator | cuda-optional | |
| order | 10 | |
| demo-model-link | https://huggingface.co/spaces/pytorch/IBN-Net |
import torch
model = torch.hub.load('XingangPan/IBN-Net', 'resnet50_ibn_a', 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 ์ฌ์ฉ์ด ๊ฐ๋ฅํ ๊ฒฝ์ฐ ์๋๋ฅผ ์ํด ์
๋ ฅ๊ณผ ๋ชจ๋ธ์ GPU๋ก ์ด๋
if torch.cuda.is_available():
input_batch = input_batch.to('cuda')
model.to('cuda')
with torch.no_grad():
output = model(input_batch)
# ImageNet์ 1000๊ฐ ํด๋์ค์ ๋ํ ์ ๋ขฐ๋ ์ ์๋ฅผ ๊ฐ์ง 1000 ํํ์ Tensor ์ถ๋ ฅ
print(output[0])
# ์ถ๋ ฅ์ ์ ๊ทํ๋์ด์์ง ์์ต๋๋ค. ์ํํธ๋งฅ์ค๋ฅผ ์คํํ์ฌ ํ๋ฅ ์ ์ป์ ์ ์์ต๋๋ค.
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()]
# ์ด๋ฏธ์ง๋ง๋ค ์์ ์นดํ
๊ณ ๋ฆฌ 5๊ฐ ๋ณด์ฌ์ฃผ๊ธฐ
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())
IBN-Net์ ๋๋ฉ์ธ/์ธ๊ด ๋ถ๋ณ์ฑ์ ๊ฐ๋ CNN ๋ชจ๋ธ์ ๋๋ค. Style transfer์ ์๊ฐ์ ์ป์ด IBN-Net์ ๋จ์ผ ์ฌ์ธต ๋คํธ์ํฌ์์ ์ธ์คํด์ค ์ ๊ทํ์ ์ผ๊ด ์ ๊ทํ๋ฅผ ์ ์คํ๊ฒ ํตํฉํฉ๋๋ค. ๋ชจ๋ธ ๋ณต์ก์ฑ์ ์ถ๊ฐํ์ง ์๊ณ ๋ชจ๋ธ๋ง ๋ฐ ๋ฒ์ฉ์ฑ์ ๋ชจ๋ ์ฆ๊ฐ์ํค๋ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ ์ ๊ณตํฉ๋๋ค. IBN-Net์ ํนํ ๊ต์ฐจ ๋๋ฉ์ธ ๋๋ ์ฌ๋/์ฐจ๋ ์ฌ์๋ณ ์์ ์ ์ ํฉํฉ๋๋ค.
ImageNet ๋ฐ์ดํฐ์ ์ ์ฌ์ฉํ์ ๋ ์ฌ์ ํ๋ จ๋ ๋ชจ๋ธ๋ค์ ์ ํ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
| Model name | Top-1 acc | Top-5 acc |
|---|---|---|
| resnet50_ibn_a | 77.46 | 93.68 |
| resnet101_ibn_a | 78.61 | 94.41 |
| resnext101_ibn_a | 79.12 | 94.58 |
| se_resnet101_ibn_a | 78.75 | 94.49 |
๋ ๊ฐ์ง Re-ID ๋ฒค์น๋งํฌ Market1501 ๋ฐ DukeMTMC-reID์ ๋ํ rank1/mAP๋ ์๋์ ๋์ด๋์ด ์์ต๋๋ค.(michuanhaohao/reid-strong-baseline์์ ๊ฐ์ ธ์์ต๋๋ค.)
| Backbone | Market1501 | DukeMTMC-reID |
|---|---|---|
| ResNet50 | 94.5 (85.9) | 86.4 (76.4) |
| ResNet101 | 94.5 (87.1) | 87.6 (77.6) |
| SeResNet50 | 94.4 (86.3) | 86.4 (76.5) |
| SeResNet101 | 94.6 (87.3) | 87.5 (78.0) |
| SeResNeXt50 | 94.9 (87.6) | 88.0 (78.3) |
| SeResNeXt101 | 95.0 (88.0) | 88.4 (79.0) |
| ResNet50-IBN-a | 95.0 (88.2) | 90.1 (79.1) |