我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用lasagne.layers.MergeLayer()。
def __init__(self, incoming, num_labels, mask_input=None, W=init.GlorotUniform(), b=init.Constant(0.), **kwargs): # This layer inherits from a MergeLayer, because it can have two # inputs - the layer input, and the mask. # We will just provide the layer input as incomings, unless a mask input was provided. self.input_shape = incoming.output_shape incomings = [incoming] self.mask_incoming_index = -1 if mask_input is not None: incomings.append(mask_input) self.mask_incoming_index = 1 super(ChainCRFLayer, self).__init__(incomings, **kwargs) self.num_labels = num_labels + 1 self.pad_label_index = num_labels num_inputs = self.input_shape[2] self.W = self.add_param(W, (num_inputs, self.num_labels, self.num_labels), name="W") if b is None: self.b = None else: self.b = self.add_param(b, (self.num_labels, self.num_labels), name="b", regularizable=False)
def __init__(self, incoming, num_labels, mask_input=None, W_h=init.GlorotUniform(), W_c=init.GlorotUniform(), b=init.Constant(0.), **kwargs): # This layer inherits from a MergeLayer, because it can have two # inputs - the layer input, and the mask. # We will just provide the layer input as incomings, unless a mask input was provided. self.input_shape = incoming.output_shape incomings = [incoming] self.mask_incoming_index = -1 if mask_input is not None: incomings.append(mask_input) self.mask_incoming_index = 1 super(TreeAffineCRFLayer, self).__init__(incomings, **kwargs) self.num_labels = num_labels dim_inputs = self.input_shape[2] # add parameters self.W_h = self.add_param(W_h, (dim_inputs, self.num_labels), name='W_h') self.W_c = self.add_param(W_c, (dim_inputs, self.num_labels), name='W_c') if b is None: self.b = None else: self.b = self.add_param(b, (self.num_labels,), name='b', regularizable=False)
def __init__(self, incoming, num_labels, mask_input=None, U=init.GlorotUniform(), W_h=init.GlorotUniform(), W_c=init.GlorotUniform(), b=init.Constant(0.), **kwargs): # This layer inherits from a MergeLayer, because it can have two # inputs - the layer input, and the mask. # We will just provide the layer input as incomings, unless a mask input was provided. self.input_shape = incoming.output_shape incomings = [incoming] self.mask_incoming_index = -1 if mask_input is not None: incomings.append(mask_input) self.mask_incoming_index = 1 super(TreeBiAffineCRFLayer, self).__init__(incomings, **kwargs) self.num_labels = num_labels dim_inputs = self.input_shape[2] # add parameters self.U = self.add_param(U, (dim_inputs, dim_inputs, self.num_labels), name='U') self.W_h = None if W_h is None else self.add_param(W_h, (dim_inputs, self.num_labels), name='W_h') self.W_c = None if W_c is None else self.add_param(W_c, (dim_inputs, self.num_labels), name='W_c') if b is None: self.b = None else: self.b = self.add_param(b, (self.num_labels,), name='b', regularizable=False)
def __init__(self, incoming, num_labels, mask_input=None, W_h=init.GlorotUniform(), W_c=init.GlorotUniform(), b=init.Constant(0.), **kwargs): # This layer inherits from a MergeLayer, because it can have two # inputs - the layer input, and the mask. # We will just provide the layer input as incomings, unless a mask input was provided. self.input_shape = incoming.output_shape incomings = [incoming] self.mask_incoming_index = -1 if mask_input is not None: incomings.append(mask_input) self.mask_incoming_index = 1 super(DepParserLayer, self).__init__(incomings, **kwargs) self.num_labels = num_labels num_inputs = self.input_shape[2] # add parameters self.W_h = self.add_param(W_h, (num_inputs, self.num_labels), name='W_h') self.W_c = self.add_param(W_c, (num_inputs, self.num_labels), name='W_c') if b is None: self.b = None else: self.b = self.add_param(b, (self.num_labels,), name='b', regularizable=False)
def __init__(self, incoming, num_labels, mask_input=None, W=init.GlorotUniform(), b=init.Constant(0.), **kwargs): # This layer inherits from a MergeLayer, because it can have two # inputs - the layer input, and the mask. # We will just provide the layer input as incomings, unless a mask input was provided. self.input_shape = incoming.output_shape incomings = [incoming] self.mask_incoming_index = -1 if mask_input is not None: incomings.append(mask_input) self.mask_incoming_index = 1 super(CRFLayer, self).__init__(incomings, **kwargs) self.num_labels = num_labels + 1 self.pad_label_index = num_labels num_inputs = self.input_shape[2] self.W = self.add_param(W, (num_inputs, self.num_labels, self.num_labels), name="W") if b is None: self.b = None else: self.b = self.add_param(b, (self.num_labels, self.num_labels), name="b", regularizable=False)
def _construct_layer_maps(self): layers = L.get_all_layers(self.output_layer) # Store inverse layers to enable merging. self.inverse_map = {l: None for l in layers} # Store the layers a specific layer feeds. self.output_map = {l: [] for l in layers} for layer in layers: if type(layer) is not L.InputLayer: if isinstance(layer, L.MergeLayer): for feeder in layer.input_layers: self.output_map[feeder].append(layer) else: self.output_map[layer.input_layer].append(layer)
def __init__(self, incomings, **kwargs): ls.MergeLayer.__init__(self, incomings, **kwargs)