Skip to content

lenet

LeNet

A standard LeNet implementation in TensorFlow.

The LeNet model has 3 convolution layers and 2 dense layers.

Parameters:

Name Type Description Default
input_shape Tuple[int, int, int]

shape of the input data (height, width, channels).

(28, 28, 1)
classes int

The number of outputs the model should generate.

10

Returns:

Type Description
tf.keras.Model

A TensorFlow LeNet model.

Source code in fastestimator\fastestimator\architecture\tensorflow\lenet.py
def LeNet(input_shape: Tuple[int, int, int] = (28, 28, 1), classes: int = 10) -> tf.keras.Model:
    """A standard LeNet implementation in TensorFlow.

    The LeNet model has 3 convolution layers and 2 dense layers.

    Args:
        input_shape: shape of the input data (height, width, channels).
        classes: The number of outputs the model should generate.

    Returns:
        A TensorFlow LeNet model.
    """
    model = Sequential()
    model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=input_shape))
    model.add(layers.MaxPooling2D((2, 2)))
    model.add(layers.Conv2D(64, (3, 3), activation='relu'))
    model.add(layers.MaxPooling2D((2, 2)))
    model.add(layers.Conv2D(64, (3, 3), activation='relu'))
    model.add(layers.Flatten())
    model.add(layers.Dense(64, activation='relu'))
    model.add(layers.Dense(classes, activation='softmax'))
    return model