Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert_keras_model() does not work as expected for BinaryDenseNet37 Dilated and XNORNet #744

Open
ZhanqiuHu opened this issue Jul 14, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@ZhanqiuHu
Copy link

ZhanqiuHu commented Jul 14, 2022

I tried using python 3.6 + LCE 0.6.2 and python 3.7/3.8 + LCE 0.7.0 to run the following code, and the tflite file generated has unexpected sizes:

For python 3.6 + LCE 0.6.2:
XNOR tflite: 88.9 MB
BinaryDenseNet37 tflite: 25.6 MB

For python 3.7/3.8 + LCE 0.7.0:
XNOR tflite: 235.2 MB
BinaryDenseNet37 tflite: 5.4 MB (this looks normal)

Do you know what is causing this and what will be a solution? Thanks a lot!

import tensorflow as tf
import larq_zoo as lqz
import larq as lq


input_tensor = tf.keras.layers.Input(shape=(224, 224, 3))
# model = lqz.literature.BinaryDenseNet37Dilated(input_tensor=input_tensor, weights="imagenet")
model = lqz.literature.XNORNet(input_tensor=input_tensor, weights="imagenet")

lq.models.summary(model, print_fn=None, include_macs=True)

import os
path = os.path.join(os.getcwd(), './tflite_models')
if not os.path.exists(path):
    os.makedirs(path)
with open(os.path.join(path,name+'.tflite'), 'wb') as flatbuffer_file:
    flatbuffer_bytes = lce.convert_keras_model(model)
    flatbuffer_file.write(flatbuffer_bytes)
@lgeiger
Copy link
Member

lgeiger commented Jul 15, 2022

It looks like dilated convolutions weren't properly converted in LCE 0.6.2 which was based on the TensorFlow 2.5 converter, this seems to fixed in LCE 0.7.

With respect to XNOR-Net:
It looks like there was a regression in 0.7 or in the underlying TensorFlow converter which leads to incorrect fusion of the xnor weights quantizer in one of the layers:
Screenshot 2022-07-15 at 17 34 00

I would need to take a closer look at this conversion issue next week, for now I'd recommend sticking with 0.6.2 for converting XNORNet.

@lgeiger lgeiger added the bug Something isn't working label Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants