diff --git a/PaddleCV/PaddleGAN/network/CGAN_network.py b/PaddleCV/PaddleGAN/network/CGAN_network.py index 4978f6dd8e57c3a0f2a6c0fad06fcb2770a88efe..8b65b7bd32b21ed78c222658d151117b692ebc10 100644 --- a/PaddleCV/PaddleGAN/network/CGAN_network.py +++ b/PaddleCV/PaddleGAN/network/CGAN_network.py @@ -35,6 +35,10 @@ class CGAN_model(object): self.gf_dim = 128 self.df_dim = 64 self.leaky_relu_factor = 0.2 + if self.batch_size == 1: + self.norm = None + else: + self.norm = "batch_norm" def network_G(self, input, label, name="generator"): # concat noise and label @@ -43,14 +47,14 @@ class CGAN_model(object): o_l1 = linear( xy, self.gf_dim * 8, - norm='batch_norm', + norm=self.norm, activation_fn='relu', name=name + '_l1') o_c1 = fluid.layers.concat([o_l1, y], 1) o_l2 = linear( o_c1, self.gf_dim * (self.img_w // 4) * (self.img_h // 4), - norm='batch_norm', + norm=self.norm, activation_fn='relu', name=name + '_l2') o_r1 = fluid.layers.reshape( @@ -107,7 +111,7 @@ class CGAN_model(object): o_l3 = linear( o_c2, self.df_dim * 16, - norm='batch_norm', + norm=self.norm, activation_fn='leaky_relu', name=name + '_l3') o_c3 = fluid.layers.concat([o_l3, y], 1) diff --git a/PaddleCV/PaddleGAN/network/DCGAN_network.py b/PaddleCV/PaddleGAN/network/DCGAN_network.py index 6c01fa449e91d338c0b24de1301c93462e9a26d4..1b455c97a40781e4d0b82f192b34a8b7e6612a21 100644 --- a/PaddleCV/PaddleGAN/network/DCGAN_network.py +++ b/PaddleCV/PaddleGAN/network/DCGAN_network.py @@ -31,13 +31,17 @@ class DCGAN_model(object): self.dfc_dim = 1024 self.gf_dim = 64 self.df_dim = 64 + if self.batch_size == 1: + self.norm = None + else: + self.norm = "batch_norm" def network_G(self, input, name="generator"): - o_l1 = linear(input, self.gfc_dim, norm='batch_norm', name=name + '_l1') + o_l1 = linear(input, self.gfc_dim, norm=self.norm, name=name + '_l1') o_l2 = linear( o_l1, self.gf_dim * 2 * self.img_dim // 4 * self.img_dim // 4, - norm='batch_norm', + norm=self.norm, name=name + '_l2') o_r1 = fluid.layers.reshape( o_l2, [-1, self.df_dim * 2, self.img_dim // 4, self.img_dim // 4]) @@ -85,7 +89,7 @@ class DCGAN_model(object): o_l1 = linear( o_c2, self.dfc_dim, - norm='batch_norm', + norm=self.norm, activation_fn='leaky_relu', name=name + '_l1') out = linear(o_l1, 1, activation_fn='sigmoid', name=name + '_l2')