'How to reduce the size of neural network model file in keras? To deploy to OpenMV

I need to train a picture classification model with 15 categories. Because it needs to be deployed to OpenMV, the model size cannot exceed 1M, otherwise it cannot be loaded by openmv. I used the trained model mobilenetv2. As in the example on Keras's website, I placed the convolution basis of mobilenetv2 at the bottom of my model, and then added a softmax activated dense layer at the top. The training effect is good, and the accuracy has reached 90%, but the problem is derived The size of H5 model reaches 3M.

I tried to use a fool migration learning website. https://studio.edgeimpulse.com/
The classification model exported from the website is only 600KB(after INT8 quantized). What causes my model to be too large?

Here is the structure of my network:

def mobile_net_v2(data_augmentation, input_shape):
    base_model = keras.applications.mobilenet_v2.MobileNetV2(
        weights='imagenet',
        input_shape=input_shape,
        alpha=0.35,
        include_top=False)
    inputs = keras.Input(shape=input_shape)
    base_model.trainable = False

    x = data_augmentation(inputs)
    x = layers.Rescaling(1. / 255)(x)

    x = base_model(x)

    x = layers.Flatten()(x)

    outputs = layers.Dense(15, activation='softmax')(x)
    return keras.Model(inputs, outputs)

The input size is (96, 96)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source