I have retrained my model on Darknet and use https://github.com/qqwweee/keras-yolo3 to convert my darknet weights to h5.
I have replace relu for leaky relu for quantization purpose. My model then has been converted to tflite model successfully by using tf-nightly.
However, I can't parse the model to edgetpu by resize nearest neighbor error. To my understanding, resize nearest neighbor is supported in https://coral.ai/docs/edgetpu/models-intro/#supported-operations So why did this error happened? Any way to fix?
Here is my tflite convert code:
import tensorflow as tf
import numpy as np
import sys
def representative_dataset_gen():
for _ in range(250):
yield [np.random.uniform(0.0, 1.0, size=(1, 416, 416, 3)).astype(np.float32)]
if len(sys.argv) != 3:
print(f"Usage: {sys.argv[0]} <keras-model> <output-filename>")
sys.exit(1)
model_fn = sys.argv[1]
out_fn = sys.argv[2]
# Convert and apply full integer quantization
converter = tf.compat.v1.lite.TFLiteConverter.from_keras_model_file(model_fn)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8,
tf.lite.OpsSet.SELECT_TF_OPS]
#converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
# Set inputs and outputs of network to 8-bit unsigned integer
converter.inference_input_type = tf.uint8
converter.inference_output_type = tf.uint8
converter.representative_dataset = representative_dataset_gen
tflite_model = converter.convert()
open(sys.argv[2], "wb").write(tflite_model)
I'm from the coral team and I'm planning on investigating the yolov3 model myself, just haven't got the bandwidth to do so yet :) Here are some tips from what I've gathered:
Users have been able to successfully compile the model after changing the leaky_relu
to relu
, although accuracy may decrease. I know you've mention this, but I wanted to put this on the list for other users to reference.
Secondly, I suspect that you are using tf-nightly
or some newer tf version for your conversion? If so, I suggest downgrading to maybe tf2.2, some newer version of the same ops are not yet supported by the compiler.
Try turning off MLIR
converter also, released version of the edgetpu_compiler
doesn't play well with MLIR
lmk if you found some success, would love to give this a shot also! fyi: I got yolov4 converted but the architect only allows 1/962 ops to run on the edgetpu so it's a bummer no go.