网站布局分类,个人创建网站程序,网站设计的目的是什么,手机版网站建设方案十二#xff1a;Paddle Inference推理 #xff08;python#xff09;API详解
15. PredictorPool 类
PredictorPool 对 Predictor 进行了简单的封装#xff0c;通过传入 config 和 thread 的数目来完成初始化#xff0c;在每个线程中#xff0c;根据自己的线程 id 直接从…十二Paddle Inference推理 pythonAPI详解
15. PredictorPool 类
PredictorPool 对 Predictor 进行了简单的封装通过传入 config 和 thread 的数目来完成初始化在每个线程中根据自己的线程 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)