当前位置:网站首页>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
边栏推荐
- CentOS installs redis multi master multi slave cluster
- MySQL Chapter 6 Summary
- MySQL第五章总结
- The first batch of 12 enterprises settled in! Opening of the first time-honored product counter in Guangzhou
- Flutter与原生通信(上)
- Linux下安装Mysql【详细】
- 基础-MySQL
- Searchview click failure
- leetCode-链表的中间结点
- June training (the 26th day) - collective search
猜你喜欢

全渠道、多场景、跨平台,App如何借助数据分析渠道流量

Selection of webrtc video codec type VP8 H264 or other? (openh264 encoding, ffmpeg decoding)

SSH, SCP command appears permission denied, please try again solution

P1296 whispers of cows (quick row + binary search)

MySQL第六次作业-查询数据-多条件

MySQL 11th job - view application

904. 水果成篮

字符串常量池、class常量池和运行时常量池

【Leetcode】76. 最小覆盖子串

利用foreach循环二维数组
随机推荐
[depth first search] 312 Poke balloon
904. 水果成篮
Blog article index summary -- Software Engineering
Function run time
開發者,微服務架構到底是什麼?
瑞萨电子面向物联网应用推出完整的智能传感器解决方案
Appium automation test foundation - mobile end test environment construction (II)
MySQL第六次作业-查询数据-多条件
创建对象的时候堆内存的分配
Flutter与原生通信(上)
MySQL 12th job - Application of stored procedure
What is LSP
Little red book - Summary of internal sales spike project
SSH, SCP command appears permission denied, please try again solution
MySQL第五章总结
Allocation of heap memory when creating objects
MySQL第六章总结
Développeur, quelle est l'architecture des microservices?
MySQL第十三次作业-事务管理
Small example of SSM project, detailed tutorial of SSM integration