深度学习模型--卷积参数计算

1.深度学习参数计算代码

# --coding:utf-8--
from keras.layers import Conv2D, Input, Activation
from keras import Model

def build_model(input_shape, filter_num=16):
    x = Input(input_shape)
    c_1 = Conv2D(filter_num, (3, 3), use_bias=True)(x)
    out = Activation('relu')(c_1)
    model = Model(input=x, output=out)
    return model
# 1*1+3*3
def build_model2(input_shape, filter_num=16):
    x = Input(input_shape)
    c_0 = Conv2D(filter_num//2, (1, 1), use_bias=True)(x)
    c_1 = Conv2D(filter_num, (3, 3), use_bias=True)(c_0)
    out = Activation('relu')(c_1)
    model = Model(input=x, output=out)
    return model
    
model = build_model((28, 28, 1), filter_num=16)
# Param = filter_num*kernel_size*kernel_size + filter_num(use_bias=True)
model.summary()
# 参数保存
import pickle
with open("./Test.pkl", 'wb') as fh:
    pickle.dump(model, fh)
with open("./Test.pkl", 'rb') as fh:
    data = pickle.load(fh)

2.计算公式

Param = filter_num * kernel_size * kernel_size*channel + filter_num(use_bias=True)

3.计算截图

use_bias=False
深度学习模型--卷积参数计算_第1张图片
use_bias=True
深度学习模型--卷积参数计算_第2张图片

你可能感兴趣的:(DeepLearning)