当前位置:网站首页>[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
边栏推荐
- 【无标题】
- 线段树杂谈
- Processing of ffmpeg wasapi can't activate audio endpoint error
- dpkg : Breaks: libapt-pkg5.0 (< 1.7~b) but 1.6.15 is to be installedE: Broken packages
- ROS机械臂 Movelt 学习笔记3 | kinect360相机(v1)相关配置
- codeforces round #797 ABCDEFG
- Promtool Check
- The new version of SSM video tutorial in shangsilicon valley was released
- Bug summary
- SQL file import database - Nanny level tutorial
猜你喜欢

做一个文艺的测试/开发程序员,慢慢改变自己......

Dynamic programming-01 knapsack rolling array optimization

Development direction and problems of optaplanner

HTB-Aragog

Implement a avatar looping control

Can Baidu network disk yundetectservice.exe be disabled and closed

SQL file import database - Nanny level tutorial

EF core: self referencing organizational structure tree

2022 最 NB 的 JVM 基础到调优笔记, 吃透阿里 P6 小 case

Efficiency increased by 98%! AI weapon behind operation and maintenance inspection of high altitude photovoltaic power station
随机推荐
[leetcode weekly replay] game 83 biweekly 20220723
GUI basic application
Implement a avatar looping control
Promtool Check
1. Smoke test
Are you still using system. Currenttimemillis()? Take a look at stopwatch
3. Pressure test
Netease game Flink SQL platform practice
Wine wechat initialization 96% stuck
LeetCode_6124_第一个出现两次的字母
2022 the most NB JVM foundation to tuning notes, thoroughly understand Alibaba P6 small case
Only by learning these JMeter plug-ins can we design complex performance test scenarios
How painful is it to write unit tests? Can you do it
EF core :自引用的组织结构树
50 places are limited to open | with the news of oceanbase's annual press conference coming!
Beisen prospectus: the advantages of the track are prominent, and integration + medium and large customers are plus points
[untitled]
Regular expression learning
Development direction and problems of optaplanner
动态规划-01背包滚动数组优化