from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D
from tensorflow.keras.layers import MaxPooling2D
from tensorflow.keras.layers import Activation
from tensorflow.keras.layers import Flatten
from tensorflow.keras.layers import Dense
from tensorflow.keras import backend as K


class LeNet:
    @staticmethod
    def build(width, height, depth, classes, last_active="softmax"):
        # Initialize the model
        model = Sequential()
        input_shape = (height, width, depth)

        # If we are using 'channels-first', update the input shape
        if K.image_data_format() == 'channels_first':
            input_shape = (depth, height, width)

        # First set of CONV => RELU => POOL layers
        model.add(Conv2D(20, (5, 5), padding='same', input_shape=input_shape))
        model.add(Activation('relu'))
        model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))

        # Second set of CONV => RELU => POOL layers
        model.add(Conv2D(50, (5, 5), padding='same'))
        model.add(Activation('relu'))
        model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))

        # First (and only) set of FC => RELU layers
        model.add(Flatten())
        model.add(Dense(500))
        model.add(Activation('relu'))

        model.add(Dense(classes))
        model.add(Activation(last_active))
            
        # return the constructed network architecture
        return model

tensorflow.keras.layers.Activation tensorflow.keras.backend.image_data_format tensorflow.keras.layers.Dense tensorflow.keras.layers.Conv2D tensorflow.keras.layers.MaxPooling2D tensorflow.keras.models.Sequential tensorflow.keras.layers.Flatten
[(14, 'tensorflow.keras.models.Sequential', 'Sequential', ([], {}), False, 'from tensorflow.keras.models import Sequential\n'), (18, 'tensorflow.keras.backend.image_data_format', 'K.image_data_format', ([], {}), True, 'from tensorflow.keras import backend as K\n'), (22, 'tensorflow.keras.layers.Conv2D', 'Conv2D', (['(20)', '(5, 5)'], {'padding': '"""same"""', 'input_shape': 'input_shape'}), False, 'from tensorflow.keras.layers import Conv2D\n'), (23, 'tensorflow.keras.layers.Activation', 'Activation', (['"""relu"""'], {}), False, 'from tensorflow.keras.layers import Activation\n'), (24, 'tensorflow.keras.layers.MaxPooling2D', 'MaxPooling2D', ([], {'pool_size': '(2, 2)', 'strides': '(2, 2)'}), False, 'from tensorflow.keras.layers import MaxPooling2D\n'), (27, 'tensorflow.keras.layers.Conv2D', 'Conv2D', (['(50)', '(5, 5)'], {'padding': '"""same"""'}), False, 'from tensorflow.keras.layers import Conv2D\n'), (28, 'tensorflow.keras.layers.Activation', 'Activation', (['"""relu"""'], {}), False, 'from tensorflow.keras.layers import Activation\n'), (29, 'tensorflow.keras.layers.MaxPooling2D', 'MaxPooling2D', ([], {'pool_size': '(2, 2)', 'strides': '(2, 2)'}), False, 'from tensorflow.keras.layers import MaxPooling2D\n'), (32, 'tensorflow.keras.layers.Flatten', 'Flatten', ([], {}), False, 'from tensorflow.keras.layers import Flatten\n'), (33, 'tensorflow.keras.layers.Dense', 'Dense', (['(500)'], {}), False, 'from tensorflow.keras.layers import Dense\n'), (34, 'tensorflow.keras.layers.Activation', 'Activation', (['"""relu"""'], {}), False, 'from tensorflow.keras.layers import Activation\n'), (36, 'tensorflow.keras.layers.Dense', 'Dense', (['classes'], {}), False, 'from tensorflow.keras.layers import Dense\n'), (37, 'tensorflow.keras.layers.Activation', 'Activation', (['last_active'], {}), False, 'from tensorflow.keras.layers import Activation\n')]