本文整理匯總了Python中lasagne.layers.ExpressionLayer方法的典型用法代碼示例。如果您正苦於以下問題:Python layers.ExpressionLayer方法的具體用法?Python layers.ExpressionLayer怎麽用?Python layers.ExpressionLayer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類lasagne.layers
的用法示例。
在下文中一共展示了layers.ExpressionLayer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup_transform_net
# 需要導入模塊: from lasagne import layers [as 別名]
# 或者: from lasagne.layers import ExpressionLayer [as 別名]
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
示例2: nn_upsample
# 需要導入模塊: from lasagne import layers [as 別名]
# 或者: from lasagne.layers import ExpressionLayer [as 別名]
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
示例3: network
# 需要導入模塊: from lasagne import layers [as 別名]
# 或者: from lasagne.layers import ExpressionLayer [as 別名]
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