1

I tried to compile a tflite model to edgetpu model and run into some error like that.

Edge TPU Compiler version 16.0.384591198
Started a compilation timeout timer of 180 seconds.
ERROR: Attempting to use a delegate that only supports static-sized tensors with a graph that has dynamic-sized tensors.
Compilation failed: Model failed in Tflite interpreter. Please ensure model can be loaded/run in Tflite interpreter.
Compilation child process completed within timeout period.
Compilation failed! 

I define my model like that:

preprocess_input = tf.keras.applications.efficientnet.preprocess_input

def Model(image_size=IMG_SIZE):
    input_shape = image_size + (3,)
    inputs = tf.keras.Input(shape=input_shape)
    x = preprocess_input(inputs)
    base_model = tf.keras.applications.efficientnet.EfficientNetB0(input_shape=input_shape, include_top=False, weights="imagenet")
    base_model.trainable = False
    x = base_model(x, training=False)
    x = tfl.GlobalAvgPool2D()(x)
    x = tfl.Dropout(rate=0.2)(x)
    outputs = tfl.Dense(90, activation='softmax')(x)
    model = tf.keras.Model(inputs, outputs)

    return model

The model summary is like that:

model summary

I convert to tflite model like that:

converter = tf.lite.TFLiteConverter.from_keras_model(model)

# Defining the representative dataset from training images.
def representative_dataset_gen():
    for image, label in train_dataset.take(100):
        yield [image]
  
        
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_dataset_gen

# Using Integer Quantization.
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
# Setting the input and output tensors to uint8.
converter.inference_input_type = tf.uint8
converter.inference_output_type = tf.uint8

tflite_model = converter.convert()

if not os.path.isdir('exported'):
        os.mkdir('exported')
        
with open('/workspace/eff/exported/groups_1.tflite', 'wb') as f:
    f.write(tflite_model)

Environment:

  • Edge TPU Compiler version 16.0.384591198
  • Python version 3.6.9
  • tensorflow 1.15.3

When looking for solutions on google, someone said you need to get rid of the preprocess_input, I'm not sure what that means.

How can I check if there is a dynamic shape tensor in the model and how can I fix it?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65

0 Answers0