当前位置:网站首页>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
边栏推荐
- Hcia-dhcp experiment
- exec系列函数(execl、execlp、execle、execv、execvp)使用
- What is in the method area - class file, class file constant pool, runtime constant pool
- Global and Chinese market of amateur football helmets 2022-2028: Research Report on technology, participants, trends, market size and share
- JS reverse | four libraries and one platform response data encryption
- 字符串常量池、class常量池和运行时常量池
- Express (I) - easy to get started
- MySQL 9th job - connection Query & sub query
- VS或Qt编译链接过程中出现“无法解析的外部符号”的原因:
- About multi table query of MySQL
猜你喜欢

MySQL seventh job - update data

Win10安装tensorflow-quantum过程详解

利用foreach循环二维数组

MySQL第九次作业-连接查询&子查询

Small example of SSM project, detailed tutorial of SSM integration

Basic string operations in C

【LeetCode】59. Spiral matrix II

Little red book - Notes inspiration - project summary

哪些PHP开源作品值得关注

MySQL 13th job - transaction management
随机推荐
What is a botnet
exec系列函数(execl、execlp、execle、execv、execvp)使用
MySQL第九次作业-连接查询&子查询
Little red book - Summary of internal sales spike project
JVM的符号引用和直接引用是什么
瑞萨电子面向物联网应用推出完整的智能传感器解决方案
Global and Chinese market for baked potato chips 2022-2028: Research Report on technology, participants, trends, market size and share
[sans titre]
MySQL第十一作业-视图的应用
Blog article index summary -- Software Engineering
MySQL 10th job - View
開發者,微服務架構到底是什麼?
cmake / set 命令
创建对象的时候堆内存的分配
Global and Chinese markets of children's electronic thermometers 2022-2028: Research Report on technology, participants, trends, market size and share
六月集训(第26天) —— 并查集
1. sum of two numbers (leetcode topic)
Luogu 1146 coin flip
Oracle11g 启动数据库时报错 ORA-27154: post/wait create failed
【无标题】