当前位置:网站首页>Adaptiveavgpool2d does not support onnx export. Customize a class to replace adaptiveavgpool2d
Adaptiveavgpool2d does not support onnx export. Customize a class to replace adaptiveavgpool2d
2022-06-26 10:35:00 【Master Yiwen】
AdaptiveAvgPool2D I won't support it onnx export , The export process will tell you ,onnx The dynamic operation barabara... Is not supported
I use it pp_liteseg Export to onnx Model , Are all the same ,paddle and Torch Of Adaptive Pool2D It's all dynamic ,onnx Not supported for the time being , I use the following formula , take AdaptiveAvgPool2D Changed , It can be used onnx It is derived that , But you need to specify the size of the original image , And the size of the output graph
h s t a r t = f l o o r ( i ∗ H i n / H o u t ) h e n d = c e i l ( ( i + 1 ) ∗ H i n / H o u t ) w s t a r t = f l o o r ( j ∗ W i n / W o u t ) w e n d = c e i l ( ( j + 1 ) ∗ W i n / W o u t ) O u t p u t ( i , j ) = ∑ I n p u t [ h s t a r t : h e n d , w s t a r t : w e n d ] ( h e n d − h s t a r t ) ∗ ( w e n d − w s t a r t ) \begin{aligned} hstart &= floor(i * H_{in} / H_{out})\\ hend &= ceil((i + 1) * H_{in} / H_{out})\\ wstart &= floor(j * W_{in} / W_{out}) \\ wend &= ceil((j + 1) * W_{in} / W_{out}) \\ Output(i ,j) &= \frac{\sum Input[hstart:hend, wstart:wend]}{(hend - hstart) * (wend - wstart)} \end{aligned} hstarthendwstartwendOutput(i,j)=floor(i∗Hin/Hout)=ceil((i+1)∗Hin/Hout)=floor(j∗Win/Wout)=ceil((j+1)∗Win/Wout)=(hend−hstart)∗(wend−wstart)∑Input[hstart:hend,wstart:wend]
Reference from :
AdaptiveAvgPool2D
class CostomAdaptiveAvgPool2D(nn.Layer):
def __init__(self, output_size, input_size):
super(CostomAdaptiveAvgPool2D, self).__init__()
self.output_size = output_size
self.input_size = input_size
def forward(self, x):
H_in, W_in = self.input_size
H_out, W_out = [self.output_size, self.output_size] \
if isinstance(self.output_size, int) \
else self.output_size
out_i = []
for i in range(H_out):
out_j = []
for j in range(W_out):
hs = int(np.floor(i * H_in / H_out))
he = int(np.ceil((i+1) * H_in / H_out))
ws = int(np.floor(j * W_in / W_out))
we = int(np.ceil((j+1) * W_in / W_out))
# print(hs, he, ws, we)
kernel_size = [he-hs, we-ws]
out = F.avg_pool2d(x[:, :, hs:he, ws:we], kernel_size)
out_j.append(out)
out_j = paddle.concat(out_j, -1)
out_i.append(out_j)
out_i = paddle.concat(out_i, -2)
return out_i
use CostomAdaptiveAvgPool2D Exchange AdaptiveAvgPool2D, And you can specify the size of the original image and the output image

[14,14] Is the size of the input graph , This is me. pp_liteseg Input shape yes 224 × 224 224\times 224 224×224, So on the upper floor shape yes
[-1, 512, 14, 14]
Then three at a time AdaptiveAvgPool2D become
[-1, 512, 1, 1]
[-1, 512, 2, 2]
[-1, 512, 4, 4]
then paddle2onnx Export it
paddle2onnx --model_dir . \
--model_filename model.pdmodel \
--params_filename model.pdiparams \
--opset_version 11 \
--save_file output.onnx
边栏推荐
- MySQL 13th job - transaction management
- Oracle sqlplus 查询结果显示优化
- 二叉树常见面试题
- RDB持久化验证测试
- Oracle11g 启动数据库时报错 ORA-27154: post/wait create failed
- Blog article index Summary - wechat games
- Win10安装tensorflow-quantum过程详解
- 2. merge two ordered arrays
- Omni channel, multi scenario and cross platform, how does app analyze channel traffic with data
- Global and Chinese market of recycled paper 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

The fourteenth MySQL operation - e-mall project

The sixth MySQL job - query data - multiple conditions

Establishment of smart dialogue platform for wechat official account

The first batch of 12 enterprises settled in! Opening of the first time-honored product counter in Guangzhou

利用foreach循环二维数组

MySQL 13th job - transaction management

MySQL第十三次作业-事务管理

MySQL 11th job - view application

118. 杨辉三角

904. 水果成篮
随机推荐
String constant pool, class constant pool, and runtime constant pool
MySQL Chapter 4 Summary
基础-MySQL
【Leetcode】76. 最小覆盖子串
Oracle11g 启动数据库时报错 ORA-27154: post/wait create failed
Blog article index Summary - wechat games
The IE mode tab of Microsoft edge browser is stuck, which has been fixed by rolling back the update
Call API interface to generate QR code of wechat applet with different colors
Small example of SSM project, detailed tutorial of SSM integration
Luogu 1146 coin flip
MySQL第四章总结
118. 杨辉三角
Servlet learning notes II
Global and Chinese market of cryogenic bulk tanks 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of electronic pet door 2022-2028: Research Report on technology, participants, trends, market size and share
Use of exec series functions (EXECL, execlp, execle, execv, execvp)
Flutter与原生通信(上)
MySQL 12th job - Application of stored procedure
Common interview questions of binary tree
【在线仿真】Arduino UNO PWM 控制直流电机转速