Skip to main content

Install

pip install pytorch_to_tflite

How to use

Pytorch to Onnx

# !pip install -e ../
from pytorch_to_tflite.pytorch_to_tflite import *
import torch
import yaml
import os
import mmcv
from nanodet.model.arch import build_model

PATH_TO_CONFIG = '/gitprojects/nano-det-parkingline/config/nanodet-g.yml'
cfg = yaml.safe_load(open(PATH_TO_CONFIG))
cfg = mmcv.Config(cfg)
model = build_model(cfg.model)

img = torch.randn(1,3,416,416)
out = model(img)

!mkdir -p cache/
onnx_out_path = 'cache/out.onnx'
torch.onnx.export(model, img, onnx_out_path)
Finish initialize Lite GFL Head.


/root/miniconda3/envs/pytorch-to-tflite/lib/python3.9/site-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at  /pytorch/c10/core/TensorImpl.h:1156.)
  return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
/root/miniconda3/envs/pytorch-to-tflite/lib/python3.9/site-packages/torch/nn/functional.py:3609: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.
  warnings.warn(
/root/miniconda3/envs/pytorch-to-tflite/lib/python3.9/site-packages/torch/nn/functional.py:3657: UserWarning: The default behavior for interpolate/upsample with float scale_factor changed in 1.6.0 to align with other frameworks/libraries, and now uses scale_factor directly, instead of relying on the computed output size. If you wish to restore the old behavior, please set recompute_scale_factor=True. See the documentation of nn.Upsample for details. 
  warnings.warn(

ONNX to Tensorflow

onnx_path = onnx_out_path
tf_path = onnx_path + '.tf'
onnx_to_tf(onnx_path=onnx_path, tf_path=tf_path)
assert os.path.exists(tf_path)

Tensorflow to tflite

tflite_path = tf_path+'.tflite'
tf_to_tf_lite(tf_path, tflite_path)
assert os.path.exists(tflite_path)
tflite_path

Metadata

Release files for pytorch-to-tflite 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytorch-to-tflite 0.0.4
File Size Uploaded Provenance Actions
pytorch_to_tflite-0.0.4.tar.gz 11.0 kB Without provenance Details for pytorch_to_tflite-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytorch-to-tflite 0.0.4
File Interpreter ABI Platform Actions
pytorch_to_tflite-0.0.4-py3-none-any.whl Python 3 none any Details for pytorch_to_tflite-0.0.4-py3-none-any.whl

Total release size: 20.7 kB

Release files / pytorch_to_tflite-0.0.4.tar.gz

Download URL pytorch_to_tflite-0.0.4.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a811be80e81a1a896c76804182ec65b8b21b983e843eb9400e2867cdad84d7c6
BLAKE2b-256 checksum
How to use checksums
84f558d91ace8894a529b341cf158dbc6e0135d2e3ddfb6e1a9b82ede5334f72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

Release files / pytorch_to_tflite-0.0.4-py3-none-any.whl

Download URL pytorch_to_tflite-0.0.4-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40490e655dd896343a3d5f8ef449a15137d9d1bddfe4854c018460d29930ce67
BLAKE2b-256 checksum
How to use checksums
b230cbfaf92015eb838dcb1791b3e08a6f1b7ad41b88d828e087b25d73800a79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

Security for pytorch-to-tflite 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page