当前位置:网站首页>Detailed explanation of pytoch's scatter function
Detailed explanation of pytoch's scatter function
2022-06-30 08:31:00 【Wu lele~】
List of articles
Preface
Looking at FCOS Algorithm source code , It is found that... Is used to obtain positive sample points scatter This function , So record it .
1、 Interpretation of official documents
Post the link first :scatter Official interpretation
Tensor.scatter_(dim, index, src, reduce=None) → Tensor
Receive three parameters : dim, index and src. This function is used to stay dim Dimensionally , according to index Index provided , from src Extract the corresponding element from the to assign to Tensor. The following is an official example of a three-dimensional tensor .
Two points need to be noted :index and src Of dim The dimensions must be the same ! In the official 3-D tensor For example , namely self、src and index The dimensions of are 3; if 2D-tensor be self、src and index The dimensions of are 2. Because I need to use index As an index , so index The size of the element in must be <self.size(d) And src.size(d).
2、 for instance

Attach code :
src = torch.Tensor([[0,1,2,3,4],[5,6,7,8,9]])
self = torch.zeros((3,5))
index = torch.tensor([[0,1,2,0,0],[2,0,0,1,2]])
self.scatter_(dim=0,index=index,src=src)
print(self)
Output :
summary
In actual programming ,src It is often scalar , Is a constant . According to the definition , On the right side of the equation src[i][j] Identical to scalar . Is this time scatter The function is based on index take self The corresponding position in becomes a constant .
边栏推荐
猜你喜欢

Redis设计与实现(一)| 数据结构 & 对象

【NVMe2.0b 14-3】Doorbell Buffer Config command、Device Self-test command

电流探头电路分析

一次cpu 跌底排查

亚马逊测评术语有哪些?

Redis design and Implementation (III) | interaction between server and client (event IO model)

Sword finger offer II 076 The kth largest number in the array (use heap to solve TOPK problem)

vim 从嫌弃到依赖(21)——跨文件搜索

【NVMe2.0b 14-5】Firmware Download/Commit command

Redis design and Implementation (IV) | master-slave replication
随机推荐
【NVMe2.0b 14-5】Firmware Download/Commit command
Axure制作菜单栏效果
牛客小白月賽52
This point in JS
云服务器上部署仿牛客网项目
【NVMe2.0b 14-5】Firmware Download/Commit command
Transformer architecture understanding
小心transmittable-thread-local的这个坑
Leetcode47. full arrangement II
Cesium learning notes (VI) particle system
Map,String,Json之間轉換
Flink Exception -- No ExecutorFactory found to execute the application
Rendering engine development
【NVMe2.0b 14-1】Abort、Asynchronous Event Request、Capacity Management command
Tidb 6.0: making Tso more efficient tidb Book rush
Enter the URL in the browser and display it on the page
【NVMe2.0b 14-5】Firmware Download/Commit command
QT event cycle
Unity简单shader
C preliminary chapter learning route