佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > Pytorch教程內(nèi)置模型源碼實(shí)現(xiàn)

Pytorch教程內(nèi)置模型源碼實(shí)現(xiàn)

熱門(mén)標(biāo)簽:智能手機(jī) 呼叫中心市場(chǎng)需求 銀行業(yè)務(wù) 檢查注冊(cè)表項(xiàng) 服務(wù)器配置 美圖手機(jī) 鐵路電話系統(tǒng) 網(wǎng)站文章發(fā)布

翻譯自
https://pytorch.org/docs/stable/torchvision/models.html
主要講解了torchvision.models的使用

torchvision.models

torchvision.models中包含了如下模型

  • AlexNet
  • VGG
  • ResNet
  • SqueezeNet
  • DenseNet
  • Inception v3

隨機(jī)初始化模型

import torchvision.models as models
resnet18 = models.resnet18()
alexnet = models.alexnet()
vgg16 = models.vgg16()
squeezenet = models.squeezenet1_0()
desnet = models.densenet161()
inception =models.inception_v3()

使用預(yù)訓(xùn)練好的參數(shù)

pytorch提供了預(yù)訓(xùn)練的模型,使用torch.utils.model_zoo ,通過(guò)讓參數(shù)pretrained =True來(lái)構(gòu)建訓(xùn)練好的模型

方法如下

resnet18 = models.resnet18(pretrained=True)
alexnet = models.alexnet(pretrained=True)
squeezenet = models.squeezenet1_0(pretrained=True)
vgg16 = models.vgg16(pretrained=True)
densenet = models.densenet161(pretrained=True)
inception = models.inception_v3(pretrained=True)

實(shí)例化一個(gè)預(yù)訓(xùn)練好的模型會(huì)自動(dòng)下載權(quán)重到緩存目錄,這個(gè)權(quán)重存儲(chǔ)路徑可以通過(guò)環(huán)境變量TORCH_MODEL_ZOO來(lái)指定,詳細(xì)的參考torch.utils.model_zoo.load_url() 這個(gè)函數(shù)

有的模型試驗(yàn)了不同的訓(xùn)練和評(píng)估,例如batch normalization。使用model.train()和model.eval()來(lái)轉(zhuǎn)換,查看train() or eval() 來(lái)了解更多細(xì)節(jié)

所有的預(yù)訓(xùn)練網(wǎng)絡(luò)希望使用相同的方式進(jìn)行歸一化,例如圖片是mini-batch形式的3通道RGB圖片(3HW),H和W最少是244,。 圖像必須加載到[0,1]范圍內(nèi),然后使用均值=[0.485,0.456,0.406]和std =[0.229, 0.224, 0.225]進(jìn)行歸一化。

您可以使用以下轉(zhuǎn)換來(lái)normalzie:

normalize = trainform.Normalize9mean = [0.485,0.456,0.406],std = [0.229,0.224,0.225])

在這里我們可以找到一個(gè)在Imagenet上的這樣的例子
https://github.com/pytorch/examples/blob/42e5b996718797e45c46a25c55b031e6768f8440/imagenet/main.py#L89-L101

目前這些模型的效果如下

下面是模型源碼的具體實(shí)現(xiàn),具體實(shí)現(xiàn)大家可以閱讀源碼

###ALEXNET
torchvision.models.alexnet(pretrained=False, **kwargs)[SOURCE]
AlexNet model architecture from the “One weird trick…” paper.
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
###VGG
torchvision.models.vgg11(pretrained=False, **kwargs)[SOURCE]
VGG 11-layer model (configuration “A”)
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.vgg11_bn(pretrained=False, **kwargs)[SOURCE]
VGG 11-layer model (configuration “A”) with batch normalization
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.vgg13(pretrained=False, **kwargs)[SOURCE]
VGG 13-layer model (configuration “B”)
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.vgg13_bn(pretrained=False, **kwargs)[SOURCE]
VGG 13-layer model (configuration “B”) with batch normalization
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.vgg16(pretrained=False, **kwargs)[SOURCE]
VGG 16-layer model (configuration “D”)
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.vgg16_bn(pretrained=False, **kwargs)[SOURCE]
VGG 16-layer model (configuration “D”) with batch normalization
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.vgg19(pretrained=False, **kwargs)[SOURCE]
VGG 19-layer model (configuration “E”)
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.vgg19_bn(pretrained=False, **kwargs)[SOURCE]
VGG 19-layer model (configuration ‘E') with batch normalization
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
RESNET
torchvision.models.resnet18(pretrained=False, **kwargs)[SOURCE]
Constructs a ResNet-18 model.
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.resnet34(pretrained=False, **kwargs)[SOURCE]
Constructs a ResNet-34 model.
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.resnet50(pretrained=False, **kwargs)[SOURCE]
Constructs a ResNet-50 model.
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.resnet101(pretrained=False, **kwargs)[SOURCE]
Constructs a ResNet-101 model.
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.resnet152(pretrained=False, **kwargs)[SOURCE]
Constructs a ResNet-152 model.
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
SQUEEZENET
torchvision.models.squeezenet1_0(pretrained=False, **kwargs)[SOURCE]
SqueezeNet model architecture from the “SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and 0.5MB model size” paper.
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.squeezenet1_1(pretrained=False, **kwargs)[SOURCE]
SqueezeNet 1.1 model from the official SqueezeNet repo. SqueezeNet 1.1 has 2.4x less computation and slightly fewer parameters than SqueezeNet 1.0, without sacrificing accuracy.
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
DENSENET
torchvision.models.densenet121(pretrained=False, **kwargs)[SOURCE]
Densenet-121 model from “Densely Connected Convolutional Networks”
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.densenet169(pretrained=False, **kwargs)[SOURCE]
Densenet-169 model from “Densely Connected Convolutional Networks”
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.densenet161(pretrained=False, **kwargs)[SOURCE]
Densenet-161 model from “Densely Connected Convolutional Networks”
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
torchvision.models.densenet201(pretrained=False, **kwargs)[SOURCE]
Densenet-201 model from “Densely Connected Convolutional Networks”
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet
INCEPTION V3
torchvision.models.inception_v3(pretrained=False, **kwargs)[SOURCE]
Inception v3 model architecture from “Rethinking the Inception Architecture for Computer Vision”.
Parameters:	pretrained (bool) – If True, returns a model pre-trained on ImageNet

以上就是Pytorch教程內(nèi)置模型源碼實(shí)現(xiàn)的詳細(xì)內(nèi)容,更多關(guān)于Pytorch內(nèi)置模型的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

您可能感興趣的文章:
  • pytorch教程之Tensor的值及操作使用學(xué)習(xí)
  • 使用Pytorch搭建模型的步驟
  • 如何使用Pytorch搭建模型
  • pytorch構(gòu)建網(wǎng)絡(luò)模型的4種方法

標(biāo)簽:沈陽(yáng) 上海 長(zhǎng)治 樂(lè)山 滄州 河南 紅河 新疆

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Pytorch教程內(nèi)置模型源碼實(shí)現(xiàn)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    廊坊市| 金坛市| 巫溪县| 页游| 高州市| 镶黄旗| 东安县| 镇赉县| 赣州市| 珲春市| 天门市| 绥宁县| 富顺县| 祥云县| 宜宾县| 济宁市| 大姚县| 平度市| 邓州市| 融水| 清流县| 江门市| 四会市| 民权县| 西盟| 昂仁县| 海南省| 通化县| 泰兴市| 海丰县| 卢氏县| 富源县| 江口县| 河间市| 习水县| 安塞县| 关岭| 南江县| 宁化县| 手游| 申扎县|