半監督和半弱監督 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 影像組成的小批次資料,其中 HW 預計至少為 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 億張公共影像上進行預訓練,這些影像帶有 1.5K 標籤,與 1000 個 ImageNet1K 同義詞集匹配,然後對 ImageNet1K 資料集進行微調。在這種情況下,相關的標籤僅用於構建更好的教師模型。在訓練學生模型期間,這些標籤被忽略,學生模型使用教師模型從相同的 9.4 億張公共影像資料集中選擇的 6400 萬張影像子集進行預訓練。

下表提供的半弱監督 ResNet 和 ResNext 模型與從頭開始訓練或截至 2019 年 9 月文獻中介紹的其他訓練機制相比,顯著提高了 ImageNet 驗證集上的 top-1 準確率。例如,我們為廣泛使用/採用的 ResNet-50 模型架構實現了 81.2% 的 ImageNet 最新準確率

架構監督方式#引數浮點運算次數 (FLOPS)Top-1 準確率Top-5 準確率
ResNet-18半監督1400 萬2B72.891.5
ResNet-50半監督2500 萬40 億79.394.9
ResNeXt-50 32x4d半監督2500 萬40 億80.395.4
ResNeXt-101 32x4d半監督4200 萬8K81.095.7
ResNeXt-101 32x8d半監督88M16B81.796.1
ResNeXt-101 32x16d半監督193M36B81.996.2
ResNet-18半弱監督1400 萬2B73.491.9
ResNet-50半弱監督2500 萬40 億81.296.0
ResNeXt-50 32x4d半弱監督2500 萬40 億82.296.3
ResNeXt-101 32x4d半弱監督4200 萬8K83.496.8
ResNeXt-101 32x8d半弱監督88M16B84.397.2
ResNeXt-101 32x16d半弱監督193M36B84.897.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}
}

在“Billion scale semi-supervised learning for image classification”論文中介紹的 ResNet 和 ResNext 模型

模型型別: 視覺
提交者: Facebook AI