首页 Paddle Inference 帖子详情
自行训练的inference文件如何部署python代码
收藏
快速回复
Paddle Inference 问答部署 1282 2
自行训练的inference文件如何部署python代码
收藏
快速回复
Paddle Inference 问答部署 1282 2

已经分别训练好检测和识别模型,并转换成inference格式

下一步希望部署在python代码内,用于识别图片。

搜到了一组代码,但是里面只引用了一组.pdmodel和.pdiparams文件,是否需要将识别和检测文件合并呢?或者有什么能同时引用检测和识别模型的代码或者教程可以参考吗,谢谢。

如何能将检测和识别推理串联呢。

mport numpy as np
from paddle.inference import Config
from paddle.inference import create_predictor

config = Config("inference_model/lenet/lenet.pdmodel", "inference_model/lenet/lenet.pdiparams")
config.disable_gpu()

# 创建PaddlePredictor
predictor = create_predictor(config)

# 获取输入的名称
input_names = predictor.get_input_names()
input_handle = predictor.get_input_handle(input_names[0])

# 设置输入
fake_input = np.random.randn(1, 1, 28, 28).astype("float32")
input_handle.reshape([1, 1, 28, 28])
input_handle.copy_from_cpu(fake_input)

# 运行predictor
predictor.run()

# 获取输出
output_names = predictor.get_output_names()
output_handle = predictor.get_output_handle(output_names[0])
output_data = output_handle.copy_to_cpu() # numpy.ndarray类型

print(output_data)

0
收藏
回复
全部评论(2)
时间顺序
FutureSI
#2 回复于2021-12

为什么要串联呢?串联在一起就是检测模型了

0
回复
DeepGeGe
#3 回复于2021-12

这个使用inference模型的架构是一个通用架构,使用不同模型或者依次链接不同的模型只需要将:

Config("inference_model/lenet/lenet.pdmodel", "inference_model/lenet/lenet.pdiparams")

这里的模型路径更改掉就可以了。

0
回复
需求/bug反馈?一键提issue告诉我们
发现bug?如果您知道修复办法,欢迎提pr直接参与建设飞桨~
在@后输入用户全名并按空格结束,可艾特全站任一用户