Paddle Inference部署推理(十二)

十二:Paddle Inference推理 (python)API详解

15. PredictorPool 类

PredictorPoolPredictor 进行了简单的封装,通过传入 configthread 的数目来完成初始化,在每个线程中,根据自己的线程 id 直接从池中取出对应的 Predictor 来完成预测过程。

类及方法定义如下:

# PredictorPool 类定义
# 参数:config - Config 类型
#      size - Predictor 对象数量
class paddle.inference.PredictorPool(config: Config, size: int)

# 根据线程 ID 取出该线程对应的 Predictor
# 参数:idx - 线程 ID
# 返回:Predictor - 线程 ID 对应的 Predictor
paddle.inference.PredictorPool.retrive(idx: int)

代码示例:

# 引用 paddle inference 预测库
import paddle.inference as paddle_infer

# 创建 Config
config = paddle_infer.Config("./mobilenet_v1.pdmodel", "./mobilenet_v1.pdiparams")

# 创建 PredictorPool
pred_pool = paddle_infer.PredictorPool(config, 4)

# 获取 ID 为 2 的 Predictor 对象
predictor = pred_pool.retrive(2)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值