欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Pytorch統(tǒng)計(jì)參數(shù)網(wǎng)絡(luò)參數(shù)數(shù)量方式

 更新時(shí)間:2023年02月20日 10:09:39   作者:qq_34535410  
這篇文章主要介紹了Pytorch統(tǒng)計(jì)參數(shù)網(wǎng)絡(luò)參數(shù)數(shù)量方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Pytorch統(tǒng)計(jì)參數(shù)網(wǎng)絡(luò)參數(shù)數(shù)量

def get_parameter_number(net):
    total_num = sum(p.numel() for p in net.parameters())
    trainable_num = sum(p.numel() for p in net.parameters() if p.requires_grad)
    return {'Total': total_num, 'Trainable': trainable_num}

Pytorch如何計(jì)算網(wǎng)絡(luò)的參數(shù)量

本文以 Dense Block 為例,Pytorch 為 DL 框架,最終計(jì)算模塊參數(shù)量方法如下:

import torch
import torch.nn as nn

class Norm_Conv(nn.Module):

? ? def __init__(self,in_channel):
? ? ? ? super(Norm_Conv,self).__init__()
? ? ? ? self.layers = nn.Sequential(
? ? ? ? ? ? nn.Conv2d(in_channel,in_channel,3,1,1),
? ? ? ? ? ? nn.ReLU(True),
? ? ? ? ? ? nn.BatchNorm2d(in_channel),
? ? ? ? ? ? nn.Conv2d(in_channel,in_channel,3,1,1),
? ? ? ? ? ? nn.ReLU(True),
? ? ? ? ? ? nn.BatchNorm2d(in_channel),
? ? ? ? ? ? nn.Conv2d(in_channel,in_channel,3,1,1),
? ? ? ? ? ? nn.ReLU(True),
? ? ? ? ? ? nn.BatchNorm2d(in_channel))
? ? def forward(self,input):
? ? ? ? out = self.layers(input)
? ? ? ? return out


class DenseBlock_Norm(nn.Module):
? ? def __init__(self,in_channel):
? ? ? ? super(DenseBlock_Norm,self).__init__()

? ? ? ? self.first_layer = nn.Sequential(nn.Conv2d(in_channel,in_channel,3,1,1),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? nn.ReLU(True),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? nn.BatchNorm2d(in_channel))
? ? ? ? self.second_layer = nn.Sequential(nn.Conv2d(in_channel*2,in_channel,3,1,1),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? nn.ReLU(True),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? nn.BatchNorm2d(in_channel))
? ? ? ? self.third_layer = nn.Sequential(
? ? ? ? ? ? nn.Conv2d(in_channel*3,in_channel,3,1,1),
? ? ? ? ? ? nn.ReLU(True),
? ? ? ? ? ? nn.BatchNorm2d(in_channel))

? ? def forward(self,input):

? ? ? ? output1 = self.first_layer(input)
? ? ? ? output2 = self.second_layer(torch.cat((output1,input),dim=1))
? ? ? ? output3 = self.third_layer(torch.cat((input,output1,output2),dim=1))

? ? ? ? return output3

def count_param(model):
? ? param_count = 0
? ? for param in model.parameters():
? ? ? ? param_count += param.view(-1).size()[0]
? ? return param_count

# Get Parameter number of Network
in_channel = 128
net1 = Norm_Conv(in_channel)
print('Norm Conv parameter count is {}'.format(count_param(net1)))
net2 = DenseBlock_Norm(in_channel)
print('DenseBlock Norm parameter count is {}'.format(count_param(net2)))

最終結(jié)果如下

Norm Conv parameter count is 443520
DenseBlock Norm parameter count is 885888

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 使用pandas對(duì)兩個(gè)dataframe進(jìn)行join的實(shí)例

    使用pandas對(duì)兩個(gè)dataframe進(jìn)行join的實(shí)例

    今天小編就為大家分享一篇使用pandas對(duì)兩個(gè)dataframe進(jìn)行join的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-06-06
  • python selenium 獲取接口數(shù)據(jù)的實(shí)現(xiàn)

    python selenium 獲取接口數(shù)據(jù)的實(shí)現(xiàn)

    這篇文章主要介紹了python selenium 獲取接口數(shù)據(jù)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Python中os模塊功能與用法詳解

    Python中os模塊功能與用法詳解

    這篇文章主要介紹了Python中os模塊功能與用法,總結(jié)分析了Python os模塊基本功能、內(nèi)置函數(shù)、使用方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下
    2020-02-02
  • Python實(shí)現(xiàn)Windows上氣泡提醒效果的方法

    Python實(shí)現(xiàn)Windows上氣泡提醒效果的方法

    這篇文章主要介紹了Python實(shí)現(xiàn)Windows上氣泡提醒效果的方法,涉及Python針對(duì)windows窗口操作的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • Python GAE、Django導(dǎo)出Excel的方法

    Python GAE、Django導(dǎo)出Excel的方法

    在Python中操作Excel的方法可以通過(guò)COM,最常用的跨平臺(tái)的方法是使用pyExcelerator,pyExcelerator的使用方法可以參考limodou的《使用pyExcelerator來(lái)讀寫Excel文件》。
    2008-11-11
  • python循環(huán)某一特定列的所有行數(shù)據(jù)(方法示例)

    python循環(huán)某一特定列的所有行數(shù)據(jù)(方法示例)

    在Python中,處理表格數(shù)據(jù)(比如CSV文件、Excel文件等)時(shí),我們通常會(huì)使用pandas庫(kù),因?yàn)樗峁┝素S富的數(shù)據(jù)結(jié)構(gòu)和數(shù)據(jù)分析工具,下面,我將以處理CSV文件中的某一特定列的所有行數(shù)據(jù)為例,給出詳細(xì)、完整的代碼示例,感興趣的朋友跟隨小編一起看看吧
    2024-08-08
  • Python實(shí)現(xiàn)進(jìn)程同步和通信的方法

    Python實(shí)現(xiàn)進(jìn)程同步和通信的方法

    本篇文章主要介紹了Python實(shí)現(xiàn)進(jìn)程同步和通信的方法,詳細(xì)的介紹了Process、Queue、Pipe、Lock等組件,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-01-01
  • python根據(jù)文章標(biāo)題內(nèi)容自動(dòng)生成摘要的實(shí)例

    python根據(jù)文章標(biāo)題內(nèi)容自動(dòng)生成摘要的實(shí)例

    今天小編就為大家分享一篇python根據(jù)文章標(biāo)題內(nèi)容自動(dòng)生成摘要的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-02-02
  • Python使用matplotlib.pyplot畫熱圖和損失圖的代碼詳解

    Python使用matplotlib.pyplot畫熱圖和損失圖的代碼詳解

    眾所周知,在完成論文相關(guān)工作時(shí)畫圖必不可少,如損失函數(shù)圖、熱力圖等是非常常見(jiàn)的圖,在本文中,總結(jié)了這兩個(gè)圖的畫法,下面給出了完整的代碼,開(kāi)箱即用,感興趣的同學(xué)可以自己動(dòng)手嘗試一下
    2023-09-09
  • python統(tǒng)計(jì)中文字符數(shù)量的兩種方法

    python統(tǒng)計(jì)中文字符數(shù)量的兩種方法

    今天小編就為大家分享一篇python統(tǒng)計(jì)中文字符數(shù)量的兩種方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-01-01

最新評(píng)論