Coder Social home page Coder Social logo

younggis / paddlequickinference Goto Github PK

View Code? Open in Web Editor NEW

This project forked from agentmaker/paddlequickinference

0.0 1.0 0.0 7.51 MB

一个基于 Paddle Inference 封装的用于快速部署的高层 API

License: Apache License 2.0

Python 100.00%

paddlequickinference's Introduction

Paddle Quick Inference

  • 一个基于 Paddle Inference 封装的用于快速部署的高层 API
  • 本项目基于 Paddle 2.0 版本开发

高层 API 特点

  • 使用方便快捷
  • 代码类似动态图模型的加载和预测
  • 将常用的 Config 和 Predictor 配置进行封装
  • 留出额外的接口以兼容一些特殊的配置操作

模型格式

  • 目前本项目支持四种推理模型格式,具体请参考下表:

    模型计算图 模型参数
    __model__ *
    model params
    __model__ __params__
    *.pdmodel *.pdiparams

安装

  • 直接安装
$ pip install ppqi -i https://pypi.python.org/simple
$ pip install [path to whl]

快速使用

import numpy as np
from ppqi import InferenceModel

# 加载推理模型
model = InferenceModel([Inference Model Path])
model.eval()

# 准备数据
inputs = np.random.randn(batch_size, n1, n2, n3, ...).astype(np.float32)

# 前向计算
outputs = model(inputs)

API 说明

'''
modelpath:推理模型路径
use_gpu:是否使用 GPU 进行推理
gpu_id:设置使用的 GPU ID
use_mkldnn:是否使用 MKLDNN 库进行 CPU 推理加速
cpu_threads:设置计算库的所使用 CPU 线程数

还可以通过 InferenceModel.config 来对其他选项进行配置
如配置 TensorRT:
model.config.enable_tensorrt_engine(
    workspace_size = 1 << 20, 
    max_batch_size = 1, 
    min_subgraph_size = 3, 
    precision_mode=paddle.inference.PrecisionType.Float32, 
    use_static = False, 
    use_calib_mode = False
)
'''
model = InferenceModel(
    modelpath=[Inference Model Path], 
    use_gpu=False,
    gpu_id=0,
    use_mkldnn=False,
    cpu_threads=1
)

'''
将模型设置为推理模式
实际上是使用 Config 创建 Predictor
'''
model.eval()

'''
创建完 Predictor 后
可打印出模型的输入输出节点的数量和名称
'''
print(model)

'''
根据输入节点的数量和名称准备好数据
数据格式为 Ndarray
'''
inputs = np.random.randn(batch_size, n1, n2, n3, ...).astype(np.float32)

'''
模型前向计算
根据输入节点顺序传入输入数据
batch_size:推理数据批大小
返回结果格式为所有输出节点的输出
数据格式为 Ndarray
'''
outputs = model(input_datas, batch_size=4)

部署案例

Contact us

Email : [email protected]
QQ Group : 1005109853

paddlequickinference's People

Contributors

gt-acerzhang avatar gt-zhangacer avatar jm12138 avatar whitefirefox avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.