当前位置:网站首页>【mindspore】【Categorical】softmax数据放入Categorical类出现和不为1的错误
【mindspore】【Categorical】softmax数据放入Categorical类出现和不为1的错误
2022-08-10 03:28:00 【小乐快乐】
Categorical类
import mindspore
import mindspore.nn as nn
import numpy as np
from mindspore import Tensor
from mindspore.nn.probability.distribution import Categorical
class Actor(nn.Cell):
def __init__(self, state_dim, action_dim):
super().__init__()
self.fc = nn.SequentialCell([
nn.Dense(in_channels=state_dim, out_channels=32),
nn.ReLU(),
nn.Dense(in_channels=32, out_channels=action_dim),
nn.Tanh()
])
self.softmax = nn.Softmax(axis=-1)
def construct(self, state):
out = self.fc(state)
return self.softmax(out)
actor = Actor(4, 2)
for i in range(1000):
x = Tensor(np.random.random(size=(10, 4)),dtype=mindspore.float32)
y = actor(x)
print(y)
cat = Categorical(y)
index = cat.sample()
print(index)
【操作步骤&问题现象】
今天使用了nn.softmax函数对神经网络输出处理,经过对神经网络的输出处理后,变为一个相加为1的Tensor,然后我用这个Tensor去输入到Categorical中,在训练过程中,有时会出现数据放到Categorical里面会出现相加不为1的错误
对于同样的数据,我把它放到pytorch的Categorical类里面处理发现没有错误,由此我在想是否是因为精度的原因,比如X为此tensor,允许X.sum() = 1 - epsilon,这个epsilon是否可以调大一点?
mindspore1.5-cpu,python3.7.5,windows 10环境下,Categorical类中的精度调整之后发现就不报错了。
边栏推荐
猜你喜欢
Mini Program Navigation and Navigation Parameters
uniapp 路由与页面跳转
Embedded Sharing Collection 32
驱动程序开发:按键中断之异步通知
maya图片如何渲染
同样是初级测试,凭什么他比我薪资高 5000 块?
全面深入了解什么是反向代理和负载均衡
盘式导电滑环的优点和缺点
It's almost 35, still "did a little"?What happened to the test workers who had been in the industry for a few years?
【科研绘图】琴图 +箱型图混合 matplotlib库和seabsorn库的使用
随机推荐
The same is a primary test, why does he pay 5,000 yuan more than me?
使用 requestAnimationFrame 提升 web 性能
【Verilog数字系统设计(夏雨闻)6-------模块的结构、数据类型、变量和基本运算符号2】
TCP协议之《自动阻塞CORK控制》
从零开始配置 vim(9)——初始配置
Qt 线程常用同步方式
如何整合全流程数据,全面提升研发效能?|2分钟了解 ONES
c语言:通讯录(动态版本)
matlab simulink response spectrum calculation
Dijkstra求最短路
一个刚入行的测试员怎么样做好功能测试?测试思维真的很重要
使用flink-sql写入mysql的时候,只指定插入的字段,但是会报错id字段错误,没有默认值,创
文件操作【c语言】
互联网公司高频面试题精讲:测试计划和测试方案有什么区别?
数据库中数据的正确性和相容性是什么
书法家唐效奇
Difference between netstat and ss command
如何开启热部署Devtools
TCP协议之《TSQ控制》
golang:base64编解码(转)