0
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

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

| improve this answer | |
$\endgroup$
  • $\begingroup$ Indeed. I will try your solution! $\endgroup$ – JarsOfJam-Scheduler Oct 14 '19 at 10:17
  • $\begingroup$ Could you please confirm that the 5th layer is block5_conv2 (block5_conv2 is the highest layer I use in my transfer style program)? $\endgroup$ – JarsOfJam-Scheduler Oct 14 '19 at 10:40
  • $\begingroup$ @JarsOfJam-Scheduler that depends on your requirement. I have taken a random number 8. $\endgroup$ – Uday Oct 14 '19 at 10:44
  • $\begingroup$ Well I think I must use the 5th layer (which would correspond to block5_conv2?). Indeed, I use the following layers: 'block5_conv2', 'block1_conv1', 'block2_conv1', 'block3_conv1', 'block4_conv1', 'block5_conv1' . Do you agree with me? :) $\endgroup$ – JarsOfJam-Scheduler Oct 14 '19 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.