当前位置:网站首页>[mindspore ascend] [user defined operator] graph_ In mode, customize how to traverse tensor
[mindspore ascend] [user defined operator] graph_ In mode, customize how to traverse tensor
2022-07-25 00:12:00 【Xiaole happy】
Because you need to use belt weights Of SoftmaxCrossEntropyLoss, It's just mindspore Provided nn.SoftmaxCrossEntropyLoss An operator is customized on .
In this operator , I need to traverse one dimension Tensor. stay PYNATIVE In the pattern , I will Tensor To numpy Array implements this operation . But in GRAPH_MODE There is no way to Tensor To numpy or list, How to operate ?
【 Related codes 】
# labels_int: (n,) dimension Tensor
# self.ignore_label: int
# self.cls_weight: (c, ) dimension Tensor
weights_np = np.ones((labels_int.shape[0]))
labels_np = labels_int.asnumpy()
weights_np[labels_np == self.ignore_label] = 0
cls_weight_np = self.cls_weight.asnumpy()
for idx, v in enumerate(cls_weight_np, 0):
weights_np[labels_np == idx] *= vYour problem is that you want to be in graph mode , Traverse one dimension Tensor, Currently, there are two ways to traverse Tensor.
The first way to get Tensor The length of the first dimension , Then traverse through the integer index , as follows :
for i in range(x.shape[0]): x[i]The second way is through enumerate Interface , Direct traversal , as follows :
for i, ele in enumerate(x, 0): ele
边栏推荐
- Excel file processing tool class (based on easyexcel)
- QT project - security monitoring system (function realization of each interface)
- Answers to some problems encountered in the process of Xperia XZ (f8332) brushing and root
- Analyzing the principle of DNS resolution in kubernetes cluster
- NXP i.mx6q development board software and hardware are all open source, and the schematic diagram of the core board is provided
- LeetCode_ 6124_ The first letter that appears twice
- Docker container Django + MySQL service
- Beisen prospectus: the advantages of the track are prominent, and integration + medium and large customers are plus points
- Excel文件处理工具类(基于EasyExcel)
- 每周小结(*66):下一个五年
猜你喜欢

Beisen prospectus: the advantages of the track are prominent, and integration + medium and large customers are plus points

Can Baidu network disk yundetectservice.exe be disabled and closed

Kubernetes application design guide

With screen and nohup running, there is no need to worry about deep learning code anymore | exiting the terminal will not affect the operation of server program code

4. Immersion test

Qt项目-安防监控系统(各个界面功能实现)

Advanced function of postman

Be an artistic test / development programmer and slowly change yourself

数组中只出现一次的两个数字

Qt学习-利用数据库单例完成 登录匹配 + 注册 功能实现
随机推荐
Let me introduce you to the partition automatic management of data warehouse
ROS机械臂 Movelt 学习笔记3 | kinect360相机(v1)相关配置
Quartus:17.1版本的Quartus安装Cyclone 10 LP器件库
[nuxt 3] (x) runtime configuration
线段树杂谈
[leetcode weekly replay] game 83 biweekly 20220723
UART
LP liquidity pledge mining system development detailed procedure
Redis memory analysis tool RMA usage
With screen and nohup running, there is no need to worry about deep learning code anymore | exiting the terminal will not affect the operation of server program code
Palm package manager of kubernetes learning offline installation of NFS client provider
.net redis client newlife.redis.core library usage
Paper time review MB2: build a behavior model for autonomous databases
91. (leaflet chapter) leaflet situation plotting - offensive direction drawing
Pain and happiness -nio programming
Install software on kubernetes cluster using helm 3 package manager
1、 MFC introduction
Processing PDF and JPG files in VB6
[acwing周赛复盘] 第 61 场周赛20220723
The laneatt code is reproduced and tested with the video collected by yourself