本文整理汇总了Python中lasagne.layers.InputLayer方法的典型用法代码示例。如果您正苦于以下问题:Python layers.InputLayer方法的具体用法?Python layers.InputLayer怎么用?Python layers.InputLayer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lasagne.layers
的用法示例。
在下文中一共展示了layers.InputLayer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_discriminator_toy
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [as 别名]
def build_discriminator_toy(image=None, nd=512, GP_norm=None):
Input = InputLayer(shape=(None, 2), input_var=image)
print ("Dis input:", Input.output_shape)
dis0 = DenseLayer(Input, nd, W=Normal(0.02), nonlinearity=relu)
print ("Dis fc0:", dis0.output_shape)
if GP_norm is True:
dis1 = DenseLayer(dis0, nd, W=Normal(0.02), nonlinearity=relu)
else:
dis1 = batch_norm(DenseLayer(dis0, nd, W=Normal(0.02), nonlinearity=relu))
print ("Dis fc1:", dis1.output_shape)
if GP_norm is True:
dis2 = batch_norm(DenseLayer(dis1, nd, W=Normal(0.02), nonlinearity=relu))
else:
dis2 = DenseLayer(dis1, nd, W=Normal(0.02), nonlinearity=relu)
print ("Dis fc2:", dis2.output_shape)
disout = DenseLayer(dis2, 1, W=Normal(0.02), nonlinearity=sigmoid)
print ("Dis output:", disout.output_shape)
return disout
示例2: build_generator_32
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [as 别名]
def build_generator_32(noise=None, ngf=128):
# noise input
InputNoise = InputLayer(shape=(None, 100), input_var=noise)
#FC Layer
gnet0 = DenseLayer(InputNoise, ngf*4*4*4, W=Normal(0.02), nonlinearity=relu)
print ("Gen fc1:", gnet0.output_shape)
#Reshape Layer
gnet1 = ReshapeLayer(gnet0,([0],ngf*4,4,4))
print ("Gen rs1:", gnet1.output_shape)
# DeConv Layer
gnet2 = Deconv2DLayer(gnet1, ngf*2, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=relu)
print ("Gen deconv1:", gnet2.output_shape)
# DeConv Layer
gnet3 = Deconv2DLayer(gnet2, ngf, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=relu)
print ("Gen deconv2:", gnet3.output_shape)
# DeConv Layer
gnet4 = Deconv2DLayer(gnet3, 3, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=tanh)
print ("Gen output:", gnet4.output_shape)
return gnet4
示例3: build_discriminator_32
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [as 别名]
def build_discriminator_32(image=None,ndf=128):
lrelu = LeakyRectify(0.2)
# input: images
InputImg = InputLayer(shape=(None, 3, 32, 32), input_var=image)
print ("Dis Img_input:", InputImg.output_shape)
# Conv Layer
dis1 = Conv2DLayer(InputImg, ndf, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu)
print ("Dis conv1:", dis1.output_shape)
# Conv Layer
dis2 = batch_norm(Conv2DLayer(dis1, ndf*2, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu))
print ("Dis conv2:", dis2.output_shape)
# Conv Layer
dis3 = batch_norm(Conv2DLayer(dis2, ndf*4, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu))
print ("Dis conv3:", dis3.output_shape)
# Conv Layer
dis4 = DenseLayer(dis3, 1, W=Normal(0.02), nonlinearity=sigmoid)
print ("Dis output:", dis4.output_shape)
return dis4
示例4: build_generator_64
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [as 别名]
def build_generator_64(noise=None, ngf=128):
# noise input
InputNoise = InputLayer(shape=(None, 100), input_var=noise)
#FC Layer
gnet0 = DenseLayer(InputNoise, ngf*8*4*4, W=Normal(0.02), nonlinearity=relu)
print ("Gen fc1:", gnet0.output_shape)
#Reshape Layer
gnet1 = ReshapeLayer(gnet0,([0],ngf*8,4,4))
print ("Gen rs1:", gnet1.output_shape)
# DeConv Layer
gnet2 = Deconv2DLayer(gnet1, ngf*8, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=relu)
print ("Gen deconv2:", gnet2.output_shape)
# DeConv Layer
gnet3 = Deconv2DLayer(gnet2, ngf*4, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=relu)
print ("Gen deconv3:", gnet3.output_shape)
# DeConv Layer
gnet4 = Deconv2DLayer(gnet3, ngf*4, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=relu)
print ("Gen deconv4:", gnet4.output_shape)
# DeConv Layer
gnet5 = Deconv2DLayer(gnet4, ngf*2, (4,4), (2,2), crop=1, W=Normal(0.02),nonlinearity=relu)
print ("Gen deconv5:", gnet5.output_shape)
# DeConv Layer
gnet6 = Deconv2DLayer(gnet5, 3, (3,3), (1,1), crop='same', W=Normal(0.02),nonlinearity=tanh)
print ("Gen output:", gnet6.output_shape)
return gnet6
示例5: build_discriminator_128
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [as 别名]
def build_discriminator_128(image=None,ndf=128):
lrelu = LeakyRectify(0.2)
# input: images
InputImg = InputLayer(shape=(None, 3, 128, 128), input_var=image)
print ("Dis Img_input:", InputImg.output_shape)
# Conv Layer
dis1 = Conv2DLayer(InputImg, ndf, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu)
print ("Dis conv1:", dis1.output_shape)
# Conv Layer
dis2 = batch_norm(Conv2DLayer(dis1, ndf*2, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu))
print ("Dis conv2:", dis2.output_shape)
# Conv Layer
dis3 = batch_norm(Conv2DLayer(dis2, ndf*4, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu))
print ("Dis conv3:", dis3.output_shape)
# Conv Layer
dis4 = batch_norm(Conv2DLayer(dis3, ndf*8, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu))
print ("Dis conv3:", dis4.output_shape)
# Conv Layer
dis5 = batch_norm(Conv2DLayer(dis4, ndf*16, (4,4), (2,2), pad=1, W=Normal(0.02), nonlinearity=lrelu))
print ("Dis conv4:", dis5.output_shape)
# Conv Layer
dis6 = DenseLayer(dis5, 1, W=Normal(0.02), nonlinearity=sigmoid)
print ("Dis output:", dis6.output_shape)
return dis6
示例6: network_classifier
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [as 别名]
def network_classifier(self, input_var):
network = {}
network['classifier/input'] = InputLayer(shape=(None, 3, 64, 64), input_var=input_var, name='classifier/input')
network['classifier/conv1'] = Conv2DLayer(network['classifier/input'], num_filters=32, filter_size=3, stride=1, pad='valid', nonlinearity=rectify, name='classifier/conv1')
network['classifier/pool1'] = MaxPool2DLayer(network['classifier/conv1'], pool_size=2, stride=2, pad=0, name='classifier/pool1')
network['classifier/conv2'] = Conv2DLayer(network['classifier/pool1'], num_filters=32, filter_size=3, stride=1, pad='valid', nonlinearity=rectify, name='classifier/conv2')
network['classifier/pool2'] = MaxPool2DLayer(network['classifier/conv2'], pool_size=2, stride=2, pad=0, name='classifier/pool2')
network['classifier/conv3'] = Conv2DLayer(network['classifier/pool2'], num_filters=32, filter_size=3, stride=1, pad='valid', nonlinearity=rectify, name='classifier/conv3')
network['classifier/pool3'] = MaxPool2DLayer(network['classifier/conv3'], pool_size=2, stride=2, pad=0, name='classifier/pool3')
network['classifier/conv4'] = Conv2DLayer(network['classifier/pool3'], num_filters=32, filter_size=3, stride=1, pad='valid', nonlinearity=rectify, name='classifier/conv4')
network['classifier/pool4'] = MaxPool2DLayer(network['classifier/conv4'], pool_size=2, stride=2, pad=0, name='classifier/pool4')
network['classifier/dense1'] = DenseLayer(network['classifier/pool4'], num_units=64, nonlinearity=rectify, name='classifier/dense1')
network['classifier/output'] = DenseLayer(network['classifier/dense1'], num_units=10, nonlinearity=softmax, name='classifier/output')
return network
示例7: setup_transform_net
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [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
示例8: __init__
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [as 别名]
def __init__(self, input_shape, output_dim, servoing_pol,
name=None, input_var=None):
if name is None:
prefix = ""
else:
prefix = name + "_"
if len(input_shape) == 3:
l_in = L.InputLayer(shape=(None, np.prod(input_shape)), input_var=input_var)
l_hid = L.reshape(l_in, ([0],) + input_shape)
elif len(input_shape) == 2:
l_in = L.InputLayer(shape=(None, np.prod(input_shape)), input_var=input_var)
input_shape = (1,) + input_shape
l_hid = L.reshape(l_in, ([0],) + input_shape)
else:
l_in = L.InputLayer(shape=(None,) + input_shape, input_var=input_var)
l_hid = l_in
l_out = TheanoServoingPolicyLayer(l_hid, servoing_pol)
self._l_in = l_in
self._l_out = l_out
self._input_var = l_in.input_var
示例9: test_conv2d
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [as 别名]
def test_conv2d(x_shape, num_filters, filter_size, flip_filters, batch_size=2):
X_var = T.tensor4('X')
l_x = L.InputLayer(shape=(None,) + x_shape, input_var=X_var, name='x')
X = np.random.random((batch_size,) + x_shape).astype(theano.config.floatX)
l_conv = L.Conv2DLayer(l_x, num_filters, filter_size=filter_size, stride=1, pad='same',
flip_filters=flip_filters, untie_biases=True, nonlinearity=None, b=None)
conv_var = L.get_output(l_conv)
conv_fn = theano.function([X_var], conv_var)
tic()
conv = conv_fn(X)
toc("conv time for x_shape=%r, num_filters=%r, filter_size=%r, flip_filters=%r, batch_size=%r\n\t" %
(x_shape, num_filters, filter_size, flip_filters, batch_size))
tic()
loop_conv = conv2d(X, l_conv.W.get_value(), flip_filters=flip_filters)
toc("loop conv time for x_shape=%r, num_filters=%r, filter_size=%r, flip_filters=%r, batch_size=%r\n\t" %
(x_shape, num_filters, filter_size, flip_filters, batch_size))
assert np.allclose(conv, loop_conv, atol=1e-6)
示例10: test_locally_connected2d
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [as 别名]
def test_locally_connected2d(x_shape, num_filters, filter_size, flip_filters, batch_size=2):
X_var = T.tensor4('X')
l_x = L.InputLayer(shape=(None,) + x_shape, input_var=X_var, name='x')
X = np.random.random((batch_size,) + x_shape).astype(theano.config.floatX)
l_conv = LT.LocallyConnected2DLayer(l_x, num_filters, filter_size=filter_size, stride=1, pad='same',
flip_filters=flip_filters, untie_biases=True, nonlinearity=None, b=None)
conv_var = L.get_output(l_conv)
conv_fn = theano.function([X_var], conv_var)
tic()
conv = conv_fn(X)
toc("locally connected time for x_shape=%r, num_filters=%r, filter_size=%r, flip_filters=%r, batch_size=%r\n\t" %
(x_shape, num_filters, filter_size, flip_filters, batch_size))
tic()
loop_conv = locally_connected2d(X, l_conv.W.get_value(), flip_filters=flip_filters)
toc("loop locally connected time for x_shape=%r, num_filters=%r, filter_size=%r, flip_filters=%r, batch_size=%r\n\t" %
(x_shape, num_filters, filter_size, flip_filters, batch_size))
assert np.allclose(conv, loop_conv, atol=1e-6)
示例11: test_channelwise_locally_connected2d
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [as 别名]
def test_channelwise_locally_connected2d(x_shape, filter_size, flip_filters, batch_size=2):
X_var = T.tensor4('X')
l_x = L.InputLayer(shape=(None,) + x_shape, input_var=X_var, name='x')
X = np.random.random((batch_size,) + x_shape).astype(theano.config.floatX)
l_conv = LT.LocallyConnected2DLayer(l_x, x_shape[0], filter_size=filter_size, channelwise=True,
stride=1, pad='same', flip_filters=flip_filters,
untie_biases=True, nonlinearity=None, b=None)
conv_var = L.get_output(l_conv)
conv_fn = theano.function([X_var], conv_var)
tic()
conv = conv_fn(X)
toc("channelwise locally connected time for x_shape=%r, filter_size=%r, flip_filters=%r, batch_size=%r\n\t" %
(x_shape, filter_size, flip_filters, batch_size))
tic()
loop_conv = channelwise_locally_connected2d(X, l_conv.W.get_value(), flip_filters=flip_filters)
toc("loop channelwise locally connected time for x_shape=%r, filter_size=%r, flip_filters=%r, batch_size=%r\n\t" %
(x_shape, filter_size, flip_filters, batch_size))
assert np.allclose(conv, loop_conv, atol=1e-7)
示例12: build_bilinear_net
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [as 别名]
def build_bilinear_net(input_shapes, X_var=None, U_var=None, X_diff_var=None, axis=1):
x_shape, u_shape = input_shapes
X_var = X_var or T.tensor4('X')
U_var = U_var or T.matrix('U')
X_diff_var = X_diff_var or T.tensor4('X_diff')
X_next_var = X_var + X_diff_var
l_x = L.InputLayer(shape=(None,) + x_shape, input_var=X_var)
l_u = L.InputLayer(shape=(None,) + u_shape, input_var=U_var)
l_x_diff_pred = LT.BilinearLayer([l_x, l_u], axis=axis)
l_x_next_pred = L.ElemwiseMergeLayer([l_x, l_x_diff_pred], T.add)
l_y = L.flatten(l_x)
l_y_diff_pred = L.flatten(l_x_diff_pred)
X_next_pred_var = lasagne.layers.get_output(l_x_next_pred)
loss = ((X_next_var - X_next_pred_var) ** 2).mean(axis=0).sum() / 2.
net_name = 'BilinearNet'
input_vars = OrderedDict([(var.name, var) for var in [X_var, U_var, X_diff_var]])
pred_layers = OrderedDict([('y_diff_pred', l_y_diff_pred), ('y', l_y), ('x0_next_pred', l_x_next_pred)])
return net_name, input_vars, pred_layers, loss
示例13: build_model
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [as 别名]
def build_model(self):
'''
Build Acoustic Event Net model
:return:
'''
# A architecture 41 classes
nonlin = lasagne.nonlinearities.rectify
net = {}
net['input'] = InputLayer((None, feat_shape[0], feat_shape[1], feat_shape[2])) # channel, time. frequency
# ----------- 1st layer group ---------------
net['conv1a'] = ConvLayer(net['input'], num_filters=64, filter_size=(3, 3), stride=1, nonlinearity=nonlin)
net['conv1b'] = ConvLayer(net['conv1a'], num_filters=64, filter_size=(3, 3), stride=1, nonlinearity=nonlin)
net['pool1'] = MaxPool2DLayer(net['conv1b'], pool_size=(1, 2)) # (time, freq)
# ----------- 2nd layer group ---------------
net['conv2a'] = ConvLayer(net['pool1'], num_filters=128, filter_size=(3, 3), stride=1, nonlinearity=nonlin)
net['conv2b'] = ConvLayer(net['conv2a'], num_filters=128, filter_size=(3, 3), stride=1, nonlinearity=nonlin)
net['pool2'] = MaxPool2DLayer(net['conv2b'], pool_size=(2, 2)) # (time, freq)
# ----------- fully connected layer group ---------------
net['fc5'] = DenseLayer(net['pool2'], num_units=1024, nonlinearity=nonlin)
net['fc6'] = DenseLayer(net['fc5'], num_units=1024, nonlinearity=nonlin)
net['prob'] = DenseLayer(net['fc6'], num_units=41, nonlinearity=lasagne.nonlinearities.softmax)
return net
示例14: __init__
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [as 别名]
def __init__(self):
self.network = collections.OrderedDict()
self.network['img'] = InputLayer((None, 3, None, None))
self.network['seed'] = InputLayer((None, 3, None, None))
config, params = self.load_model()
self.setup_generator(self.last_layer(), config)
if args.train:
concatenated = lasagne.layers.ConcatLayer([self.network['img'], self.network['out']], axis=0)
self.setup_perceptual(concatenated)
self.load_perceptual()
self.setup_discriminator()
self.load_generator(params)
self.compile()
#------------------------------------------------------------------------------------------------------------------
# Network Configuration
#------------------------------------------------------------------------------------------------------------------
示例15: OrthoInitRecurrent
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import InputLayer [as 别名]
def OrthoInitRecurrent(input_var, mask_var=None, batch_size=1, n_in=100, n_out=1, n_hid=200, init_val=0.9, out_nlin=lasagne.nonlinearities.linear):
# Input Layer
l_in = InputLayer((batch_size, None, n_in), input_var=input_var)
if mask_var==None:
l_mask=None
else:
l_mask = InputLayer((batch_size, None), input_var=mask_var)
_, seqlen, _ = l_in.input_var.shape
l_in_hid = DenseLayer(lasagne.layers.InputLayer((None, n_in)), n_hid, W=lasagne.init.GlorotNormal(0.95), nonlinearity=lasagne.nonlinearities.linear)
l_hid_hid = DenseLayer(lasagne.layers.InputLayer((None, n_hid)), n_hid, W=lasagne.init.Orthogonal(gain=init_val), nonlinearity=lasagne.nonlinearities.linear)
l_rec = lasagne.layers.CustomRecurrentLayer(l_in, l_in_hid, l_hid_hid, nonlinearity=lasagne.nonlinearities.tanh, mask_input=l_mask, grad_clipping=100)
# Output Layer
l_shp = ReshapeLayer(l_rec, (-1, n_hid))
l_dense = DenseLayer(l_shp, num_units=n_out, W=lasagne.init.GlorotNormal(0.95), nonlinearity=out_nlin)
# To reshape back to our original shape, we can use the symbolic shape variables we retrieved above.
l_out = ReshapeLayer(l_dense, (batch_size, seqlen, n_out))
return l_out, l_rec