一区二区三区三上|欧美在线视频五区|国产午夜无码在线观看视频|亚洲国产裸体网站|无码成年人影视|亚洲AV亚洲AV|成人开心激情五月|欧美性爱内射视频|超碰人人干人人上|一区二区无码三区亚洲人区久久精品

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

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

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

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

jf_78858299 ? 來源:算法與編程之美 ? 作者:算法與編程之美 ? 2023-02-14 15:00 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

1 問題

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

2 方法

步驟:

首先導(dǎo)包

VGG11由8個卷積,三個全連接組成,注意池化只改變特征圖大小,不改變通道數(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é)語

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

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

    關(guān)注

    4

    文章

    1223

    瀏覽量

    25377
  • MNIST
    +關(guān)注

    關(guān)注

    0

    文章

    10

    瀏覽量

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

    關(guān)注

    1

    文章

    11

    瀏覽量

    5341
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關(guān)推薦
    熱點推薦

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

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

    使用MXNetFashionMNIST數(shù)據(jù)分類簡潔實現(xiàn)

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

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

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

    使用MXNetFashionMNIST數(shù)據(jù)分類手動實現(xiàn)

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

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

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

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

    /get_started/mnist/beginners提供。大部分人已經(jīng)對 MNIST 數(shù)據(jù)很熟悉了,它是機器學(xué)習(xí)的基礎(chǔ),包含手寫數(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īng)網(wǎng)絡(luò)推理的簡要介紹

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

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

    第5講講解了keras制作mnist數(shù)據(jù)的流程,進一步的,有時候我們需要構(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ù)分類

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

    如何使用VGG網(wǎng)絡(luò)進行MNIST圖像分類

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

    簡述PyTorch中mnist的transforms圖像處理

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

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

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

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

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