tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.51k stars 1.93k forks source link

tensorflowjs_converter : size of a converted model is 60% bigger with tfjs 2 compare to tfjs 1 #3837

Closed gabides closed 4 years ago

gabides commented 4 years ago

TensorFlow.js version

2.3.0

Browser version

N/A

Describe the problem or feature request

I upgraded to pip tensorflowjs 2.3.0 from 1.3.2 and now the models converted by tensorflowjs_converter are significantly heavier (around 60% more, regardless of quantization).

previously with pip install tensorflowjs==1.3.2 :
tensorflowjs_converter --input_format=tf_saved_model \
        --output_format=tfjs_graph_model \
        --signature_name=serving_default \
        --saved_model_tags=serve \
        --strip_debug_ops=False\
       /path_to_saved_model/saved_model converted_model

=> size 3.3 MB

tensorflowjs_converter --input_format=tf_saved_model \
        --output_format=tfjs_graph_model \
        --signature_name=serving_default \
        --saved_model_tags=serve \
        --strip_debug_ops=False \
        --quantization_bytes 1 \
       /path_to_saved_model/saved_model converted_model_quantized_1_byte

=> size 1 MB

now with pip install tensorflowjs==2.3.0 with the tensorflowjs_wizard generated command :
tensorflowjs_converter --control_flow_v2=True \
        --input_format=tf_saved_model \
        --saved_model_tags=serve \
        --signature_name=serving_default \
        --strip_debug_ops=False \
        --weight_shard_size_bytes=4194304 \
       /path_to_saved_model/saved_model converted_model

=> size 5.3 MB

tensorflowjs_converter --control_flow_v2=True \
        --input_format=tf_saved_model \
        --quantize_uint8=* \
        --saved_model_tags=serve \
        --signature_name=serving_default \
        --strip_debug_ops=False \
        --weight_shard_size_bytes=4194304 \
        /path_to_saved_model/saved_model converted_model_quantized_1_byte

=> size 1.6 MB

both converted models size have increased by 60% compared to tensorflowjs 1.3.2. is this expected behaviour or a bug, or maybe there is an option I missed?

Thanks

pyu10055 commented 4 years ago

@gabides What is the model you are trying to converter? can you try the earlier version of the converter (2.0.0) with an empty virtualenv?

It could be related to TF version, as well as the control_flow_v2 flag, it would be better we can isolate that.

gabides commented 4 years ago

@pyu10055 i did every test in clean separate virtualenvs for the conversion (each with only tensorflowjs installed with the specific version to test). Also i did a few more tests to answer your questions:

pyu10055 commented 4 years ago

@gabides can you try to export your model with TF 2, since tfjs 2.x are using at lease 2.1 TF.

google-ml-butler[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 dyas if no further activity occurs. Thank you.

google-ml-butler[bot] commented 4 years ago

Closing as stale. Please @mention us if this needs more attention.