用户您好,您的代码是否使用了反向过程,如果是的话那可能是反向传播不支持切片。您能提供一下您的代码我们再来看看具体是什么问题
代码内容比较多,不太好复现,这里给出了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)
用户您好,欢迎安装使用mindspore。上述的问题已经收到,会尽快给您解答回复
用户您好,您的代码是否使用了反向过程,如果是的话那可能是反向传播不支持切片。您能提供一下您的代码我们再来看看具体是什么问题
昨天 09:33
昨天 09:38
代码内容比较多,不太好复现,这里给出了customwithlosscell,当调用self.stylegan2loss.accumulate_gradients时,计算如下方第二张图,return的值在construct里即为loss
是的用户就是说grad_od来获取梯度过程
然后由于你给出的代码片段太少我们不好进行debug,能否麻烦你在gitee上创建一个仓库然后存放所有代码或者直接通过附件形式提供代码
感谢分享
感谢分享
感谢分享