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完成FizzBuzzWhizz問(wèn)題(拉勾網(wǎng)面試題)示例
這篇文章主要介紹了python完成FizzBuzzWhizz問(wèn)題(拉勾網(wǎng)面試題)示例,需要的朋友可以參考下2014-05-05
老生常談python函數(shù)參數(shù)的區(qū)別(必看篇)
下面小編就為大家?guī)?lái)一篇老生常談python函數(shù)參數(shù)的區(qū)別(必看篇)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05
Pygame實(shí)戰(zhàn)之檢測(cè)按鍵正確的小游戲
這篇文章主要為大家介紹了利用Pygame模塊實(shí)現(xiàn)的檢測(cè)按鍵正確的小游戲:每個(gè)字母有10秒的按鍵時(shí)間,如果按對(duì),則隨機(jī)產(chǎn)生新的字符,一共60s,如果時(shí)間到了,則游戲結(jié)束??靵?lái)跟隨小編一起學(xué)習(xí)一下吧2021-12-12
詳解pandas庫(kù)pd.read_excel操作讀取excel文件參數(shù)整理與實(shí)例
這篇文章主要介紹了pandas庫(kù)pd.read_excel操作讀取excel文件參數(shù)整理與實(shí)例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-02-02
python爬蟲(chóng)中g(shù)et和post方法介紹以及cookie作用
本篇文章通過(guò)爬取163郵箱實(shí)例介紹了python爬蟲(chóng)中g(shù)et和post方法介紹以及cookie作用,對(duì)此有興趣的朋友學(xué)習(xí)下。2018-02-02
Python實(shí)現(xiàn)PS濾鏡特效之扇形變換效果示例
這篇文章主要介紹了Python實(shí)現(xiàn)PS濾鏡特效之扇形變換效果,結(jié)合實(shí)例形式分析了Python實(shí)現(xiàn)PS濾鏡扇形變換效果的原理與相關(guān)操作技巧,需要的朋友可以參考下2018-01-01
使用Python實(shí)現(xiàn)一鍵隱藏屏幕并鎖定輸入
本文主要介紹了使用 Python 編寫(xiě)一個(gè)一鍵隱藏屏幕并鎖定輸入的黑科技程序,能夠在指定熱鍵觸發(fā)后立即遮擋屏幕,并禁止一切鍵盤(pán)鼠標(biāo)輸入,這樣就再也不用擔(dān)心自己的屏幕被人偷看啦2025-04-04
Python Matplotlib數(shù)據(jù)可視化模塊使用詳解
matplotlib是基建立在python之上,適用于創(chuàng)建靜態(tài),動(dòng)畫(huà)和交互式可視化,通常與數(shù)據(jù)分析模塊pandas搭配使用,用于數(shù)據(jù)的分析和展示,適用于主流的操作系統(tǒng),如Linux、Win、Mac2022-11-11

