0
votes

How are we supposed to convert a multiple input_shape model from Keras to Tensorflow Lite ?

I tried to convert this:

{
    "class_name": "Model",
    "keras_version": "2.2.4",
    "config": {
        "layers": [
            {
                "class_name": "InputLayer",
                "config": {
                    "dtype": "float32",
                    "batch_input_shape": [
                        null,
                        null,
                        null,
                        3
                    ],
                    "name": "input",
                    "sparse": false
                },
                "inbound_nodes": [],
                "name": "input"
            },
...

with that:

import sys, os
import tensorflow as tf
import traceback

from os.path import splitext, basename

print(tf.__version__)

mod_path = "wpod-net_update1.h5"

def load_model(path,custom_objects={},verbose=0):
    #from tf.keras.models import model_from_json

    path = splitext(path)[0]
    with open('wpod-net.json','r') as json_file:
        model_json = json_file.read()
    model = tf.keras.models.model_from_json(model_json, custom_objects=custom_objects)
    model.load_weights('%s.h5' % path)
    if verbose: print('Loaded from %s' % path)
    return model

keras_mod = load_model(mod_path)

converter = tf.lite.TFLiteConverter.from_keras_model(keras_mod)
tflite_model = converter.convert()

# Save the TF Lite model.
with tf.io.gfile.GFile('wpod-net-1.tflite', 'wb') as f:
    f.write(tflite_model)

But my output looks like this : neutron description of my model So if I understand correctly it says that the input required is an RGB image of 1 pixel.

Is that possible to keep this variable input_shape behavior when I'm using TensorFlow Lite ? Or should I replace the 3 null to some constant ?

And just to let you know I didn't create the model it's coming from here

1

1 Answers

0
votes

TFLite converter does not work well with dynamic input shape. Solution is to put prior conversion fixed size and change it prior to inference, see how.