Skip to content

Commit

Permalink
get_layer
Browse files Browse the repository at this point in the history
  • Loading branch information
pchavanne committed Dec 12, 2016
1 parent ea7a28f commit 23a1d1e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/user/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ We now create each layers of the network by implementing :class:`yadll.layers` c
The first layers must be a :class:`yadll.layers.Input` that give the shape of the input data.
This network will be a mlp with two dense layer with rectified linear unit activation and dropout.
Each layer receive as `incoming` the previous layer.
Each layer has a name. You can provide it or it will be, by default, the name of the layer class, space, the number of
the instantiation.
The last layer is a :class:`yadll.layers.LogisticRegression` which is a dense layer with softmax activation.
Layers names are optional.

Expand Down
3 changes: 2 additions & 1 deletion yadll/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class Layer(object):
incoming : a `Layer` or a `tuple` of `int`
The incoming layer or shape if input layer
name : `string`, optional
The layer name.
The layer name. default name is the class name
plus instantiation number i.e: 'DenseLayer 3'
"""
nb_instances = 0
Expand Down
22 changes: 21 additions & 1 deletion yadll/network.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: UTF-8 -*-
from collections import OrderedDict
import cPickle
import yadll

from .layers import *

import logging
Expand Down Expand Up @@ -33,6 +34,7 @@ class Network(object):
"""
def __init__(self, name=None, layers=None):
self.layers = []
self.layer_names = []
self.params = []
self.reguls = 0
self.has_unsupervised_layer = False
Expand All @@ -51,6 +53,7 @@ def add(self, layer):
"""
self.layers.append(layer)
self.layer_names.append(layer.name)
self.params.extend(layer.params)
self.reguls += layer.reguls
if isinstance(layer, UnsupervisedLayer):
Expand All @@ -68,6 +71,23 @@ def get_output(self, **kwargs):
"""
return self.layers[-1].get_output(**kwargs)

def get_layer(self, layer_name):
"""
Get a layer of the network from its name
Parameters
----------
layer_name : `string`
name of the layer requested
Returns
-------
yaddl.layers object
a yadll layer object in the
"""
return self.layers[self.layer_names.index(layer_name)]

def save_params(self, file):
"""
Save the parameters of the network to file with cPickle
Expand Down

0 comments on commit 23a1d1e

Please sign in to comment.