惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recorded Future
Recorded Future
S
Secure Thoughts
D
Docker
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
F
Fortinet All Blogs
月光博客
月光博客
S
Security @ Cisco Blogs
AI
AI
IT之家
IT之家
P
Proofpoint News Feed
Stack Overflow Blog
Stack Overflow Blog
大猫的无限游戏
大猫的无限游戏
N
News and Events Feed by Topic
Hacker News: Ask HN
Hacker News: Ask HN
人人都是产品经理
人人都是产品经理
Recent Announcements
Recent Announcements
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Google Online Security Blog
Google Online Security Blog
K
Kaspersky official blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
P
Proofpoint News Feed
Latest news
Latest news
Webroot Blog
Webroot Blog
GbyAI
GbyAI
L
Lohrmann on Cybersecurity
T
Threat Research - Cisco Blogs
S
Schneier on Security
G
Google Developers Blog
N
News | PayPal Newsroom
C
Check Point Blog
T
Tenable Blog
L
LINUX DO - 最新话题
C
CERT Recently Published Vulnerability Notes
T
Troy Hunt's Blog
Know Your Adversary
Know Your Adversary
SecWiki News
SecWiki News
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
爱范儿
爱范儿
W
WeLiveSecurity
Project Zero
Project Zero
M
MIT News - Artificial intelligence
H
Hacker News: Front Page
Apple Machine Learning Research
Apple Machine Learning Research
V
V2EX
C
Cyber Attacks, Cyber Crime and Cyber Security

洛屿的小站

一种简单的卡尔曼滤波器设计 Cadence - 应律而动,落指成音 Zephyr - 聆风之息,为你而奏 不改一行插件代码,实现消息优先级与阻断 洛玖定时任务系统 在 butterfly 主题中添加首页点集动画(基于p2line项目) 你好,2026 stm32f4xx-ads1256驱动 stm32f4xx-ad9854并行驱动 主动式网站状态监测实现及其应用 右键菜单加入用Trae打开文件和文件夹 三角洲行动ID映射表 洛玖SDK说明 为网页文章开头添加原文连接 Hexo-Butterfly主题在主页添加GitHub贡献日历 Proteus中555定时器仿真问题 装饰器 洛玖开发日记 STS3032舵机获取力矩输出 kotlin网页前后端那些事 mspm0g3507-ad9850 奇怪的bug Paddle模型转PaddleLite 人工智能考核 构建一个yolov3网络 yolo和paddle模型常见输出参数 随便写的一些东西 实验室C语言第一次考核题目讲解及相关代码解读 C语言神经网络房价预测系统 C、C++数组,指针,指针数组,数组指针的区别 C、C++的大括号是必须的部分吗? C、C++预处理详解 C、C++其他关键字详解 C、C++存储类型关键字详解 C、C++控制语句关键字详解 C、C++数据类型关键字详解 C、C++关键字 C++药品管理系统 Bi-LSTM(Attention)的PyTorch实现 C语言实现波士顿房价预测 easy库的使用 edgeboardFZ3A相关问题 Predict.py的编写 Paddle环境搭建 百度Paddle模型训练 GMD09601-0.96OLED显示屏 【LeetCode 1617】统计子树中城市之间最大距离 C语言学习相关 STM32阵列按键 CH32(F10X F20X) 最短路 拓扑排序
PaddleDetection
洛屿 · 2024-01-07 · via 洛屿的小站

爱来自ZZULI❤drluo

1. Config 类定义

Config 类为用于配置构建 Predictor 对象的配置信息,如模型路径、是否开启 gpu 等等。

构造函数定义如下:

1
2
3
4
5
6
7
8
# Config 类定义,输入为 None
class paddle.inference.Config()

# Config 类定义,输入为其他 Config 对象
class paddle.inference.Config(config: Config)

# Config 类定义,输入分别为模型文件路径和参数文件路径
class paddle.inference.Config(prog_file: str, params_file: str)

代码示例:

1
2
3
4
5
6
7
8
# 引用 paddle inference 预测库
import paddle.inference as paddle_infer

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

# 根据 config 创建 predictor
predictor = paddle_infer.create_predictor(config)

2. 设置预测模型

2.1. 从文件中加载预测模型

API定义如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 设置模型文件路径,当需要从磁盘加载模型时使用
# 参数:prog_file_path - 模型文件路径
# params_file_path - 参数文件路径
# 返回:None
paddle.inference.Config.set_model(prog_file_path: str, params_file_path: str)

# 设置模型文件路径
# 参数:x - 模型文件路径
# 返回:None
paddle.inference.Config.set_prog_file(x: str)

# 设置参数文件路径
# 参数:x - 参数文件路径
# 返回:None
paddle.inference.Config.set_params_file(x: str)

# 获取模型文件路径
# 参数:None
# 返回:str - 模型文件路径
paddle.inference.Config.prog_file()

# 获取参数文件路径
# 参数:None
# 返回:str - 参数文件路径
paddle.inference.Config.params_file()

代码示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 引用 paddle inference 预测库
import paddle.inference as paddle_infer

# 创建 config
config = paddle_infer.Config()

# 通过 API 设置模型文件夹路径
config.set_prog_file("./mobilenet_v2.pdmodel")
config.set_params_file("./mobilenet_v2.pdiparams")

# 通过 API 获取 config 中的模型文件和参数文件路径
print(config.prog_file())
print(config.params_file())

# 根据 config 创建 predictor
predictor = paddle_infer.create_predictor(config)

2.2. 从内存中加载预测模型

API定义如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
# 从内存加载模型
# 参数:prog_buffer - 内存中模型结构数据
# prog_buffer_size - 内存中模型结构数据的大小
# params_buffer - 内存中模型参数数据
# params_buffer_size - 内存中模型参数数据的大小
# 返回:None
paddle.inference.Config.set_model_buffer(prog_buffer: str, prog_buffer_size: int,
params_buffer: str, params_buffer_size: int)

# 判断是否从内存中加载模型
# 参数:None
# 返回:bool - 是否从内存中加载模型
paddle.inference.Config.model_from_memory()

代码示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 引用 paddle inference 预测库
import paddle.inference as paddle_infer

# 创建 config
config = paddle_infer.Config()

# 加载模型文件到内存
with open('./mobilenet_v2.pdmodel', 'rb') as prog_file:
prog_data=prog_file.read()

with open('./mobilenet_v2.pdiparams', 'rb') as params_file:
params_data=params_file.read()

# 从内存中加载模型
config.set_model_buffer(prog_data, len(prog_data), params_data, len(params_data))

# 通过 API 获取 config 中 model_from_memory 的值 - True
print(config.model_from_memory())

# 根据 config 创建 predictor
predictor = paddle_infer.create_predictor(config)

重要内容

paddlepaddle中

  • DynamicDimension :表示动态维度,一般是1
  • im_shape:图像经过resize后的大小,表示为H,W, DynamicDimension 表示batch维度
  • image:输入网络的图像,DynamicDimension 表示batch维度,如果输入图像大小为变长,则H,W为None
  • scale_factor:输入图像大小比真实图像大小,表示为scale_y, scale_x
  • multiclass_nms3_0.tmp_0:bbox, NMS的输出,形状为[N, 6], 其中N为预测框的个数,6为[class_id, score, x1, y1, x2, y2]
  • multiclass_nms3_0.tmp_2:bbox_num, 每张图片对应预测框的个数,例如batch_size为2,输出为[N1, N2], 表示第一张图包含N1个预测框,第二张图包含N2个预测框,并且预测框的总个数和NMS输出的第一维N相同

版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 洛屿的小站

打赏

  • wechat

    wechat

  • alipay

    alipay