0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫(xiě)文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

如何搭建VGG網(wǎng)絡(luò)實(shí)現(xiàn)Mnist數(shù)據(jù)集的圖像分類(lèi)

jf_78858299 ? 來(lái)源:算法與編程之美 ? 作者:算法與編程之美 ? 2023-02-14 15:00 ? 次閱讀

1 問(wèn)題

如何搭建VGG網(wǎng)絡(luò),實(shí)現(xiàn)Mnist數(shù)據(jù)集的圖像分類(lèi)?

2 方法

步驟:

首先導(dǎo)包

VGG11由8個(gè)卷積,三個(gè)全連接組成,注意池化只改變特征圖大小,不改變通道數(shù)

給定x查看最后結(jié)果

x = torch.rand(128,3,224,224)
net = MyNet()
out = net(x)
print(out.shape)
#torch.Size([128, 1000])

class MyNet(nn.Module):
def __init__(self) -> None:
super().__init__()
#(1)conv3-64
self.conv1 = nn.Conv2d(
in_channels=3,
out_channels=64,
kernel_size=3,
stride=1,
padding=1 #! 不改變特征圖的大小
)
#! 池化只改變特征圖大小,不改變通道數(shù)
self.max_pool_1 = nn.MaxPool2d(2)
#(2)conv3-128
self.conv2 = nn.Conv2d(
in_channels=64,
out_channels=128,
kernel_size=3,
stride=1,
padding=1
)
self.max_pool_2 = nn.MaxPool2d(2)
#(3) conv3-256,conv3-256
self.conv3_1 = nn.Conv2d(
in_channels=128,
out_channels=256,
kernel_size=3,
stride=1,
padding=1)
self.conv3_2 = nn.Conv2d(
in_channels=256,
out_channels=256,
kernel_size=3,
stride=1,
padding=1
)
self.max_pool_3 = nn.MaxPool2d(2)
#(4)conv3-512,conv3-512
self.conv4_1 = nn.Conv2d(
in_channels=256,
out_channels=512,
kernel_size=3,
stride=1,
padding=1
)
self.conv4_2 = nn.Conv2d(
in_channels=512,
out_channels=512,
kernel_size=3,
stride=1,
padding=1
)
self.max_pool_4 = nn.MaxPool2d(2)
#(5)conv3-512,conv3-512
self.conv5_1 = nn.Conv2d(
in_channels=512,
out_channels=512,
kernel_size=3,
stride=1,
padding=1
)
self.conv5_2 = nn.Conv2d(
in_channels=512,
out_channels=512,
kernel_size=3,
stride=1,
padding=1
)
self.max_pool_5 = nn.MaxPool2d(2)
#(6)
self.fc1 = nn.Linear(25088,4096)
self.fc2 = nn.Linear(4096,4096)
self.fc3 = nn.Linear(4096,1000)
def forward(self,x):
x = self.conv1(x)
print(x.shape)
x = self.max_pool_1(x)
print(x.shape)
x = self.conv2(x)
print(x.shape)
x = self.max_pool_2(x)
print(x.shape)
x = self.conv3_1(x)
print(x.shape)
x = self.conv3_2(x)
print(x.shape)
x = self.max_pool_3(x)
print(x.shape)
x = self.conv4_1(x)
print(x.shape)
x = self.conv4_2(x)
print(x.shape)
x = self.max_pool_4(x)
print(x.shape)
x = self.conv5_1(x)
print(x.shape)
x = self.conv5_2(x)
print(x.shape)
x = self.max_pool_5(x)
print(x.shape)
x = torch.flatten(x,1)
print(x.shape)
x = self.fc1(x)
print(x.shape)
x = self.fc2(x)
print(x.shape)
out = self.fc3(x)
return out

Import torch
from torch import nn

3 結(jié)語(yǔ)

通過(guò)本周學(xué)習(xí)讓我學(xué)會(huì)了VGG11網(wǎng)絡(luò),從實(shí)驗(yàn)中我遇到的容易出錯(cuò)的地方是卷積的in_features和out_features容易出錯(cuò),尺寸不對(duì)的時(shí)候就會(huì)報(bào)錯(cuò),在多個(gè)卷積的情況下尤其需要注意,第二點(diǎn)容易出錯(cuò)的地方是卷積以及池化所有結(jié)束后,一定要使用torch.flatten進(jìn)行拉伸,第三點(diǎn)容易出錯(cuò)的地方是fc1的in_features,這個(gè)我通過(guò)使用斷點(diǎn)的方法,得到fc1前一步的size值,從而得到in_features的值,從中收獲頗深。

聲明:本文內(nèi)容及配圖由入駐作者撰寫(xiě)或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 數(shù)據(jù)集
    +關(guān)注

    關(guān)注

    4

    文章

    1199

    瀏覽量

    24594
  • MNIST
    +關(guān)注

    關(guān)注

    0

    文章

    10

    瀏覽量

    3353
  • vgg
    vgg
    +關(guān)注

    關(guān)注

    1

    文章

    11

    瀏覽量

    5176
收藏 人收藏

    評(píng)論

    相關(guān)推薦

    TF之CNN:CNN實(shí)現(xiàn)mnist數(shù)據(jù)預(yù)測(cè)

    TF之CNN:CNN實(shí)現(xiàn)mnist數(shù)據(jù)預(yù)測(cè) 96%采用placeholder用法+2層C及其max_pool法+隱藏層dropout法+輸出層softmax法+目標(biāo)函數(shù)cross_e
    發(fā)表于 12-19 17:02

    使用MXNetFashionMNIST數(shù)據(jù)分類(lèi)簡(jiǎn)潔實(shí)現(xiàn)

    [MXNet逐夢(mèng)之旅]練習(xí)四·使用MXNetFashionMNIST數(shù)據(jù)分類(lèi)簡(jiǎn)潔實(shí)現(xiàn)
    發(fā)表于 05-11 15:21

    圖像分類(lèi)Caltech 256數(shù)據(jù)

    教程圖像分類(lèi) Caltech 256?數(shù)據(jù)
    發(fā)表于 05-12 09:04

    使用MXNetFashionMNIST數(shù)據(jù)分類(lèi)手動(dòng)實(shí)現(xiàn)

    [MXNet逐夢(mèng)之旅]練習(xí)三·使用MXNetFashionMNIST數(shù)據(jù)分類(lèi)手動(dòng)實(shí)現(xiàn)
    發(fā)表于 05-14 07:40

    TensorFlow邏輯回歸處理MNIST數(shù)據(jù)

    /get_started/mnist/beginners提供。大部分人已經(jīng)對(duì) MNIST 數(shù)據(jù)很熟悉了,它是機(jī)器學(xué)習(xí)的基礎(chǔ),包含手寫(xiě)數(shù)字的圖像
    發(fā)表于 08-11 19:36

    TensorFlow邏輯回歸處理MNIST數(shù)據(jù)

    /get_started/mnist/beginners提供。大部分人已經(jīng)對(duì) MNIST 數(shù)據(jù)很熟悉了,它是機(jī)器學(xué)習(xí)的基礎(chǔ),包含手寫(xiě)數(shù)字的圖像
    發(fā)表于 08-11 19:36

    如何用TensorFlow導(dǎo)入MNIST數(shù)據(jù)?

    用TensorFlow導(dǎo)入MNIST數(shù)據(jù)
    發(fā)表于 11-11 07:33

    圖像預(yù)處理和改進(jìn)神經(jīng)網(wǎng)絡(luò)推理的簡(jiǎn)要介紹

    為提升識(shí)別準(zhǔn)確率,采用改進(jìn)神經(jīng)網(wǎng)絡(luò),通過(guò)Mnist數(shù)據(jù)進(jìn)行訓(xùn)練。整體處理過(guò)程分為兩步:圖像預(yù)處理和改進(jìn)神經(jīng)
    發(fā)表于 12-23 08:07

    keras制作mnist數(shù)據(jù)的流程

    第5講講解了keras制作mnist數(shù)據(jù)的流程,進(jìn)一步的,有時(shí)候我們需要構(gòu)建自己的數(shù)據(jù)。 以flower
    發(fā)表于 08-18 06:38

    如何利用keras打包制作mnist數(shù)據(jù)

    mnist為例講述怎么自己制作數(shù)據(jù)。 1 使用keras內(nèi)置函數(shù)下載數(shù)據(jù) import tensorflow as tf impor
    發(fā)表于 08-18 06:12

    如何使用神經(jīng)網(wǎng)絡(luò)模型加速圖像數(shù)據(jù)分類(lèi)

    通過(guò)圖像分類(lèi)示例,了解Xilinx FPGA如何加速機(jī)器學(xué)習(xí),這是關(guān)鍵的數(shù)據(jù)中心工作負(fù)載。 該演示使用Alexnet神經(jīng)網(wǎng)絡(luò)模型加速了ImageNet
    的頭像 發(fā)表于 11-21 06:08 ?2437次閱讀

    如何使用VGG網(wǎng)絡(luò)進(jìn)行MNIST圖像分類(lèi)

    VGG網(wǎng)絡(luò),可以應(yīng)用在人臉識(shí)別、圖像分類(lèi)等方面。VGG有兩種結(jié)構(gòu),分別為16層和19層。具體結(jié)構(gòu)在其文獻(xiàn)做了詳細(xì)表述
    的頭像 發(fā)表于 02-17 15:06 ?858次閱讀
    如何使用<b class='flag-5'>VGG</b><b class='flag-5'>網(wǎng)絡(luò)</b>進(jìn)行<b class='flag-5'>MNIST</b><b class='flag-5'>圖像</b><b class='flag-5'>分類(lèi)</b>

    簡(jiǎn)述PyTorch中mnist的transforms圖像處理

    MNIST數(shù)據(jù)是一個(gè)公開(kāi)的數(shù)據(jù),相當(dāng)于深度學(xué)習(xí)的hello world,用來(lái)檢驗(yàn)一個(gè)模型/庫(kù)/框架是否有效的一個(gè)評(píng)價(jià)指標(biāo)。
    的頭像 發(fā)表于 02-24 10:43 ?512次閱讀
    簡(jiǎn)述PyTorch中<b class='flag-5'>mnist</b>的transforms<b class='flag-5'>圖像</b>處理

    PyTorch教程4.2之圖像分類(lèi)數(shù)據(jù)

    電子發(fā)燒友網(wǎng)站提供《PyTorch教程4.2之圖像分類(lèi)數(shù)據(jù).pdf》資料免費(fèi)下載
    發(fā)表于 06-05 15:41 ?0次下載
    PyTorch教程4.2之<b class='flag-5'>圖像</b><b class='flag-5'>分類(lèi)</b><b class='flag-5'>數(shù)據(jù)</b><b class='flag-5'>集</b>

    PyTorch教程-4.2. 圖像分類(lèi)數(shù)據(jù)

    SageMaker Studio Lab 中打開(kāi)筆記本 廣泛用于圖像分類(lèi)數(shù)據(jù)之一是手寫(xiě)數(shù)字的MNIST
    的頭像 發(fā)表于 06-05 15:38 ?565次閱讀
    PyTorch教程-4.2. <b class='flag-5'>圖像</b><b class='flag-5'>分類(lèi)</b><b class='flag-5'>數(shù)據(jù)</b><b class='flag-5'>集</b>