Lenet.py 1.53 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 11
#!/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
"""

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


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

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

                 conv2_kernel_size=5,
                 conv2_output=32,

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

                 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
        """
45
        super(Lenet, self).__init__(feature_layer=feature_layer)
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))