def build_network(self, conf, model=None, input_shape=None, is_conv=True):
"""Build network"""
_model = model
model = Sequential()
if _model is None:
model.add(Lambda(lambda x: x, input_shape=input_shape))
else:
model.add(_model)
for x in conf:
if x['is_drop']:
model.add(Dropout(x['drop_rate']))
if x['type'] is 'full':
if is_conv:
model.add(Flatten())
is_conv = False
model.add(Dense(x['n_feature']))
elif x['type'] is 'conv':
model.add(Convolution2D(nb_filter=x['n_feature'],
nb_row=x['kw'],
nb_col=1,
border_mode='same'))
is_conv=True
if x['is_batch']:
if x['type'] is 'full':
model.add(BatchNormalization(mode=1, axis=-1))
if x['type'] is 'conv':
model.add(BatchNormalization(mode=2, axis=-1))
model.add(x['activation'])
return model
评论列表
文章目录