Can I save only some VGG19's layers into a .H5 file?

I am training a deep-learning style transfer model with the pretrained-VGG19 CNN.

My aim is to use it in my Android app for personal purposes with Google Firebase Machine Learning Kit (which would host my .H5 model to make it usable by my Android app). The maximum .H5 model file's size allowed by Machine Learning Kit is: 8MB. However when I save the whole VGG19 model, I end with 80MB... So I can't use it.

Since only some layers of the VGG19 network are used in my style transfer program, is it possible to reduce the .H5's size by saving only those layers' weights, or something like that? Is there any other solution to my problem?

To save my VGG19 network as a .H5 file, I use the following Python command:

model.save('./style_transfer/st.h5', include_optimizer=False) , where model = vgg19.VGG19(input_tensor=input_tensor, weights='imagenet', include_top=False).

As you can see, I already don't include the optimizer in order to reduce the saved .H5's size.

Topic vgg16 transfer-learning neural-style-transfer cnn tensorflow

Category Data Science


after creating the model you can create another model as below ( I created model till 8 layers)

model = Model(vgg19.input, vgg19.layers[8].output)
model.save('./style_transfer/st.h5')

You can also use post-training Quantization techniques to reduce the size of the model to deploy in mobile/IoT devices. please check tensorflow documentation here

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.