|
|
|
@ -82,10 +82,17 @@ import activation
|
|
|
|
|
import attr
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
|
'parse_network', 'data', 'fc', 'max_id', 'classification_cost',
|
|
|
|
|
'cross_entropy_cost', 'cross_entropy_with_selfnorm_cost', 'regression_cost',
|
|
|
|
|
'parse_network', 'data', 'fc', 'conv_shift', 'img_conv', 'img_pool', 'spp',
|
|
|
|
|
'maxout', 'img_cmrnorm', 'batch_norm', 'sum_to_one_norm', 'recurrent',
|
|
|
|
|
'lstmemory', 'grumemory', 'pool', 'last_seq', 'first_seq', 'concat',
|
|
|
|
|
'seq_concat', 'block_expand', 'expand', 'repeat', 'seq_reshape', 'addto',
|
|
|
|
|
'linear_comb', 'interpolation', 'bilinear_interp', 'power', 'scaling',
|
|
|
|
|
'slope_intercept', 'tensor', 'cos_sim', 'trans', 'max_id', 'sampling_id',
|
|
|
|
|
'pad', 'classification_cost', 'cross_entropy_cost',
|
|
|
|
|
'cross_entropy_with_selfnorm_cost', 'regression_cost',
|
|
|
|
|
'multi_binary_label_cross_entropy_cost', 'rank_cost', 'lambda_cost',
|
|
|
|
|
'sum_cost', 'huber_cost'
|
|
|
|
|
'sum_cost', 'huber_cost', 'crf', 'crf_decoding', 'ctc', 'warp_ctc', 'nce',
|
|
|
|
|
'hsigmoid', 'eos'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
__projection_names__ = filter(lambda x: x.endswith('_projection'),
|
|
|
|
@ -143,9 +150,9 @@ class Layer(object):
|
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __convert_to_v2__(method_name, name_prefix=None, parent_names=None):
|
|
|
|
|
if name_prefix is not None:
|
|
|
|
|
wrapper = wrap_name_default(name_prefix=name_prefix)
|
|
|
|
|
def __convert_to_v2__(method_name, parent_names, is_default_name=True):
|
|
|
|
|
if is_default_name:
|
|
|
|
|
wrapper = wrap_name_default(name_prefix=method_name)
|
|
|
|
|
else:
|
|
|
|
|
wrapper = None
|
|
|
|
|
|
|
|
|
@ -278,43 +285,91 @@ def mixed(size=0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = DataLayerV2
|
|
|
|
|
fc = __convert_to_v2__('fc_layer', name_prefix='fc', parent_names=['input'])
|
|
|
|
|
max_id = __convert_to_v2__(
|
|
|
|
|
'maxid_layer', name_prefix='maxid', parent_names=['input'])
|
|
|
|
|
classification_cost = __convert_to_v2__(
|
|
|
|
|
'classification_cost',
|
|
|
|
|
name_prefix='classification_cost',
|
|
|
|
|
parent_names=['input', 'label', 'weight'])
|
|
|
|
|
regression_cost = __convert_to_v2__(
|
|
|
|
|
'regression_cost',
|
|
|
|
|
name_prefix='regression_cost',
|
|
|
|
|
parent_names=['input', 'label', 'weight'])
|
|
|
|
|
cross_entropy_cost = __convert_to_v2__(
|
|
|
|
|
'cross_entropy',
|
|
|
|
|
name_prefix='cross_entropy',
|
|
|
|
|
parent_names=['input', 'label'])
|
|
|
|
|
cross_entropy_with_selfnorm_cost = __convert_to_v2__(
|
|
|
|
|
'cross_entropy_with_selfnorm',
|
|
|
|
|
name_prefix='cross_entropy_with_selfnorm',
|
|
|
|
|
parent_names=['input', 'label'])
|
|
|
|
|
multi_binary_label_cross_entropy_cost = __convert_to_v2__(
|
|
|
|
|
'multi_binary_label_cross_entropy',
|
|
|
|
|
name_prefix='multi_binary_label_cross_entropy',
|
|
|
|
|
parent_names=['input', 'label'])
|
|
|
|
|
rank_cost = __convert_to_v2__(
|
|
|
|
|
'rank_cost',
|
|
|
|
|
name_prefix='rank_cost',
|
|
|
|
|
parent_names=['left', 'right', 'label', 'weight'])
|
|
|
|
|
lambda_cost = __convert_to_v2__(
|
|
|
|
|
'lambda_cost', name_prefix='lambda_cost', parent_names=['input', 'score'])
|
|
|
|
|
sum_cost = __convert_to_v2__(
|
|
|
|
|
'sum_cost', name_prefix='sum_cost', parent_names=['input'])
|
|
|
|
|
huber_cost = __convert_to_v2__(
|
|
|
|
|
'huber_cost', name_prefix='huber_cost', parent_names=['input', 'label'])
|
|
|
|
|
AggregateLevel = conf_helps.layers.AggregateLevel
|
|
|
|
|
ExpandLevel = conf_helps.layers.ExpandLevel
|
|
|
|
|
|
|
|
|
|
layer_list = [
|
|
|
|
|
# [V2LayerImpl, V1_method_name, parent_names]
|
|
|
|
|
# fully connected layers
|
|
|
|
|
['fc', 'fc_layer', ['input']],
|
|
|
|
|
# conv layers
|
|
|
|
|
['conv_shift', 'conv_shift_layer', ['a', 'b']],
|
|
|
|
|
['img_conv', 'img_conv_layer', ['input']],
|
|
|
|
|
# image pooling layers
|
|
|
|
|
['img_pool', 'img_pool_layer', ['input']],
|
|
|
|
|
['spp', 'spp_layer', ['input']],
|
|
|
|
|
['maxout', 'maxout_layer', ['input']],
|
|
|
|
|
# norm layers
|
|
|
|
|
['img_cmrnorm', 'img_cmrnorm_layer', ['input']],
|
|
|
|
|
['batch_norm', 'batch_norm_layer', ['input']],
|
|
|
|
|
['sum_to_one_norm', 'sum_to_one_norm_layer', ['input']],
|
|
|
|
|
# recurrent layers
|
|
|
|
|
['recurrent', 'recurrent_layer', ['input']],
|
|
|
|
|
['lstmemory', 'lstmemory', ['input']],
|
|
|
|
|
['grumemory', 'grumemory', ['input']],
|
|
|
|
|
# aggregate layers
|
|
|
|
|
['pool', 'pooling_layer', ['input']],
|
|
|
|
|
['last_seq', 'last_seq', ['input']],
|
|
|
|
|
['first_seq', 'first_seq', ['input']],
|
|
|
|
|
['concat', 'concat_layer', ['input']],
|
|
|
|
|
['seq_concat', 'seq_concat_layer', ['a', 'b']],
|
|
|
|
|
# reshaping layers
|
|
|
|
|
['block_expand', 'block_expand_layer', ['input']],
|
|
|
|
|
['expand', 'expand_layer', ['input', 'expand_as']],
|
|
|
|
|
['repeat', 'repeat_layer', ['input']],
|
|
|
|
|
['rotate', 'rotate_layer', ['input']],
|
|
|
|
|
['seq_reshape', 'seq_reshape_layer', ['input']],
|
|
|
|
|
# math layers
|
|
|
|
|
['addto', 'addto_layer', ['input']],
|
|
|
|
|
['linear_comb', 'linear_comb_layer', ['weights', 'vectors']],
|
|
|
|
|
['interpolation', 'interpolation_layer', ['input', 'weight']],
|
|
|
|
|
['bilinear_interp', 'bilinear_interp_layer', ['input']],
|
|
|
|
|
['power', 'power_layer', ['input', 'weight']],
|
|
|
|
|
['scaling', 'scaling_layer', ['input', 'weight']],
|
|
|
|
|
['slope_intercept', 'slope_intercept_layer', ['input']],
|
|
|
|
|
['tensor', 'tensor_layer', ['a', 'b']],
|
|
|
|
|
['cos_sim', 'cos_sim', ['a', 'b']],
|
|
|
|
|
['trans', 'trans_layer', ['input']],
|
|
|
|
|
# sampling layers
|
|
|
|
|
['max_id', 'maxid_layer', ['input']],
|
|
|
|
|
['sampling_id', 'sampling_id_layer', ['input']],
|
|
|
|
|
# slicing and joining layers
|
|
|
|
|
['pad', 'pad_layer', ['input']],
|
|
|
|
|
# cost layers
|
|
|
|
|
[
|
|
|
|
|
'classification_cost', 'classification_cost',
|
|
|
|
|
['input', 'label', 'weight']
|
|
|
|
|
],
|
|
|
|
|
['regression_cost', 'regression_cost', ['input', 'label', 'weight']],
|
|
|
|
|
['cross_entropy_cost', 'cross_entropy', ['input', 'label']],
|
|
|
|
|
[
|
|
|
|
|
'cross_entropy_with_selfnorm_cost', 'cross_entropy_with_selfnorm',
|
|
|
|
|
['input', 'label']
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'multi_binary_label_cross_entropy_cost',
|
|
|
|
|
'multi_binary_label_cross_entropy', ['input', 'label']
|
|
|
|
|
],
|
|
|
|
|
['rank_cost', 'rank_cost', ['left', 'right', 'label', 'weight']],
|
|
|
|
|
['lambda_cost', 'lambda_cost', ['input', 'score']],
|
|
|
|
|
['sum_cost', 'sum_cost', ['input']],
|
|
|
|
|
['huber_cost', 'huber_cost', ['input', 'label']],
|
|
|
|
|
['crf', 'crf_layer', ['input', 'label']],
|
|
|
|
|
['crf_decoding', 'crf_decoding_layer', ['input']],
|
|
|
|
|
['ctc', 'ctc_layer', ['input', 'label']],
|
|
|
|
|
['warp_ctc', 'warp_ctc_layer', ['input', 'label']],
|
|
|
|
|
['nce', 'nce_layer', ['input', 'label']],
|
|
|
|
|
['hsigmoid', 'hsigmoid', ['input', 'label']],
|
|
|
|
|
# check layers
|
|
|
|
|
['eos', 'eos_layer', ['input']]
|
|
|
|
|
]
|
|
|
|
|
for l in layer_list:
|
|
|
|
|
globals()[l[0]] = __convert_to_v2__(l[1], l[2])
|
|
|
|
|
|
|
|
|
|
# convert projection
|
|
|
|
|
for prj in __projection_names__:
|
|
|
|
|
globals()[prj] = __convert_to_v2__(prj, parent_names=['input'])
|
|
|
|
|
globals()[prj] = __convert_to_v2__(
|
|
|
|
|
prj, parent_names=['input'], is_default_name=False)
|
|
|
|
|
|
|
|
|
|
# convert operator
|
|
|
|
|
operator_list = [
|
|
|
|
@ -323,4 +378,5 @@ operator_list = [
|
|
|
|
|
['conv_operator', ['img', 'filter']]
|
|
|
|
|
]
|
|
|
|
|
for op in operator_list:
|
|
|
|
|
globals()[op[0]] = __convert_to_v2__(op[0], parent_names=op[1])
|
|
|
|
|
globals()[op[0]] = __convert_to_v2__(
|
|
|
|
|
op[0], parent_names=op[1], is_default_name=False)
|
|
|
|
|