Python lasagne.layers.ExpressionLayer() Examples
The following are 3
code examples of lasagne.layers.ExpressionLayer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
lasagne.layers
, or try the search function
.
Example #1
Source File: model.py From gogh-figure with GNU Affero General Public License v3.0 | 6 votes |
def setup_transform_net(self, input_var=None): transform_net = InputLayer(shape=self.shape, input_var=input_var) transform_net = style_conv_block(transform_net, self.num_styles, 32, 9, 1) transform_net = style_conv_block(transform_net, self.num_styles, 64, 3, 2) transform_net = style_conv_block(transform_net, self.num_styles, 128, 3, 2) for _ in range(5): transform_net = residual_block(transform_net, self.num_styles) transform_net = nn_upsample(transform_net, self.num_styles) transform_net = nn_upsample(transform_net, self.num_styles) if self.net_type == 0: transform_net = style_conv_block(transform_net, self.num_styles, 3, 9, 1, tanh) transform_net = ExpressionLayer(transform_net, lambda X: 150.*X, output_shape=None) elif self.net_type == 1: transform_net = style_conv_block(transform_net, self.num_styles, 3, 9, 1, sigmoid) self.network['transform_net'] = transform_net
Example #2
Source File: layers.py From gogh-figure with GNU Affero General Public License v3.0 | 5 votes |
def nn_upsample(upsample_in, num_styles=None, num_filters=None, filter_size=3, stride=1): if num_filters == None: num_filters = upsample_in.output_shape[1] nn_network = ExpressionLayer(upsample_in, lambda X: X.repeat(2, 2).repeat(2, 3), output_shape='auto') nn_network = style_conv_block(nn_network, num_styles, num_filters, filter_size, stride) return nn_network
Example #3
Source File: convnade.py From NADE with BSD 3-Clause "New" or "Revised" License | 4 votes |
def network(self): if self._network is not None: return self._network # Build the computational graph using a dummy input. import lasagne from lasagne.layers.dnn import Conv2DDNNLayer as ConvLayer from lasagne.layers import ElemwiseSumLayer, NonlinearityLayer, ExpressionLayer, PadLayer, InputLayer, FlattenLayer, SliceLayer # from lasagne.layers import batch_norm from lasagne.nonlinearities import rectify self._network_in = InputLayer(shape=(None, self.nb_channels,) + self.image_shape, input_var=None) convnet_layers = [self._network_in] convnet_layers_preact = [self._network_in] layer_blueprints = list(map(str.strip, self.convnet_blueprint.split("->"))) for i, layer_blueprint in enumerate(layer_blueprints, start=1): "64@3x3(valid) -> 64@3x3(full)" nb_filters, rest = layer_blueprint.split("@") filter_shape, rest = rest.split("(") nb_filters = int(nb_filters) filter_shape = tuple(map(int, filter_shape.split("x"))) pad = rest[:-1] preact = ConvLayer(convnet_layers[-1], num_filters=nb_filters, filter_size=filter_shape, stride=(1, 1), nonlinearity=None, pad=pad, W=lasagne.init.HeNormal(gain='relu')) if i > len(layer_blueprints) // 2 and i != len(layer_blueprints): shortcut = convnet_layers_preact[len(layer_blueprints)-i] if i == len(layer_blueprints): if preact.output_shape[1] != shortcut.output_shape[1]: shortcut = SliceLayer(shortcut, slice(0, 1), axis=1) else: raise NameError("Something is wrong.") print("Shortcut from {} to {}".format(len(layer_blueprints)-i, i)) preact = ElemwiseSumLayer([preact, shortcut]) convnet_layers_preact.append(preact) layer = NonlinearityLayer(preact, nonlinearity=rectify) convnet_layers.append(layer) self._network = FlattenLayer(preact) # network = DenseLayer(l, num_units=int(np.prod(self.image_shape)), # W=lasagne.init.HeNormal(), # nonlinearity=None) print("Nb. of parameters in model: {}".format(lasagne.layers.count_params(self._network, trainable=True))) return self._network