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
--torch-pathPath to local PyTorch model, please save whole model e.g. torch.save(model, PATH)--tf-lite-pathSave path for Tensorflow Lite model--target-shapeModel input shape to create static-graph (default:(224, 224, 3)--sample-filePath to sample image file. If model is not about computer-vision, please use leave empty and only enter--target-shape--seedSeeds RNG to produce random input data when--sample-filedoes not exists--log=INFOTo see what happens behind
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