From 5c751d8f3af4a14696f38174c6a430e14bd61e10 Mon Sep 17 00:00:00 2001 From: lvmengsi Date: Mon, 8 Jul 2019 19:46:45 +0800 Subject: [PATCH] fix_nan (#2753) --- PaddleCV/PaddleGAN/trainer/AttGAN.py | 3 ++- PaddleCV/PaddleGAN/trainer/STGAN.py | 3 ++- PaddleCV/PaddleGAN/trainer/StarGAN.py | 3 ++- PaddleCV/PaddleGAN/util/utility.py | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/PaddleCV/PaddleGAN/trainer/AttGAN.py b/PaddleCV/PaddleGAN/trainer/AttGAN.py index 41a0fcd2..d7d84efd 100644 --- a/PaddleCV/PaddleGAN/trainer/AttGAN.py +++ b/PaddleCV/PaddleGAN/trainer/AttGAN.py @@ -165,9 +165,10 @@ class DTrainer(): grad_shape = grad.shape grad = fluid.layers.reshape( grad, [-1, grad_shape[1] * grad_shape[2] * grad_shape[3]]) + epsilon = 1e-16 norm = fluid.layers.sqrt( 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)) return gp diff --git a/PaddleCV/PaddleGAN/trainer/STGAN.py b/PaddleCV/PaddleGAN/trainer/STGAN.py index aeab44e1..7b3c88a8 100644 --- a/PaddleCV/PaddleGAN/trainer/STGAN.py +++ b/PaddleCV/PaddleGAN/trainer/STGAN.py @@ -163,9 +163,10 @@ class DTrainer(): grad_shape = grad.shape grad = fluid.layers.reshape( grad, [-1, grad_shape[1] * grad_shape[2] * grad_shape[3]]) + epsilon = 1e-16 norm = fluid.layers.sqrt( 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)) return gp diff --git a/PaddleCV/PaddleGAN/trainer/StarGAN.py b/PaddleCV/PaddleGAN/trainer/StarGAN.py index 6aef1fb4..c71b1bf7 100644 --- a/PaddleCV/PaddleGAN/trainer/StarGAN.py +++ b/PaddleCV/PaddleGAN/trainer/StarGAN.py @@ -189,9 +189,10 @@ class DTrainer(): grad_shape = grad.shape grad = fluid.layers.reshape( grad, [-1, grad_shape[1] * grad_shape[2] * grad_shape[3]]) + epsilon = 1e-16 norm = fluid.layers.sqrt( 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)) return gp diff --git a/PaddleCV/PaddleGAN/util/utility.py b/PaddleCV/PaddleGAN/util/utility.py index 3c624d09..0f4f216e 100644 --- a/PaddleCV/PaddleGAN/util/utility.py +++ b/PaddleCV/PaddleGAN/util/utility.py @@ -113,7 +113,7 @@ def save_test_image(epoch, images = [real_img_temp] for i in range(cfg.c_dim): 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_tmp, attr_names[i], attr_names) tensor_label_trg = fluid.LoDTensor() -- GitLab