当前位置:网站首页>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 :
边栏推荐
- JS foundation - prototype prototype chain and macro task / micro task / event mechanism
- Stm32f407 key interrupt
- Quelle langue choisir pour programmer un micro - ordinateur à puce unique
- Basic knowledge of MySQL database (an introduction to systematization)
- All processes of top ten management in project management
- Comment la base de données mémoire joue - t - elle l'avantage de la mémoire?
- 【力扣刷题笔记(二)】特别技巧,模块突破,45道经典题目分类总结,在不断巩固中精进
- 万字手撕七大排序(代码+动图演示)
- uniapp 实现微信小程序全局分享及自定义分享按钮样式
- [CSDN] C1 training problem analysis_ Part II_ Web Foundation
猜你喜欢
NR PUCCH format0 sequence generation and detection mechanism
It is difficult to quantify the extent to which a single-chip computer can find a job
嵌入式系统没有特别明确的定义
CEF download, compile project
2.Elment Ui 日期选择器 格式化问题
嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走
JMX、MBean、MXBean、MBeanServer 入门
Code word in NR
2021-10-27
JS基础-原型原型链和宏任务/微任务/事件机制
随机推荐
It is difficult to quantify the extent to which a single-chip computer can find a job
MYSQL数据库底层基础专栏
2021-10-28
2020-08-23
byte alignment
Basic knowledge of MySQL database (an introduction to systematization)
Project cost management__ Plan value_ Earned value_ Relationship among actual cost and Countermeasures
自動裝箱與拆箱了解嗎?原理是什麼?
Programming ideas are more important than anything, not more than who can use several functions, but more than the understanding of the program
Synchronization control between tasks
2.Elment Ui 日期选择器 格式化问题
一个可执行的二进制文件包含的不仅仅是机器指令
Not many people can finally bring their interests to college graduation
STM32 general timer 1s delay to realize LED flashing
openEuler kernel 技術分享 - 第1期 - kdump 基本原理、使用及案例介紹
2021-01-03
Stm32f04 clock configuration
[22 graduation season] I'm a graduate yo~
In third tier cities and counties, it is difficult to get 10K after graduation
(2)接口中新增的方法