omerferhatt / torch2tflite

PyTorch to TensorFlow Lite converter
MIT License
181 stars 43 forks source link
model-converter onnx onnx-tf pytorch tensorflow2 tensorflowlite tflite

:heavy_exclamation_mark: This codebase has been archived because there are more updated solutions available. Please check out https://ai.google.dev/edge/lite/models/pytorch_to_tflite

PyTorch to TensorFlow Lite Converter

Converts PyTorch whole model into Tensorflow Lite

PyTorch -> Onnx -> Tensorflow 2 -> TFLite

Please install first

python3 setup.py install

Args

Basic usage of the script

To test with sample file:

python3 -m torch2tflite.converter
    --torch-path tests/mobilenetv2_model.pt
    --tflite-path mobilenetv2.tflite
    --sample-file sample_image.png
    --target-shape 224 224 3

To test with random input to check gradients:

python3 -m torch2tflite.converter
    --torch-path tests/mobilenetv2_model.pt
    --tflite-path mobilenetv2.tflite
    --target-shape 224 224 3
    --seed 10