当前位置:网站首页>[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
边栏推荐
- Google Earth engine - the use of the neighborhood tobands function
- Bug summary
- Heap and stack in embedded development
- Analysis of WPF multi finger application development
- Why do I have to clean up data?
- Excel file processing tool class (based on easyexcel)
- Use es to realize fuzzy search and search recommendation of personal blog
- From the big guy baptism! 2022 headline first hand play MySQL advanced notes, and it is expected to penetrate P7
- 1、 MFC introduction
- Branch and loop statements in C language learning
猜你喜欢

Let me introduce you to the partition automatic management of data warehouse

How painful is it to write unit tests? Can you do it

NXP i.mx6q development board software and hardware are all open source, and the schematic diagram of the core board is provided

Be an artistic test / development programmer and slowly change yourself

Exception, import package and file operation

Can Baidu network disk yundetectservice.exe be disabled and closed

Dynamic programming-01 knapsack rolling array optimization

每周小结(*66):下一个五年

Bug summary

SQL file import database - Nanny level tutorial
随机推荐
Let me introduce you to the partition automatic management of data warehouse
Video chat source code - one-to-one live broadcast system source code
Wechat applet development learning 5 (custom components)
How painful is it to write unit tests? Can you do it
指针与数组
The new version of SSM video tutorial in shangsilicon valley was released
From the big guy baptism! 2022 headline first hand play MySQL advanced notes, and it is expected to penetrate P7
What can testers do when there is an online bug?
LeetCode_ 392_ Judgement subsequence
Qt学习-利用数据库单例完成 登录匹配 + 注册 功能实现
HTB-Aragog
Promtool Check
cloud chart
SQLite database operation
Excel文件处理工具类(基于EasyExcel)
Two numbers that appear only once in the array
Use es to realize fuzzy search and search recommendation of personal blog
JS ------ Chapter 5 functions and events
[hero planet July training leetcode problem solving daily] 24th line segment tree
EF core :自引用的组织结构树