提交 5c751d8f 编写于 作者: L lvmengsi 提交者: whs

fix_nan (#2753)

上级 55ba9c60
...@@ -165,9 +165,10 @@ class DTrainer(): ...@@ -165,9 +165,10 @@ class DTrainer():
grad_shape = grad.shape grad_shape = grad.shape
grad = fluid.layers.reshape( grad = fluid.layers.reshape(
grad, [-1, grad_shape[1] * grad_shape[2] * grad_shape[3]]) grad, [-1, grad_shape[1] * grad_shape[2] * grad_shape[3]])
epsilon = 1e-16
norm = fluid.layers.sqrt( norm = fluid.layers.sqrt(
fluid.layers.reduce_sum( fluid.layers.reduce_sum(
fluid.layers.square(grad), dim=1)) fluid.layers.square(grad), dim=1) + epsilon)
gp = fluid.layers.reduce_mean(fluid.layers.square(norm - 1.0)) gp = fluid.layers.reduce_mean(fluid.layers.square(norm - 1.0))
return gp return gp
......
...@@ -163,9 +163,10 @@ class DTrainer(): ...@@ -163,9 +163,10 @@ class DTrainer():
grad_shape = grad.shape grad_shape = grad.shape
grad = fluid.layers.reshape( grad = fluid.layers.reshape(
grad, [-1, grad_shape[1] * grad_shape[2] * grad_shape[3]]) grad, [-1, grad_shape[1] * grad_shape[2] * grad_shape[3]])
epsilon = 1e-16
norm = fluid.layers.sqrt( norm = fluid.layers.sqrt(
fluid.layers.reduce_sum( fluid.layers.reduce_sum(
fluid.layers.square(grad), dim=1)) fluid.layers.square(grad), dim=1) + epsilon)
gp = fluid.layers.reduce_mean(fluid.layers.square(norm - 1.0)) gp = fluid.layers.reduce_mean(fluid.layers.square(norm - 1.0))
return gp return gp
......
...@@ -189,9 +189,10 @@ class DTrainer(): ...@@ -189,9 +189,10 @@ class DTrainer():
grad_shape = grad.shape grad_shape = grad.shape
grad = fluid.layers.reshape( grad = fluid.layers.reshape(
grad, [-1, grad_shape[1] * grad_shape[2] * grad_shape[3]]) grad, [-1, grad_shape[1] * grad_shape[2] * grad_shape[3]])
epsilon = 1e-16
norm = fluid.layers.sqrt( norm = fluid.layers.sqrt(
fluid.layers.reduce_sum( fluid.layers.reduce_sum(
fluid.layers.square(grad), dim=1)) fluid.layers.square(grad), dim=1) + epsilon)
gp = fluid.layers.reduce_mean(fluid.layers.square(norm - 1.0)) gp = fluid.layers.reduce_mean(fluid.layers.square(norm - 1.0))
return gp return gp
......
...@@ -113,7 +113,7 @@ def save_test_image(epoch, ...@@ -113,7 +113,7 @@ def save_test_image(epoch,
images = [real_img_temp] images = [real_img_temp]
for i in range(cfg.c_dim): for i in range(cfg.c_dim):
label_trg_tmp = copy.deepcopy(label_org) label_trg_tmp = copy.deepcopy(label_org)
label_trg_tmp[0][i] = 1.0 - label_trg_tmp[j][i] label_trg_tmp[0][i] = 1.0 - label_trg_tmp[0][i]
label_trg = check_attribute_conflict( label_trg = check_attribute_conflict(
label_trg_tmp, attr_names[i], attr_names) label_trg_tmp, attr_names[i], attr_names)
tensor_label_trg = fluid.LoDTensor() tensor_label_trg = fluid.LoDTensor()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册