PyTorch實現(xiàn)AlexNet示例
更新時間:2020年01月14日 14:18:19 作者:mingo_敏
今天小編就為大家分享一篇PyTorch實現(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實現(xiàn)AlexNet示例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python?Flask-Login構(gòu)建強大的用戶認證系統(tǒng)實例探究
這篇文章主要為大家介紹了Python?Flask-Login構(gòu)建強大的用戶認證系統(tǒng)示例探究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2024-01-01
tensorflow 實現(xiàn)數(shù)據(jù)類型轉(zhuǎn)換
今天小編就為大家分享一篇tensorflow 實現(xiàn)數(shù)據(jù)類型轉(zhuǎn)換,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02
celery實現(xiàn)動態(tài)設(shè)置定時任務(wù)
這篇文章主要為大家詳細介紹了celery實現(xiàn)動態(tài)設(shè)置定時任務(wù),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-03-03
網(wǎng)易2016研發(fā)工程師編程題 獎學(xué)金(python)
這篇文章主要為大家詳細介紹了網(wǎng)易2016研發(fā)工程師編程題:獎學(xué)金(python),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-06-06
python Pandas庫基礎(chǔ)分析之時間序列的處理詳解
這篇文章主要介紹了python Pandas庫基礎(chǔ)分析之時間序列的處理詳解,Pandas作為Python環(huán)境下的數(shù)據(jù)分析庫,更是提供了強大的日期數(shù)據(jù)處理的功能,是處理時間序列的利器,需要的朋友可以參考下2019-07-07

