Skip to main content

深度学习模型格式转换器

项目描述

Deeplite模型转换器

协作是设计基于深度学习的解决方案的最大挑战之一。可以使用多种格式来表示深度学习 mdoel:PyTorch、Tensorflow、ONNX、TFLite。这个开源转换器库旨在将深度学习模型从一种格式转换为另一种格式。

使用 pip 安装

使用以下命令从我们的内部 PyPI 存储库安装包。

$ pip install --upgrade pip
$ pip install deeplite-model-converter

从源安装

$ git clone https://github.com/Deeplite/deeplite-model-converter.git
$ pip install .

以开发模式安装

$ git clone https://github.com/Deeplite/deeplite-model-converter.git
$ pip install -e .
$ pip install -r requirements-test.txt

要测试安装,可以使用pytest根文件夹中的命令运行基本测试。

注意: 目前,我们支持 Tensorflow 2.4+ 版本和 onnxruntime 1.8。我们还不支持 ONNX 的所有 OPSET 版本。

如何使用

PyTorch2ONNX

# Step 1: Define native pytorch dataloaders and model
data_splits = /* ... load iterable data loaders ... */
model = /* ... load native deep learning model ... */

# Step 2: Instantiate a converter object
pytorch2onnx = PyTorch2ONNX(model=model)
pytorch2onnx.set_config(precision='fp32', device=Device.CPU)

# Step 3: Convert the format and save
dataloader = TorchProfiler.enable_forward_pass_data_splits(data_splits)
rval = pytorch2onnx.convert(dataloader, dynamic_input='bchw', path="model.onnx")

TF2TFLite

# Step 1: Define native Tensorflow model
model_conc_functions = /* ... load TF native model as concrete functions ... */

# Step 2: Instantiate a converter object
tf2tflite = TF2TFLite(model=model_conc_functions)

# Step 3: Convert the format and save
tflite_model, rval = tf2tflite.convert()
tf2tflite.save(tflite_model, "model.tflite")

例子

运行一个例子,

pip install deeplite-torch-zoo
python examples/converters/pytorch2tflite.py

支持的转换器

到目前为止,支持以下转换器,

  • pytorch2onnx
  • pytorch2jit
  • onnx2tf
  • tf2tflite

贡献一个转换器

我们始终欢迎社区贡献以扩大范围deeplite-model-converter并增加新的转换器。一般来说,我们遵循fork-and-pullGit 工作流程。

  1. Fork GitHub 上的 repo
  2. 将项目克隆到自己的机器上
  3. 将更改提交到您自己的分支
  4. 把你的工作推回你的叉子
  5. 提交拉取请求,以便我们审核您的更改

注意:在发出拉取请求之前,请务必合并来自“上游”的最新版本!

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

内置发行版

deeplite_model_converter-1.2.2-cp39-cp39-manylinux1_x86_64.whl (1.3 MB 查看哈希

已上传 cp39

deeplite_model_converter-1.2.2-cp38-cp38-manylinux1_x86_64.whl (1.4 MB 查看哈希

已上传 cp38