This repository can be used to convert PyTorch to other types of model such as ONNX, Tensorflow and TensorflowLite.
If you want to convert pytorch to TFLite, to utilize the pretrained Deep Learning model in Android, you need to follow this step:
- Pytorch -> ONNX
- ONNX -> Tensorflow
- Tensorflow -> TensorflowLite
To illustrate how to use this code, consider converting ResNet18 (PyTorch Model) as an example.
Run pytorch2onnx.py.
If converting has no problem, you can see "The model is valid!".
If you want to convert your model, you have to import your model and set the appropriate shape of input.
Run onnx2tf.py.
Modify the file path or name(Name_of_ONNX, Name_of_TF)
Run tf2TFLite.py.
Modify the file path or name(TF_PATH, TFLite_name)