建议使用以下浏览器,以获得最佳体验。 ie 9.0 以上版本 chrome 31 谷歌浏览器 firefox 30 火狐浏览器
温馨提示

抱歉,您需设置社区昵称后才能参与社区互动!

前往修改
我再想想
选择版块
主题:4944帖子:15307

问题处理中

【 问题求助-执行问题】

【mindspore】【梯度计算功能】customwithlosscell计算梯度报错

2022/6/14 345

【功能模块】

customwithlosscell计算loss没有问题,在计算梯度时报错。


【操作步骤&问题现象】

1、customwithlosscell计算network的loss没有问题,在计算梯度时报错。

2、报错内容似乎为strideslicegrad不支持梯度计算,不知道是否是这个原因,且不知道strideslicegrad对应于网络中的哪个函数。

3、在之前在网络中我用了ops.rsqrt(),在计算梯度时也报同样错误,内容是将strideslicegrad替换为rsqrt,我把网络中的ops.rsqrt()去掉了,就没有报rsqrt的错,但是报了如下的错。麻烦解释一下报错原因以及strideslicegrad是指哪个函数。


【截图信息】


【日志信息】(可选,上传日志内容或者附件)


回复8

0 0
2022/6/15 08:58

用户您好,欢迎安装使用mindspore。上述的问题已经收到,会尽快给您解答回复

2 0
2022/6/20 16:21

用户您好,您的代码是否使用了反向过程,如果是的话那可能是反向传播不支持切片。您能提供一下您的代码我们再来看看具体是什么问题

昨天 09:33

感谢回复,我在计算loss的过程中使用了grad_op来获取梯度,然后将梯度的均值作为loss,给到customwithlosscell,然后报错。已经定位到是因为grad_op导致的,但是不知道原因。您说的是否使用了反向过程指的是计算loss时进行了反向传播获取梯度吗?
... 展开

昨天 09:38

代码在楼下给了
... 展开
0 0
2022/6/21 09:37
用户您好,您的代码是否使用了反向过程,如果是的话那可能是反向传播不支持切片。您能提供一下您的代码我们再来看看具体是什么问题

代码内容比较多,不太好复现,这里给出了customwithlosscell,当调用self.stylegan2loss.accumulate_gradients时,计算如下方第二张图,return的值在construct里即为loss

class customwithlosscell(nn.cell):
def __init__(self, g_mapping, g_synthesis, d):
super(customwithlosscell, self).__init__()
self.g_mapping = g_mapping
self.g_synthesis = g_synthesis
self.d = d
self.stylegan2loss = stylegan2loss(self.g_mapping, self.g_synthesis, self.d, r1_gamma=5.0)

# def construct(self, target_features, synth_features, reg_loss, regularize_noise_weight):
def construct(self, phase, real_img, pose, real_c, gen_z, gen_c, sync, gain):
loss = self.stylegan2loss.accumulate_gradients(phase, real_img, pose, real_c, gen_z, gen_c, sync, gain)
return loss
if do_gpl:
batch_size = gen_z.shape[0] // self.pl_batch_shrink
gen_ws = self.run_g_mapping(gen_z[:batch_size], gen_c[:batch_size], sync=sync)
pl_grads = grad_op(net(self.g_synthesis))(gen_ws, pose[:batch_size])
pl_lengths = sqrt(square(pl_grads).sum(2).mean(1))
pl_mean = self.pl_mean (pl_lengths.mean() - self.pl_mean) * self.pl_decay
self.pl_mean = pl_mean.copy()
pl_penalty = square(pl_lengths - pl_mean)
loss_gpl = pl_penalty * self.pl_weight
print('loss_gpl: ', loss_gpl.mean())
return mul(loss_gpl.mean(), gain)

0 0
2022/6/21 19:08
用户您好,您的代码是否使用了反向过程,如果是的话那可能是反向传播不支持切片。您能提供一下您的代码我们再来看看具体是什么问题

是的用户就是说grad_od来获取梯度过程

0 0
2022/6/21 19:10
是的用户就是说grad_od来获取梯度过程

然后由于你给出的代码片段太少我们不好进行debug,能否麻烦你在gitee上创建一个仓库然后存放所有代码或者直接通过附件形式提供代码

0 0
2022/6/21 22:09

感谢分享

0 0
2022/6/21 22:14

感谢分享

0 0
2022/6/21 22:21

感谢分享

上划加载中
直达楼层
全部回复
正序浏览
标签
您还可以添加5个标签
  • 没有搜索到和“关键字”相关的标签
  • 云产品
  • 亚博平台下载的解决方案
  • 技术领域
  • 通用技术
  • 平台功能
取消

【mindspore】【梯度计算功能】customwithlosscell计算梯度报错-yb体育官方

您已采纳当前回复为最佳回复

发帖: 4粉丝: 0

发表于2022年06月14日 22:38:34 345 8
[执行问题] 【mindspore】【梯度计算功能】customwithlosscell计算梯度报错

【功能模块】

customwithlosscell计算loss没有问题,在计算梯度时报错。


【操作步骤&问题现象】

1、customwithlosscell计算network的loss没有问题,在计算梯度时报错。

2、报错内容似乎为strideslicegrad不支持梯度计算,不知道是否是这个原因,且不知道strideslicegrad对应于网络中的哪个函数。

3、在之前在网络中我用了ops.rsqrt(),在计算梯度时也报同样错误,内容是将strideslicegrad替换为rsqrt,我把网络中的ops.rsqrt()去掉了,就没有报rsqrt的错,但是报了如下的错。麻烦解释一下报错原因以及strideslicegrad是指哪个函数。


【截图信息】


【日志信息】(可选,上传日志内容或者附件)


分享文章到朋友圈

分享文章到微博
您已采纳当前回复为最佳回复

发帖: 399粉丝: 59

级别 : 版主,版块专家

发表于2022年06月15日 08:58:49

用户您好,欢迎安装使用mindspore。上述的问题已经收到,会尽快给您解答回复

您已采纳当前回复为最佳回复

发帖: 0粉丝: 0

发表于2022年06月20日 16:21:08

用户您好,您的代码是否使用了反向过程,如果是的话那可能是反向传播不支持切片。您能提供一下您的代码我们再来看看具体是什么问题

评论
昨天 09:33

感谢回复,我在计算loss的过程中使用了grad_op来获取梯度,然后将梯度的均值作为loss,给到customwithlosscell,然后报错。已经定位到是因为grad_op导致的,但是不知道原因。您说的是否使用了反向过程指的是计算loss时进行了反向传播获取梯度吗?

... 查看全部
昨天 09:38

代码在楼下给了

... 查看全部
您已采纳当前回复为最佳回复

发帖: 4粉丝: 0

发表于2022年06月21日 09:37:35
用户您好,您的代码是否使用了反向过程,如果是的话那可能是反向传播不支持切片。您能提供一下您的代码我们再来看看具体是什么问题

代码内容比较多,不太好复现,这里给出了customwithlosscell,当调用self.stylegan2loss.accumulate_gradients时,计算如下方第二张图,return的值在construct里即为loss

class customwithlosscell(nn.cell):
def __init__(self, g_mapping, g_synthesis, d):
super(customwithlosscell, self).__init__()
self.g_mapping = g_mapping
self.g_synthesis = g_synthesis
self.d = d
self.stylegan2loss = stylegan2loss(self.g_mapping, self.g_synthesis, self.d, r1_gamma=5.0)

# def construct(self, target_features, synth_features, reg_loss, regularize_noise_weight):
def construct(self, phase, real_img, pose, real_c, gen_z, gen_c, sync, gain):
loss = self.stylegan2loss.accumulate_gradients(phase, real_img, pose, real_c, gen_z, gen_c, sync, gain)
return loss
if do_gpl:
batch_size = gen_z.shape[0] // self.pl_batch_shrink
gen_ws = self.run_g_mapping(gen_z[:batch_size], gen_c[:batch_size], sync=sync)
pl_grads = grad_op(net(self.g_synthesis))(gen_ws, pose[:batch_size])
pl_lengths = sqrt(square(pl_grads).sum(2).mean(1))
pl_mean = self.pl_mean (pl_lengths.mean() - self.pl_mean) * self.pl_decay
self.pl_mean = pl_mean.copy()
pl_penalty = square(pl_lengths - pl_mean)
loss_gpl = pl_penalty * self.pl_weight
print('loss_gpl: ', loss_gpl.mean())
return mul(loss_gpl.mean(), gain)

您已采纳当前回复为最佳回复

发帖: 0粉丝: 0

发表于2022年06月21日 19:08:09
用户您好,您的代码是否使用了反向过程,如果是的话那可能是反向传播不支持切片。您能提供一下您的代码我们再来看看具体是什么问题

是的用户就是说grad_od来获取梯度过程

您已采纳当前回复为最佳回复

发帖: 0粉丝: 0

发表于2022年06月21日 19:10:01
是的用户就是说grad_od来获取梯度过程

然后由于你给出的代码片段太少我们不好进行debug,能否麻烦你在gitee上创建一个仓库然后存放所有代码或者直接通过附件形式提供代码

您已采纳当前回复为最佳回复

慕雪

发帖: 2粉丝: 2

发表于2022年06月21日 22:09:55

感谢分享

您已采纳当前回复为最佳回复

红鲤鱼与绿鲤鱼

发帖: 2粉丝: 2

发表于2022年06月21日 22:14:44

感谢分享

您已采纳当前回复为最佳回复

zdnyyh

发帖: 2粉丝: 2

发表于2022年06月21日 22:21:21

感谢分享

您需要登录后才可以回帖 | 立即注册

推荐阅读

邀请回答
您可以邀请3位专家
您对问题的回复是否满意?
满意度
非常满意 满意 一般 不满意
我要反馈
0/200
网站地图