SE-ResNeXt101


模型描述
SE-ResNeXt101-32x4d 是一個ResNeXt101-32x4d模型,其中添加了在Squeeze-and-Excitation Networks論文中介紹的Squeeze-and-Excitation模組。
該模型在Volta、Turing和NVIDIA Ampere GPU架構上使用Tensor Cores進行混合精度訓練。因此,研究人員可以獲得比不使用Tensor Cores訓練快3倍的結果,同時體驗混合精度訓練的優勢。該模型針對每個NGC月度容器版本進行測試,以確保隨著時間的推移保持一致的準確性和效能。
在使用混合精度進行訓練時,我們使用 NHWC 資料佈局。
模型架構

圖片來源:Squeeze-and-Excitation Networks
圖片展示了SE模組的架構及其在ResNet瓶頸模組中的位置。
請注意,SE-ResNeXt101-32x4d模型可以使用TorchScript、ONNX Runtime或TensorRT作為執行後端,部署到NVIDIA Triton 推理伺服器進行推理。有關詳細資訊,請檢視NGC。
示例
在下面的示例中,我們將使用預訓練的SE-ResNeXt101-32x4d模型對影像執行推理並呈現結果。
要執行此示例,您需要安裝一些額外的 Python 包。這些包用於影像預處理和視覺化。
!pip install validators matplotlib
import torch
from PIL import Image
import torchvision.transforms as transforms
import numpy as np
import json
import requests
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
print(f'Using {device} for inference')
載入在 ImageNet 資料集上預訓練的模型。
resneXt = torch.hub.load('NVIDIA/DeepLearningExamples:torchhub', 'nvidia_se_resnext101_32x4d')
utils = torch.hub.load('NVIDIA/DeepLearningExamples:torchhub', 'nvidia_convnets_processing_utils')
resneXt.eval().to(device)
準備示例輸入資料。
uris = [
'http://images.cocodataset.org/test-stuff2017/000000024309.jpg',
'http://images.cocodataset.org/test-stuff2017/000000028117.jpg',
'http://images.cocodataset.org/test-stuff2017/000000006149.jpg',
'http://images.cocodataset.org/test-stuff2017/000000004954.jpg',
]
batch = torch.cat(
[utils.prepare_input_from_uri(uri) for uri in uris]
).to(device)
執行推理。使用輔助函式pick_n_best(predictions=output, n=topN)根據模型選擇N個最可能的假設。
with torch.no_grad():
output = torch.nn.functional.softmax(resneXt(batch), dim=1)
results = utils.pick_n_best(predictions=output, n=5)
顯示結果。
for uri, result in zip(uris, results):
img = Image.open(requests.get(uri, stream=True).raw)
img.thumbnail((256,256), Image.ANTIALIAS)
plt.imshow(img)
plt.show()
print(result)
詳情
有關模型輸入和輸出、訓練方法、推理和效能的詳細資訊,請訪問:github和/或NGC。
參考文獻