python中l2 什么意思_Python regularizers.l1l2方法代码示例

# 需要导入模块: from keras import regularizers [as 别名]

# 或者: from keras.regularizers import l1l2 [as 别名]

def comp_two_path(self):

'''

compiles two-path model, takes in a 4x33x33 patch and assesses global and local paths, then merges the results.

'''

print 'Compiling two-path model...'

model = Graph()

model.add_input(name='input', input_shape=(self.n_chan, 33, 33))

# local pathway, first convolution/pooling

model.add_node(Convolution2D(64, 7, 7, border_mode='valid', activation='relu', W_regularizer=l1l2(l1=0.01, l2=0.01)), name='local_c1', input= 'input')

model.add_node(MaxPooling2D(pool_size=(4,4), strides=(1,1), border_mode='valid'), name='local_p1', input='local_c1')

# local pathway, second convolution/pooling

model.add_node(Dropout(0.5), name='drop_lp1', input='local_p1')

model.add_node(Convolution2D(64, 3, 3, border_mode='valid', activation='relu', W_regularizer=l1l2(l1=0.01, l2=0.01)), name='local_c2', input='drop_lp1')

model.add_node(MaxPooling2D(pool_size=(2,2), strides=(1,1), border_mode='valid'), name='local_p2', input='local_c2')

# global pathway

model.add_node(Convolution2D(160, 13, 13, border_mode='valid', activation='relu', W_regularizer=l1l2(l1=0.01, l2=0.01)), name='global', input='input')

# merge local and global pathways

model.add_node(Dropout(0.5), name='drop_lp2', input='local_p2')

model.add_node(Dropout(0.5), name='drop_g', input='global')

model.add_node(Convolution2D(5, 21, 21, border_mode='valid', activation='relu', W_regularizer=l1l2(l1=0.01, l2=0.01)), name='merge', inputs=['drop_lp2', 'drop_g'], merge_mode='concat', concat_axis=1)

# Flatten output of 5x1x1 to 1x5, perform softmax

model.add_node(Flatten(), name='flatten', input='merge')

model.add_node(Dense(5, activation='softmax'), name='dense_output', input='flatten')

model.add_output(name='output', input='dense_output')

sgd = SGD(lr=0.005, decay=0.1, momentum=0.9)

model.compile('sgd', loss={'output':'categorical_crossentropy'})

print 'Done.'

return model

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值