Layer.py 1.51 KB
Newer Older
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
1 2 3 4 5
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# @author: Tiago de Freitas Pereira <tiago.pereira@idiap.ch>
# @date: Wed 11 May 2016 17:38 CEST

6
import tensorflow as tf
7 8
from bob.learn.tensorflow.initialization import Xavier
from bob.learn.tensorflow.initialization import Constant
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
9 10 11 12 13 14 15 16


class Layer(object):

    """
    Layer base class
    """

17 18 19 20 21 22
    def __init__(self, name,
                 activation=None,
                 weights_initialization=Xavier(),
                 bias_initialization=Constant(),
                 use_gpu=False,
                 seed=10):
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
23 24 25 26
        """
        Base constructor

        **Parameters**
27 28
          name: Name of the layer
          activation: Tensorflow activation operation (https://www.tensorflow.org/versions/r0.10/api_docs/python/nn.html)
29 30
          weights_initialization: Initialization for the weights
          bias_initialization: Initialization for the biases
31 32
          use_gpu: I think this is not necessary to explain
          seed: Initialization seed set in Tensor flow
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
33
        """
34
        self.name = name
35 36
        self.weights_initialization = weights_initialization
        self.bias_initialization = bias_initialization
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
37 38 39
        self.use_gpu = use_gpu
        self.seed = seed

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
40 41
        self.input_layer = None
        self.activation = activation
42

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
43
    def create_variables(self, input_layer):
44 45
        NotImplementedError("Please implement this function in derived classes")

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
46 47
    def get_graph(self):
        NotImplementedError("Please implement this function in derived classes")