本文整理汇总了Python中lasagne.layers.get_all_layers方法的典型用法代码示例。如果您正苦于以下问题:Python layers.get_all_layers方法的具体用法?Python layers.get_all_layers怎么用?Python layers.get_all_layers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lasagne.layers
的用法示例。
在下文中一共展示了layers.get_all_layers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: example2
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def example2():
""" Two branches"""
# Input
l_in = lasagne.layers.InputLayer((100, 1, 20, 20))
# Branch one
l_conv1 = lasagne.layers.Conv2DLayer(l_in, num_filters=32, filter_size=(5, 5))
l_pool1 = lasagne.layers.MaxPool2DLayer(l_conv1, pool_size=(2, 2))
l_dense1 = lasagne.layers.DenseLayer(l_pool1, num_units=20)
# Branch two
l_conv2 = lasagne.layers.Conv2DLayer(l_in, num_filters=32, filter_size=(5, 5))
l_pool2 = lasagne.layers.MaxPool2DLayer(l_conv2, pool_size=(2, 2))
l_dense2 = lasagne.layers.DenseLayer(l_pool2, num_units=20)
# Merge
l_concat = lasagne.layers.ConcatLayer((l_dense1, l_dense2))
# Output
l_out = lasagne.layers.DenseLayer(l_concat, num_units=10)
layers = get_all_layers(l_out)
print(get_network_str(layers, get_network=False, incomings=True, outgoings=True))
return None
示例2: loadModel
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def loadModel(filename):
print "IMPORTING MODEL PARAMS...",
net_filename = MODEL_PATH + filename
with open(net_filename, 'rb') as f:
data = pickle.load(f)
#for training, we only want to load the model params
net = data['net']
params = l.get_all_param_values(net)
if LOAD_OUTPUT_LAYER:
l.set_all_param_values(NET, params)
else:
l.set_all_param_values(l.get_all_layers(NET)[:-1], params[:-2])
print "DONE!"
示例3: loadPretrained
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def loadPretrained(net):
if cfg.MODEL_NAME:
# Load saved model
n, c = io.loadModel(cfg.MODEL_NAME)
# Set params
params = l.get_all_param_values(n)
if cfg.LOAD_OUTPUT_LAYER:
l.set_all_param_values(net, params)
else:
l.set_all_param_values(l.get_all_layers(net)[:-1], params[:-2])
return net
#################### LOSS FUNCTION ######################
示例4: train_function
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def train_function(net):
# We use dynamic learning rates which change after some epochs
lr_dynamic = T.scalar(name='learning_rate')
# Theano variable for the class targets
targets = T.matrix('targets', dtype=theano.config.floatX)
# Get the network output
prediction = l.get_output(net)
# The theano train functions takes images and class targets as input
log.i("COMPILING TRAIN FUNCTION...", new_line=False)
start = time.time()
loss = loss_function(net, prediction, targets)
updates = net_updates(net, loss, lr_dynamic)
train_net = theano.function([l.get_all_layers(net)[0].input_var, targets, lr_dynamic], loss, updates=updates, allow_input_downcast=True)
log.i(("DONE! (", int(time.time() - start), "s )"))
return train_net
################# PREDICTION FUNCTION ####################
示例5: test_function
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def test_function(net, hasTargets=True, layer_index=-1):
# We need the prediction function to calculate the validation accuracy
# this way we can test the net during/after training
# We need a version with targets and one without
prediction = l.get_output(l.get_all_layers(net)[layer_index], deterministic=True)
log.i("COMPILING TEST FUNCTION...", new_line=False)
start = time.time()
if hasTargets:
# Theano variable for the class targets
targets = T.matrix('targets', dtype=theano.config.floatX)
loss = loss_function(net, prediction, targets)
accuracy = accuracy_function(net, prediction, targets)
test_net = theano.function([l.get_all_layers(net)[0].input_var, targets], [prediction, loss, accuracy], allow_input_downcast=True)
else:
test_net = theano.function([l.get_all_layers(net)[0].input_var], prediction, allow_input_downcast=True)
log.i(("DONE! (", int(time.time() - start), "s )"))
return test_net
示例6: get_objective
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def get_objective(l1=0.0, l2=0.0005):
class RegularizedObjective(Objective):
def get_loss(self, input=None, target=None, aggregation=None,
deterministic=False, **kwargs):
l1_layer = get_all_layers(self.input_layer)[1]
loss = super(RegularizedObjective, self).get_loss(
input=input, target=target, aggregation=aggregation,
deterministic=deterministic, **kwargs)
if not deterministic:
return loss \
+ l1 * lasagne.regularization.regularize_layer_params(
l1_layer, lasagne.regularization.l1) \
+ l2 * lasagne.regularization.regularize_network_params(
self.input_layer, lasagne.regularization.l2)
else:
return loss
return RegularizedObjective
示例7: _build
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def _build(self, forget_bias=5.0, grad_clip=10.0):
"""Build architecture
"""
network = InputLayer(shape=(None, self.seq_length, self.input_size),
name='input')
self.input_var = network.input_var
# Hidden layers
tanh = lasagne.nonlinearities.tanh
gate, constant = lasagne.layers.Gate, lasagne.init.Constant
for _ in range(self.depth):
network = LSTMLayer(network, self.width, nonlinearity=tanh,
grad_clipping=grad_clip,
forgetgate=gate(b=constant(forget_bias)))
# Retain last-output state
network = SliceLayer(network, -1, 1)
# Output layer
sigmoid = lasagne.nonlinearities.sigmoid
loc_layer = DenseLayer(network, self.num_outputs * 2)
conf_layer = DenseLayer(network, self.num_outputs,
nonlinearity=sigmoid)
# Grab all layers into DAPs instance
self.network = get_all_layers([loc_layer, conf_layer])
# Get theano expression for outputs of DAPs model
self.loc_var, self.conf_var = get_output([loc_layer, conf_layer],
deterministic=True)
示例8: getPredictionFuntion
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def getPredictionFuntion(net):
net_output = l.get_output(net, deterministic=True)
print "COMPILING THEANO TEST FUNCTION...",
start = time.time()
test_net = theano.function([l.get_all_layers(NET)[0].input_var], net_output, allow_input_downcast=True)
print "DONE! (", int(time.time() - start), "s )"
return test_net
################# PREDICTION POOLING ####################
示例9: classificationBranch
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def classificationBranch(net, kernel_size):
# Post Convolution
branch = l.batch_norm(l.Conv2DLayer(net,
num_filters=int(FILTERS[-1] * RESNET_K),
filter_size=kernel_size,
nonlinearity=nl.rectify))
#log.p(("\t\tPOST CONV SHAPE:", l.get_output_shape(branch), "LAYER:", len(l.get_all_layers(branch)) - 1))
# Dropout Layer
branch = l.DropoutLayer(branch)
# Dense Convolution
branch = l.batch_norm(l.Conv2DLayer(branch,
num_filters=int(FILTERS[-1] * RESNET_K * 2),
filter_size=1,
nonlinearity=nl.rectify))
#log.p(("\t\tDENSE CONV SHAPE:", l.get_output_shape(branch), "LAYER:", len(l.get_all_layers(branch)) - 1))
# Dropout Layer
branch = l.DropoutLayer(branch)
# Class Convolution
branch = l.Conv2DLayer(branch,
num_filters=len(cfg.CLASSES),
filter_size=1,
nonlinearity=None)
return branch
示例10: test_function
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def test_function(net, layer_index=-1):
log.p('COMPILING THEANO TEST FUNCTION FUNCTION...', new_line=False)
prediction = l.get_output(l.get_all_layers(net)[layer_index], deterministic=True)
test_function = theano.function([l.get_all_layers(net)[0].input_var], prediction, allow_input_downcast=True)
log.p('DONE!')
return test_function
示例11: get_equivalent_input_padding
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def get_equivalent_input_padding(layer, layers_args=[]):
"""Compute the equivalent padding in the input layer
A function to compute the equivalent padding of a sequence of
convolutional and pooling layers. It memorizes the padding
of all the Layers up to the first InputLayer.
It then computes what would be the equivalent padding in the Layer
immediately before the chain of Layers that is being taken into account.
"""
# Initialize the DynamicPadding layers
lasagne.layers.get_output(layer)
# Loop through conv and pool to collect data
all_layers = get_all_layers(layer)
# while(not isinstance(layer, (InputLayer))):
for layer in all_layers:
# Note: stride is numerical, but pad *could* be symbolic
try:
pad, stride = (layer.pad, layer.stride)
if isinstance(pad, int):
pad = pad, pad
if isinstance(stride, int):
stride = stride, stride
layers_args.append((pad, stride))
except(AttributeError):
pass
# Loop backward to compute the equivalent padding in the input
# layer
tot_pad = T.zeros(2)
pad_factor = T.ones(2)
while(layers_args):
pad, stride = layers_args.pop()
tot_pad += pad * pad_factor
pad_factor *= stride
return tot_pad
示例12: loadParams
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def loadParams(epoch, filename=None):
print "IMPORTING MODEL PARAMS...",
net_filename = MODEL_PATH + filename
with open(net_filename, 'rb') as f:
params = pickle.load(f)
if LOAD_OUTPUT_LAYER:
l.set_all_param_values(NET, params)
else:
l.set_all_param_values(l.get_all_layers(NET)[:-1], params[:-2])
print "DONE!"
################ PREDICTION SAVE/LOAD ##################
示例13: getPredictionFuntion
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def getPredictionFuntion(net):
net_output = l.get_output(net, deterministic=True)
print "COMPILING THEANO TEST FUNCTION...",
start = time.time()
test_net = theano.function([l.get_all_layers(net)[0].input_var], net_output, allow_input_downcast=True)
print "DONE! (", int(time.time() - start), "s )"
return test_net
################# PREDICTION POOLING ####################
示例14: getPredictionFuntion
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def getPredictionFuntion(net):
net_output = l.get_output(net, deterministic=True)
print "COMPILING THEANO TEST FUNCTION...",
start = time.time()
test_net = theano.function([l.get_all_layers(NET)[0].input_var], net_output, allow_input_downcast=True)
print "DONE! (", int(time.time() - start), "s )"
return test_net
示例15: loadParams
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_layers [as 别名]
def loadParams(epoch, filename=None):
print "IMPORTING MODEL PARAMS...",
if filename == None:
net_filename = MODEL_PATH + "birdCLEF_" + RUN_NAME + "_model_params_epoch_" + str(epoch) + ".pkl"
else:
net_filename = MODEL_PATH + filename
with open(net_filename, 'rb') as f:
params = pickle.load(f)
if LOAD_OUTPUT_LAYER:
l.set_all_param_values(NET, params)
else:
l.set_all_param_values(l.get_all_layers(NET)[:-1], params[:-2])
print "DONE!"