檢視模型的權值 模型與Tensor的區別

2021-10-17 03:05:45 字數 1776 閱讀 8894

模型:

1)conv1 = nn.conv2d(in_ch,out_ch,kernel_size,stride,padding)

2) 繼承nn.module類 (nn.sequence)

3)繼承nn.module類 (手寫)

tensor

1) conv1(input)

2) doubleconv(input)

tensor沒有state_dict()方法,模型有state_dict()方法,可以檢視變數

#%%

import torch

import torch.nn as nn

#%% md

#%% 單層網路模型

input = torch.arange(16,dtype=torch.float32).view([1,1,4,4])

model = nn.conv2d(1,1,kernel_size=3,stride=1,padding=0)

print(model.state_dict())

modeldict = model.state_dict()

print(modeldict['weight'])

print(modeldict['bias'])

#%% 多層網路模型(nn.sequence)

class doubleconv(nn.module):

def __init__(self, in_ch, out_ch):

super(doubleconv, self).__init__()

self.conv = nn.sequential( #影象大小不變

nn.conv2d(in_ch, out_ch, 3, padding=1), #in_ch * w * h * t -> out_ch * w * h * t

nn.conv2d(out_ch, out_ch, 3, padding=1),

)def forward(self, input):

return self.conv(input)

#模型model1 = doubleconv(2,2)

print(model1.state_dict())

#%% 多層網路模型(手動)

class doubleconv1(nn.module):

def __init__(self, in_ch, out_ch):

super(doubleconv1, self).__init__()

#影象大小不變

self.conv1 = nn.conv2d(in_ch, out_ch, 3, padding=1) #in_ch * w * h * t -> out_ch * w * h * t #in_ch * w * h * t -> out_ch * w * h * t #in_ch * w * h * t -> out_ch * w * h * t

self.conv2 = nn.conv2d(in_ch, out_ch, 3, padding=1)

def forward(self, x):

c1=self.conv1(x) #自動呼叫doubleconv類中的forward函式

c2=self.conv2(c1)

return c2

#模型model2 = doubleconv1(2,2)

print(model2.state_dict())

權值的輸出我就不寫了,執行**即可

檢視caffe模型的引數

1.訓練模型的引數 solver caffe.sgdsolver str solver path for name,blob in solver.net.blobs,items 網路中的資料,blobs是乙個字典 print name str blob.data.shape blob是blob的類物...

樹模型與線性模型的融合模型 Python實現

目錄 一 樹模型與線性模型的融合模型 二 python sklearn實現gbdt lr融合模型 樹模型gbdt原理 線性模型lr原理 海量的離散特徵 線性模型lr,因其較高的精度和較少的運算開銷在業界廣為使用。線性模型lr無法捕捉到非線性特徵對標籤的影響,因而提公升線性模型精度的有效方法是構造有效...

OSI模型與TCP IP模型的比較

cp ip模型實際上是osi模型的乙個濃縮版本,它只有四個層次 1.應用層 2.運輸層 3.網際層 4.網路介面層 與osi功能相比 應用層對應著osi的 應用層 表示層 會話層 運輸層對應著osi的傳輸層 網際層對應著osi的網路層 網路介面層對應著osi的資料鏈路層和物理層 tcp ip模型的主...