提交 1c52e005 编写于 作者: u010070587's avatar u010070587 提交者: ruri

add PaddleGAN ce (#4079)

上级 d127132c
......@@ -207,7 +207,10 @@ class CycleGAN(object):
type=int,
default=3,
help="only used when CycleGAN discriminator is nlayers")
parser.add_argument(
'--enable_ce',
action='store_true',
help="if set, run the tasks with continuous evaluation logs")
return parser
def __init__(self,
......@@ -237,6 +240,9 @@ class CycleGAN(object):
name='fake_pool_A', shape=data_shape, dtype='float32')
fake_pool_B = fluid.data(
name='fake_pool_B', shape=data_shape, dtype='float32')
# used for continuous evaluation
if self.cfg.enable_ce:
fluid.default_startup_program().random_seed = 90
A_py_reader = fluid.io.PyReader(
feed_list=[input_A],
......@@ -344,6 +350,9 @@ class CycleGAN(object):
sys.stdout.flush()
batch_id += 1
# used for continuous evaluation
if self.cfg.enable_ce and batch_id == 10:
break
if self.cfg.run_test:
A_image_name = fluid.data(
......@@ -390,3 +399,26 @@ class CycleGAN(object):
"net_DA")
utility.checkpoints(epoch_id, self.cfg, exe, d_B_trainer,
"net_DB")
# used for continuous evaluation
if self.cfg.enable_ce:
device_num = fluid.core.get_cuda_device_count(
) if self.cfg.use_gpu else 1
print("kpis\tcyclegan_g_A_loss_card{}\t{}".format(device_num,
g_A_loss[0]))
print("kpis\tcyclegan_g_A_cyc_loss_card{}\t{}".format(
device_num, g_A_cyc_loss[0]))
print("kpis\tcyclegan_g_A_idt_loss_card{}\t{}".format(
device_num, g_A_idt_loss[0]))
print("kpis\tcyclegan_d_A_loss_card{}\t{}".format(device_num,
d_A_loss[0]))
print("kpis\tcyclegan_g_B_loss_card{}\t{}".format(device_num,
g_B_loss[0]))
print("kpis\tcyclegan_g_B_cyc_loss_card{}\t{}".format(
device_num, g_B_cyc_loss[0]))
print("kpis\tcyclegan_g_B_idt_loss_card{}\t{}".format(
device_num, g_B_idt_loss[0]))
print("kpis\tcyclegan_d_B_loss_card{}\t{}".format(device_num,
d_B_loss[0]))
print("kpis\tcyclegan_Batch_time_cost_card{}\t{}".format(
device_num, batch_time))
......@@ -27,6 +27,7 @@ import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
import paddle.fluid as fluid
import random
class GTrainer():
......@@ -78,7 +79,10 @@ class DCGAN(object):
def add_special_args(self, parser):
parser.add_argument(
'--noise_size', type=int, default=100, help="the noise dimension")
parser.add_argument(
'--enable_ce',
action='store_true',
help="if set, run the tasks with continuous evaluation logs")
return parser
def __init__(self, cfg=None, train_reader=None):
......@@ -90,6 +94,11 @@ class DCGAN(object):
noise = fluid.data(
name='noise', shape=[None, self.cfg.noise_size], dtype='float32')
label = fluid.data(name='label', shape=[None, 1], dtype='float32')
# used for continuous evaluation
if self.cfg.enable_ce:
fluid.default_startup_program().random_seed = 90
random.seed(0)
np.random.seed(0)
g_trainer = GTrainer(noise, label, self.cfg)
d_trainer = DTrainer(img, label, self.cfg)
......@@ -200,3 +209,11 @@ class DCGAN(object):
if self.cfg.save_checkpoints:
utility.checkpoints(epoch_id, self.cfg, exe, g_trainer, "net_G")
utility.checkpoints(epoch_id, self.cfg, exe, d_trainer, "net_D")
# used for continuous evaluation
if self.cfg.enable_ce:
device_num = fluid.core.get_cuda_device_count(
) if self.cfg.use_gpu else 1
print("kpis\tdcgan_d_loss_card{}\t{}".format(device_num, d_loss[0]))
print("kpis\tdcgan_g_loss_card{}\t{}".format(device_num, g_loss[0]))
print("kpis\tdcgan_Batch_time_cost_card{}\t{}".format(device_num,
batch_time))
......@@ -196,7 +196,10 @@ class Pix2pix(object):
type=int,
default=3,
help="only used when Pix2pix discriminator is nlayers")
parser.add_argument(
'--enable_ce',
action='store_true',
help="if set, run the tasks with continuous evaluation logs")
return parser
def __init__(self,
......@@ -218,6 +221,9 @@ class Pix2pix(object):
input_B = fluid.data(name='input_B', shape=data_shape, dtype='float32')
input_fake = fluid.data(
name='input_fake', shape=data_shape, dtype='float32')
# used for continuous evaluation
if self.cfg.enable_ce:
fluid.default_startup_program().random_seed = 90
loader = fluid.io.DataLoader.from_generator(
feed_list=[input_A, input_B],
......@@ -261,7 +267,7 @@ class Pix2pix(object):
for epoch_id in range(self.cfg.epoch):
batch_id = 0
for tensor in loader():
if self.cfg.max_iter and total_train_batch == self.cfg.max_iter: # used for benchmark
if self.cfg.max_iter and total_train_batch == self.cfg.max_iter: # used for benchmark
return
s_time = time.time()
......@@ -336,3 +342,16 @@ class Pix2pix(object):
"net_G")
utility.checkpoints(epoch_id, self.cfg, exe, dis_trainer,
"net_D")
if self.cfg.enable_ce:
device_num = fluid.core.get_cuda_device_count(
) if self.cfg.use_gpu else 1
print("kpis\tpix2pix_g_loss_gan_card{}\t{}".format(device_num,
g_loss_gan[0]))
print("kpis\tpix2pix_g_loss_l1_card{}\t{}".format(device_num,
g_loss_l1[0]))
print("kpis\tpix2pix_d_loss_real_card{}\t{}".format(device_num,
d_loss_real[0]))
print("kpis\tpix2pix_d_loss_fake_card{}\t{}".format(device_num,
d_loss_fake[0]))
print("kpis\tpix2pix_Batch_time_cost_card{}\t{}".format(device_num,
batch_time))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册