MCPcopy Index your code
hub / github.com/AgentMaker/PaddleQuickInference

github.com/AgentMaker/PaddleQuickInference @1.0.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.0.4 ↗ · + Follow
39 symbols 156 edges 21 files 13 documented · 33%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Paddle Quick Inference

  • PaddleInference封装的一个快速部署的高层API
  • 本项目基于Paddle2.0版本开发

高层API特点

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

模型格式

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

    模型计算图 模型参数
    model params
    __model__ *
    __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(8, 64, 64, 3).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
'''
input_datas = np.random.randn(8, 64, 64, 3).astype(np.float32)

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

部署案例

Core symbols most depended-on inside this repo

eval
called by 8
ppqi/inference.py
constrain_to_multiple_of
called by 6
examples/MiDaS/transforms.py
get_size
called by 1
examples/MiDaS/transforms.py
write_pfm
called by 1
examples/MiDaS/utils.py
write_depth
called by 1
examples/MiDaS/utils.py
preprocess
called by 1
examples/MiDaS/processor.py
postprocess
called by 1
examples/MiDaS/processor.py
normPRED
called by 1
examples/U2Net/PortraitGeneration/processor.py

Shape

Function 21
Method 14
Class 4

Languages

Python100%

Modules by API surface

examples/MiDaS/transforms.py11 symbols
ppqi/inference.py7 symbols
examples/U2Net/PortraitGeneration/processor.py3 symbols
examples/OpenPose/HandsEstimation/processor.py3 symbols
examples/MiDaS/utils.py3 symbols
examples/UGATIT/processor.py2 symbols
examples/SINet/processor.py2 symbols
examples/PyramidBox/processor.py2 symbols
examples/MiDaS/processor.py2 symbols
examples/ExtremeC3Net/processor.py2 symbols
examples/AnimeGAN/processor.py2 symbols

For agents

$ claude mcp add PaddleQuickInference \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page