当前位置:网站首页>Adaptiveavgpool1d internal implementation
Adaptiveavgpool1d internal implementation
2022-07-03 10:00:00 【Star soul is not a dream】
The formula :
# average adaptive pool1d
# suppose input data in shape of [N, C, L], `output_size` is m or [m],
# output shape is [N, C, m], adaptive pool divide L dimension
# of input data into m grids averagely and performs poolings in each
# grid to get output.
# adaptive avg pool performs calculations as follow:
#
# for i in range(m):
# lstart = floor(i * L / m)
# lend = ceil((i + 1) * L / m)
# output[:, :, i] = sum(input[:, :, lstart: lend])/(lstart - lend)
#
import torch
import numpy as np
L = 4
M = 5
input = torch.ones(1, 1, L)
input[0, 0 , 2] = 0
print(input)
AdaptiveAvgPool1D = torch.nn.AdaptiveAvgPool1d(M)
output1 = AdaptiveAvgPool1D(input)
print(output1)
input = np.array(input)
for i in range(M):
lstart = math.floor(i * L / M)
lend = math.ceil((i + 1) * L / M)
print(np.sum(input[:, :, lstart: lend], axis=2) / (lend - lstart))
Output :
tensor([[[1., 1., 0., 1.]]])
tensor([[[1.0000, 1.0000, 0.5000, 0.5000, 1.0000]]])
[[1.]]
[[1.]]
[[0.5]]
[[0.5]]
[[1.]]
Reference resources :
边栏推荐
- Project cost management__ Cost management technology__ Article 8 performance review
- Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit
- STM32 general timer 1s delay to realize LED flashing
- (2)接口中新增的方法
- Successful graduation [3]- blog system update...
- Project cost management__ Cost management technology__ Article 7 completion performance index (tcpi)
- Eight working modes of stm32gpio and chip naming rules
- MySQL的简单使用(增删改查)
- 2. Elment UI date selector formatting problem
- [22 graduation season] I'm a graduate yo~
猜你喜欢
Windows下MySQL的安装和删除
In third tier cities and counties, it is difficult to get 10K after graduation
Mobile phones are a kind of MCU, but the hardware it uses is not 51 chip
yocto 技术分享第四期:自定义增加软件包支持
Happy Dragon Boat Festival—— Zongzi written by canvas~~~~~
MYSQL数据库底层基础专栏
JS foundation - prototype prototype chain and macro task / micro task / event mechanism
03 fastjason solves circular references
Which language should I choose to program for single chip microcomputer
STM32 serial communication principle
随机推荐
There is no shortcut to learning and development, and there is almost no situation that you can learn faster by leading the way
(1) What is a lambda expression
Programming ideas are more important than anything, not more than who can use several functions, but more than the understanding of the program
Project scope management__ Scope management plan and scope specification
Education is a pass and ticket. With it, you can step into a higher-level environment
QT qcombobox QSS style settings
Serial port programming
Stm32f04 clock configuration
An executable binary file contains more than machine instructions
Installation and removal of MySQL under Windows
How does the memory database give full play to the advantages of memory?
干单片机这一行的时候根本没想过这么多,只想着先挣钱养活自己
STM32 serial communication principle
The new series of MCU also continues the two advantages of STM32 product family: low voltage and energy saving
A lottery like scissors, stone and cloth (C language)
[CSDN] C1 training problem analysis_ Part IV_ Advanced web
Fundamentals of Electronic Technology (III)_ Integrated operational amplifier and its application__ Basic arithmetic circuit
El table X-axis direction (horizontal) scroll bar slides to the right by default
Application of external interrupts
In third tier cities and counties, it is difficult to get 10K after graduation