import torch
model = torch.hub.load('facebookresearch/WSL-Images', 'resnext101_32x8d_wsl')
# or
# model = torch.hub.load('facebookresearch/WSL-Images', 'resnext101_32x16d_wsl')
# or
# model = torch.hub.load('facebookresearch/WSL-Images', 'resnext101_32x32d_wsl')
# or
#model = torch.hub.load('facebookresearch/WSL-Images', 'resnext101_32x48d_wsl')
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))

模型说明

所提供的 ResNeXt 模型是在 9.4 亿张公共图像上以弱监督方式预训练的,这些图像带有与 1000 个 ImageNet1K synsets 匹配的 1.5K 标签,然后在 ImageNet1K 数据集上进行微调。有关模型训练的详细信息,请参阅在 ECCV 2018 上发表的论文《探索弱监督预训练的极限》(https://arxiv.org/abs/1805.00932)。

我们提供了 4 种不同容量的模型。

模型 参数 FLOPS Top-1 准确率 Top-5 准确率
ResNeXt-101 32x8d 88M 16B 82.2 96.4
ResNeXt-101 32x16d 193M 36B 84.2 97.2
ResNeXt-101 32x32d 466M 87B 85.1 97.5
ResNeXt-101 32x48d 829M 153B 85.4 97.6

与从零开始训练相比,我们的模型显著提高了在 ImageNet 上的训练准确率。使用我们的 ResNext-101 32x48d 模型,我们在 ImageNet 上达到了 85.4% 的最新(state-of-the-art)准确率

参考