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

Raises:

Type Description
ValueError

Length of input_shape is not 3.

ValueError

input_shape[0] or input_shape[1] is smaller than 18.

Returns:

Type Description
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.

    Raises:
        ValueError: Length of `input_shape` is not 3.
        ValueError: `input_shape`[0] or `input_shape`[1] is smaller than 18.

    Returns:
        A TensorFlow LeNet model.
    """
    _check_input_shape(input_shape)
    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