tensorflow-yolov4-tflite icon indicating copy to clipboard operation
tensorflow-yolov4-tflite copied to clipboard

From scratch training model, can be converted to tflite?

Open zxj11838 opened this issue 4 years ago • 12 comments

Does anyone train a model on their own data, convert it to tflite format, and apply it to Android?

zxj11838 avatar Jun 04 '20 08:06 zxj11838

Haven't tried on Android. But I did transfer learning (started with pretrained weights but had custom dataset), converted to tflite (both regular and int8 (int8 required some hacks)), and ran on raspberry pi

sterlingrpi avatar Jun 06 '20 14:06 sterlingrpi

The model format saved using model.save_weights() in train.py is ckpt, how to convert to tflite format?Does anyone know how to do it?

zxj11838 avatar Jun 12 '20 02:06 zxj11838

Try:

python convert_tflite.py --weights ./checkpoints/yolov4

And change the load function to:

model.load_weights(FLAGS.weights)

https://github.com/hunglc007/tensorflow-yolov4-tflite/issues/68

sterlingrpi avatar Jun 12 '20 02:06 sterlingrpi

Could you please show more about convert_tflite.py? I do not know how to transfer "converter = tf.lite.TFLiteConverter.from_saved_model(FLAGS.weights)" to "load_weights", thanks a lot.

Yxxxb avatar Jun 08 '22 12:06 Yxxxb

tflite doesn't support load_weights. You have to use tf.lite.Interpreter

sterlingrpi avatar Jun 08 '22 12:06 sterlingrpi

But I found interpreter could also not use load_weight. Could you please send me your convert_tflite.py that converts yolov4.data-00000-of-00001 to tflite? My email is [email protected]. Sorry for my anxiety because it's my homework and today is ddl.

Yxxxb avatar Jun 08 '22 12:06 Yxxxb

Put the path of your model here. I used h5 format. It should work with file format too

https://github.com/sterlingrpi/ssd_tflite_tpu/blob/c693f0b506f18091787bea8b1c33a94936b00bb5/tflite_convert.py#L10

sterlingrpi avatar Jun 08 '22 12:06 sterlingrpi

What class has you doing a custom trained SSD on a TPU?

sterlingrpi avatar Jun 08 '22 12:06 sterlingrpi

NM. I thought you were asking about a different repo

sterlingrpi avatar Jun 08 '22 12:06 sterlingrpi

like this? ssd = tf.keras.models.load_model('./checkpoints/yolov4.data-00000-of-00001') It requires {saved_model.pbtxt|saved_model.pb} but I only get .data-00000-of-00001

Yxxxb avatar Jun 08 '22 12:06 Yxxxb

What class has you doing a custom trained SSD on a TPU?

Emmm I'm training Yolo4.

Yxxxb avatar Jun 08 '22 12:06 Yxxxb

Put the path of your model here. I used h5 format. It should work with file format too

https://github.com/sterlingrpi/ssd_tflite_tpu/blob/c693f0b506f18091787bea8b1c33a94936b00bb5/tflite_convert.py#L10

It still doesn't work. It requires a .pdtxt or .pd file but I only have yolov4.data-00000-of-00001 instead.

Yxxxb avatar Jun 08 '22 12:06 Yxxxb