半監督和半弱監督 ImageNet 模型

import torch
# === SEMI-WEAKLY SUPERVISED MODELS PRETRAINED WITH 940 HASHTAGGED PUBLIC CONTENT ===
model = torch.hub.load('facebookresearch/semi-supervised-ImageNet1K-models', 'resnet18_swsl')
# model = torch.hub.load('facebookresearch/semi-supervised-ImageNet1K-models', 'resnet50_swsl')
# model = torch.hub.load('facebookresearch/semi-supervised-ImageNet1K-models', 'resnext50_32x4d_swsl')
# model = torch.hub.load('facebookresearch/semi-supervised-ImageNet1K-models', 'resnext101_32x4d_swsl')
# model = torch.hub.load('facebookresearch/semi-supervised-ImageNet1K-models', 'resnext101_32x8d_swsl')
# model = torch.hub.load('facebookresearch/semi-supervised-ImageNet1K-models', 'resnext101_32x16d_swsl')
# ================= SEMI-SUPERVISED MODELS PRETRAINED WITH YFCC100M ==================
# model = torch.hub.load('facebookresearch/semi-supervised-ImageNet1K-models', 'resnet18_ssl')
# model = torch.hub.load('facebookresearch/semi-supervised-ImageNet1K-models', 'resnet50_ssl')
# model = torch.hub.load('facebookresearch/semi-supervised-ImageNet1K-models', 'resnext50_32x4d_ssl')
# model = torch.hub.load('facebookresearch/semi-supervised-ImageNet1K-models', 'resnext101_32x4d_ssl')
# model = torch.hub.load('facebookresearch/semi-supervised-ImageNet1K-models', 'resnext101_32x8d_ssl')
# model = torch.hub.load('facebookresearch/semi-supervised-ImageNet1K-models', 'resnext101_32x16d_ssl')
model.eval()
所有預訓練模型都要求輸入影像以相同的方式進行歸一化,即由形狀為 (3 x H x W) 的 3 通道 RGB 影像組成的小批次資料,其中 H 和 W 預計至少為 224。影像必須載入到 [0, 1] 範圍內,然後使用 mean = [0.485, 0.456, 0.406] 和 std = [0.229, 0.224, 0.225] 進行歸一化。
這是一個示例執行。
# 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)
except: urllib.request.urlretrieve(url, filename)
# sample execution (requires 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) # create a mini-batch as expected by the model
# move the input and model to GPU for speed if available
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
print(output[0])
# The output has unnormalized scores. To get probabilities, you can run a softmax on it.
print(torch.nn.functional.softmax(output[0], dim=0))
模型描述
本專案包含“十億級半監督影像分類學習”https://arxiv.org/abs/1905.00546中介紹的半監督和半弱監督 ImageNet 模型。
“半監督”(SSL)ImageNet 模型在無標籤的 YFCC100M 公共影像資料集子集上進行預訓練,並使用 ImageNet1K 訓練資料集進行微調,如上述論文中的半監督訓練框架所述。在這種情況下,高容量教師模型僅使用有標籤的樣本進行訓練。
“半弱監督”(SWSL)ImageNet 模型在包含 9.4 億公共影像的資料集上進行預訓練,這些影像帶有與 1000 個 ImageNet1K 同義詞集匹配的 1.5K 標籤,隨後在 ImageNet1K 資料集上進行微調。在這種情況下,相關的標籤僅用於構建一個更好的教師模型。在訓練學生模型時,這些標籤被忽略,學生模型使用教師模型從相同的 9.4 億公共影像資料集中選擇的 64M 影像子集進行預訓練。
下表提供的半弱監督 ResNet 和 ResNext 模型與從頭開始訓練或截至 2019 年 9 月文獻中介紹的其他訓練機制相比,顯著提高了 ImageNet 驗證集上的 top-1 準確率。例如,我們為廣泛使用/採用的 ResNet-50 模型架構在 ImageNet 上實現了 81.2% 的最先進準確率。
| 架構 | 監督方式 | #引數 | 浮點運算次數 (FLOPS) | Top-1 準確率 | Top-5 準確率 |
|---|---|---|---|---|---|
| ResNet-18 | 半監督 | 14M | 2B | 72.8 | 91.5 |
| ResNet-50 | 半監督 | 25M | 4B | 79.3 | 94.9 |
| ResNeXt-50 32x4d | 半監督 | 25M | 4B | 80.3 | 95.4 |
| ResNeXt-101 32x4d | 半監督 | 42M | 8K | 81.0 | 95.7 |
| ResNeXt-101 32x8d | 半監督 | 88M | 16B | 81.7 | 96.1 |
| ResNeXt-101 32x16d | 半監督 | 193M | 36B | 81.9 | 96.2 |
| ResNet-18 | 半弱監督 | 14M | 2B | 73.4 | 91.9 |
| ResNet-50 | 半弱監督 | 25M | 4B | 81.2 | 96.0 |
| ResNeXt-50 32x4d | 半弱監督 | 25M | 4B | 82.2 | 96.3 |
| ResNeXt-101 32x4d | 半弱監督 | 42M | 8K | 83.4 | 96.8 |
| ResNeXt-101 32x8d | 半弱監督 | 88M | 16B | 84.3 | 97.2 |
| ResNeXt-101 32x16d | 半弱監督 | 193M | 36B | 84.8 | 97.4 |
引用
如果您使用本倉庫中釋出的模型,請引用以下出版物 (https://arxiv.org/abs/1905.00546)。
@misc{yalniz2019billionscale,
title={Billion-scale semi-supervised learning for image classification},
author={I. Zeki Yalniz and Hervé Jégou and Kan Chen and Manohar Paluri and Dhruv Mahajan},
year={2019},
eprint={1905.00546},
archivePrefix={arXiv},
primaryClass={cs.CV}
}