当前位置:网站首页>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 :
边栏推荐
- Fundamentals of Electronic Technology (III)_ Chapter 2 principle of amplification circuit__ Crystal triode and field effect triode
- Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit
- CEF download, compile project
- Installation and removal of MySQL under Windows
- It is difficult to quantify the extent to which a single-chip computer can find a job
- byte alignment
- Eight working modes of stm32gpio and chip naming rules
- Notes on C language learning of migrant workers majoring in electronic information engineering
- Stm32f04 clock configuration
- Gif image analysis drawing RGB to YUV table lookup method to reduce CPU occupancy
猜你喜欢

openEuler kernel 技术分享 - 第1期 - kdump 基本原理、使用及案例介绍

STM32 serial communication principle

STM32 external interrupt experiment

Assignment to '*' form incompatible pointer type 'linkstack' {aka '*'} problem solving

对于新入行的同学,如果你完全没有接触单片机,建议51单片机入门

Project cost management__ Cost management technology__ Article 6 prediction

Hal library sets STM32 clock

2021-10-27

CEF下载,编译工程

NR PUCCH format0 sequence generation and detection mechanism
随机推荐
[CSDN] C1 training problem analysis_ Part IV_ Advanced web
El table X-axis direction (horizontal) scroll bar slides to the right by default
单片机学到什么程度能找到工作,这个标准不好量化
学历是一张通行证,门票,你有了它,可以踏入更高层次的环境里
Project cost management__ Topic of comprehensive calculation
Chromium Embedded Framework (CEF) 介绍
2021-01-03
Assignment to '*' form incompatible pointer type 'linkstack' {aka '*'} problem solving
[CSDN] C1 training problem analysis_ Part II_ Web Foundation
openEuler kernel 技術分享 - 第1期 - kdump 基本原理、使用及案例介紹
Not many people can finally bring their interests to college graduation
Comment la base de données mémoire joue - t - elle l'avantage de la mémoire?
自動裝箱與拆箱了解嗎?原理是什麼?
【力扣刷题笔记(二)】特别技巧,模块突破,45道经典题目分类总结,在不断巩固中精进
01 business structure of imitation station B project
I didn't think so much when I was in the field of single chip microcomputer. I just wanted to earn money to support myself first
Stm32f407 key interrupt
JS foundation - prototype prototype chain and macro task / micro task / event mechanism
嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走
Schematic diagram and connection method of six pin self-locking switch