PyTorch實(shí)現(xiàn)AlexNet示例
PyTorch: https://github.com/shanglianlm0525/PyTorch-Networks

import torch
import torch.nn as nn
import torchvision
class AlexNet(nn.Module):
def __init__(self,num_classes=1000):
super(AlexNet,self).__init__()
self.feature_extraction = nn.Sequential(
nn.Conv2d(in_channels=3,out_channels=96,kernel_size=11,stride=4,padding=2,bias=False),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3,stride=2,padding=0),
nn.Conv2d(in_channels=96,out_channels=192,kernel_size=5,stride=1,padding=2,bias=False),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3,stride=2,padding=0),
nn.Conv2d(in_channels=192,out_channels=384,kernel_size=3,stride=1,padding=1,bias=False),
nn.ReLU(inplace=True),
nn.Conv2d(in_channels=384,out_channels=256,kernel_size=3,stride=1,padding=1,bias=False),
nn.ReLU(inplace=True),
nn.Conv2d(in_channels=256,out_channels=256,kernel_size=3,stride=1,padding=1,bias=False),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2, padding=0),
)
self.classifier = nn.Sequential(
nn.Dropout(p=0.5),
nn.Linear(in_features=256*6*6,out_features=4096),
nn.ReLU(inplace=True),
nn.Dropout(p=0.5),
nn.Linear(in_features=4096, out_features=4096),
nn.ReLU(inplace=True),
nn.Linear(in_features=4096, out_features=num_classes),
)
def forward(self,x):
x = self.feature_extraction(x)
x = x.view(x.size(0),256*6*6)
x = self.classifier(x)
return x
if __name__ =='__main__':
# model = torchvision.models.AlexNet()
model = AlexNet()
print(model)
input = torch.randn(8,3,224,224)
out = model(input)
print(out.shape)
以上這篇PyTorch實(shí)現(xiàn)AlexNet示例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
python+opencv實(shí)現(xiàn)閾值分割
這篇文章主要為大家詳細(xì)介紹了python+opencv實(shí)現(xiàn)閾值分割的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12
Python?Flask-Login構(gòu)建強(qiáng)大的用戶認(rèn)證系統(tǒng)實(shí)例探究
這篇文章主要為大家介紹了Python?Flask-Login構(gòu)建強(qiáng)大的用戶認(rèn)證系統(tǒng)示例探究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-01-01
Python實(shí)現(xiàn)簡(jiǎn)繁體轉(zhuǎn)換
很多時(shí)候簡(jiǎn)繁體轉(zhuǎn)換,掌握了簡(jiǎn)體與繁體的轉(zhuǎn)換,往往能夠事半功倍,本文主要介紹了Python實(shí)現(xiàn)簡(jiǎn)繁體轉(zhuǎn)換,感興趣的可以了解一下2021-06-06
tensorflow 實(shí)現(xiàn)數(shù)據(jù)類型轉(zhuǎn)換
今天小編就為大家分享一篇tensorflow 實(shí)現(xiàn)數(shù)據(jù)類型轉(zhuǎn)換,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-02-02
celery實(shí)現(xiàn)動(dòng)態(tài)設(shè)置定時(shí)任務(wù)
這篇文章主要為大家詳細(xì)介紹了celery實(shí)現(xiàn)動(dòng)態(tài)設(shè)置定時(shí)任務(wù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-03-03
網(wǎng)易2016研發(fā)工程師編程題 獎(jiǎng)學(xué)金(python)
這篇文章主要為大家詳細(xì)介紹了網(wǎng)易2016研發(fā)工程師編程題:獎(jiǎng)學(xué)金(python),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-06-06
python Pandas庫(kù)基礎(chǔ)分析之時(shí)間序列的處理詳解
這篇文章主要介紹了python Pandas庫(kù)基礎(chǔ)分析之時(shí)間序列的處理詳解,Pandas作為Python環(huán)境下的數(shù)據(jù)分析庫(kù),更是提供了強(qiáng)大的日期數(shù)據(jù)處理的功能,是處理時(shí)間序列的利器,需要的朋友可以參考下2019-07-07

