Lenet.py 1.59 KB
Newer Older
Tiago de Freitas Pereira's avatar
Scratch  
Tiago de Freitas Pereira committed
1 2 3 4 5 6 7 8 9 10
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# @author: Tiago de Freitas Pereira <tiago.pereira@idiap.ch>
# @date: Wed 11 May 2016 09:39:36 CEST 

"""
Class that creates the lenet architecture
"""

import tensorflow as tf
11 12
from .SequenceNetwork import SequenceNetwork
from ..layers import Conv2D, FullyConnected, MaxPooling
13
import bob.learn.tensorflow
Tiago de Freitas Pereira's avatar
Scratch  
Tiago de Freitas Pereira committed
14

15
class Lenet(SequenceNetwork):
Tiago de Freitas Pereira's avatar
Scratch  
Tiago de Freitas Pereira committed
16 17 18 19 20 21 22 23 24 25

    def __init__(self,
                 conv1_kernel_size=5,
                 conv1_output=16,

                 conv2_kernel_size=5,
                 conv2_output=32,

                 fc1_output=400,
                 n_classes=10,
26
                 default_feature_layer="fc2",
Tiago de Freitas Pereira's avatar
Scratch  
Tiago de Freitas Pereira committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

                 seed=10, use_gpu = False):
        """
        Create all the necessary variables for this CNN

        **Parameters**
            conv1_kernel_size=5,
            conv1_output=32,

            conv2_kernel_size=5,
            conv2_output=64,

            fc1_output=400,
            n_classes=10

            seed = 10
        """
44
        super(Lenet, self).__init__(default_feature_layer=default_feature_layer)
45

46 47
        self.add(Conv2D(name="conv1", kernel_size=conv1_kernel_size,
                        filters=conv1_output, activation=tf.nn.tanh))
48
        self.add(MaxPooling(name="pooling1"))
49
        self.add(Conv2D(name="conv2", kernel_size=conv2_kernel_size, filters=conv2_output, activation=tf.nn.tanh))
50
        self.add(MaxPooling(name="pooling2"))
51
        self.add(FullyConnected(name="fc1", output_dim=fc1_output, activation=tf.nn.tanh))
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
52
        self.add(FullyConnected(name="fc2", output_dim=n_classes, activation=None))