最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2021年09月07日 12:03:14   作者:xz1308579340  
本文是關(guān)于Pytorch教程文章,本篇主要為教大家Pytorch內(nèi)置模型源碼實(shí)現(xiàn),有需要的朋友可以借鑒參考下,希望可以有所幫助,祝大家多多進(jìn)步,早日升職加薪

翻譯自
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 ,通過讓參數(shù)pretrained =True來構(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ǔ)路徑可以通過環(huán)境變量TORCH_MODEL_ZOO來指定,詳細(xì)的參考torch.utils.model_zoo.load_url() 這個(gè)函數(shù)

有的模型試驗(yàn)了不同的訓(xùn)練和評(píng)估,例如batch normalization。使用model.train()和model.eval()來轉(zhuǎn)換,查看train() or eval() 來了解更多細(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)換來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)文章!

相關(guān)文章

  • python使用正則表達(dá)式匹配反斜杠\遇到的問題

    python使用正則表達(dá)式匹配反斜杠\遇到的問題

    在學(xué)習(xí)Python正則式的過程中,有一個(gè)問題一直困擾我,如何去匹配一個(gè)反斜杠(即“\”),下面這篇文章主要給大家介紹了關(guān)于python使用正則表達(dá)式匹配反斜杠\的相關(guān)資料,需要的朋友可以參考下
    2022-09-09
  • 淺述python中深淺拷貝原理

    淺述python中深淺拷貝原理

    Python中,對(duì)象的賦值,拷貝(深/淺拷貝)之間是有差異的,如果使用的時(shí)候不注意,就可能產(chǎn)生意外的結(jié)果,其實(shí)這個(gè)是由于共享內(nèi)存導(dǎo)致的結(jié)果,下面我們來簡(jiǎn)單談下Python中的深拷貝和淺拷貝。
    2018-09-09
  • Python機(jī)器學(xué)習(xí)pytorch交叉熵?fù)p失函數(shù)的深刻理解

    Python機(jī)器學(xué)習(xí)pytorch交叉熵?fù)p失函數(shù)的深刻理解

    這篇文章主要為大家介紹了Python機(jī)器學(xué)習(xí)中對(duì)交叉熵?fù)p失函數(shù)的深刻理解,文中作出了詳細(xì)易懂的講解,有需要的朋友可以借鑒參考下希望能夠有所幫助
    2021-10-10
  • 詳解pygame捕獲鍵盤事件的兩種方式

    詳解pygame捕獲鍵盤事件的兩種方式

    這篇文章主要介紹了詳解pygame捕獲鍵盤事件的兩種方式,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • Python中初始化一個(gè)二維數(shù)組及注意事項(xiàng)說明

    Python中初始化一個(gè)二維數(shù)組及注意事項(xiàng)說明

    這篇文章主要介紹了Python中初始化一個(gè)二維數(shù)組及注意事項(xiàng)說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • Python實(shí)現(xiàn)日期判斷和加減操作詳解

    Python實(shí)現(xiàn)日期判斷和加減操作詳解

    這篇文章主要介紹了如何利用Python實(shí)現(xiàn)日期的判斷,以及對(duì)日期的加減操作,文中的示例代碼對(duì)我們學(xué)習(xí)或工作有一定的價(jià)值,需要的可以參考一下
    2022-01-01
  • 利用python實(shí)時(shí)刷新基金估值效果(摸魚小工具)

    利用python實(shí)時(shí)刷新基金估值效果(摸魚小工具)

    這篇文章主要介紹了利用python實(shí)時(shí)刷新基金估值(摸魚小工具),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-09-09
  • 使用Python實(shí)現(xiàn)合并多個(gè)Excel文件

    使用Python實(shí)現(xiàn)合并多個(gè)Excel文件

    合并Excel可以將多個(gè)文件中的數(shù)據(jù)合并到一個(gè)文件中,這樣可以幫助我們更好地匯總和管理數(shù)據(jù),本文主要介紹了如何使用第三方Python庫(kù) Spire.XLS for Python 實(shí)現(xiàn)以上兩種合并Excel文件的需求,有需要的可以了解下
    2023-12-12
  • python爬蟲之PySpider框架的使用

    python爬蟲之PySpider框架的使用

    本文主要介紹了python爬蟲之PySpider框架的使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • Python字典的概念及常見應(yīng)用實(shí)例詳解

    Python字典的概念及常見應(yīng)用實(shí)例詳解

    這篇文章主要介紹了Python字典的概念及常見應(yīng)用,結(jié)合實(shí)例形式詳細(xì)的分析了Python字典的概念、原理、創(chuàng)建、常見操作函數(shù)與使用注意事項(xiàng),需要的朋友可以參考下
    2019-10-10

最新評(píng)論

玉环县| 华阴市| 金平| 沧州市| 岐山县| 武隆县| 左贡县| 乌兰察布市| 文化| 资中县| 峡江县| 奉化市| 五指山市| 房产| 桃园县| 商河县| 河北区| 阿拉尔市| 河津市| 腾冲县| 抚松县| 马关县| 福清市| 钟祥市| 临江市| 克东县| 临澧县| 吐鲁番市| 如东县| 巢湖市| 成武县| 福建省| 新郑市| 横峰县| 莎车县| 乌拉特后旗| 繁昌县| 资溪县| 铜川市| 开远市| 邵武市|