I have created a object detection model using Pytorch and then converted from .pth to .onnx and then .pb, but now I need to convert it into .tflite for android app! How to do it? It's my first time.
input_arrays = [64, 3, 224, 224]
output_arrays = ?
for binary classification.
I have done it from pytorch but everything I find to look at was from keras or Tensorflow...
This is the code I have used to convert it from .pb to .tflie
converter = lite.TFLiteConverter.from_frozen_graph(
model/model.pb , input_arrays, output arrays )
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
!tflite_convert \
--output_file= model/model.tflite \
--graph_def_file= model/model.pb \
--input_arrays= input_arrays \
-- output_arrays= output_arrays
I think it has something to do with input arrays and output arrays, but not sure about it. Is graph_def_file supposed to store model.pb ?
No need to specify input and output array, when using the following code:
import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
Try this out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With