def generator(self, x): net = self.arch['generator'] ## DownSample downS = net['downSample'] c = downS['channel'] k = downS['kernel'] s = downS['stride'] for i in range(len(c)): x = conv2d(x, c[i], k[i], s[i], prelu, name='downSample-L{}'.format(i)) ## Residual resid = net['residual'] c = resid['channel'] k = resid['kernel'] s = resid['stride'] for i in range(len(c) // 2): y = x x = conv2d(x, c[2 * i], k[2 * i], s[2 * i], prelu, name='resid_conv1-L{}'.format(i)) x = conv2d(x, c[2 * i + 1], k[2 * i + 1], s[2 * i + 1], prelu, name='resid_conv2-L{}'.format(i)) x = y + x ## UpSample upS = net['UpSample'] c = upS['channel'] k = upS['kernel'] s = upS['stride'] r = upS['ratio'] for i in range(len(c)): x = conv2d(x, c[i], k[i], s[i], prelu, name='UpSample-L{}'.format(i)) if (i < len(r)): x = PS(x, r[i], color=True) return x
def discriminator(self, x): unit = self.arch['discriminator'] c = unit['channel'] k = unit['kernel'] s = unit['stride'] for i in range(len(c)): x = conv2d(x, c[i], k[i], s[i], prelu, name='discriminator-L{}'.format(i)) x = tf.layers.flatten(x) y = tf.layers.dense(x, 1) return y
def encoder(self, x): unit = self.arch['encoder'] c = unit['channel'] k = unit['kernel'] s = unit['stride'] for i in range(len(c)): x = conv2d(x, c[i], k[i], s[i], prelu, name='encoder-L{}'.format(i)) x = tf.layers.flatten(x) z_mu = tf.layers.dense(x, self.arch['z_dim']) z_var = tf.layers.dense(x, self.arch['z_dim']) return z_mu, z_var
def discriminator(self, x): x = tf.reshape(x, [-1, self.featureSize, 1, 1]) unit = self.arch['discriminator'] c = unit['channel'] k = unit['kernel'] s = unit['stride'] for i in range(len(c)): x = conv2d(x, c[i], k[i], s[i], prelu, name='discriminator-L{}'.format(i)) x = tf.layers.flatten(x) y = tf.layers.dense(x, 1, bias_initializer=tf.constant_initializer(0.1)) return y
randfile = random.choice(dat[randInd]) randind = random.randint(0, randfile.shape[0] - 4000) data.append(randfile[randind:randind + 4000]) ind = list(dat.keys()).index(randInd) lab = np.zeros((1, speakerN)) lab[0][ind] = 1 label.append(lab) data = np.array(data) label = np.array(label) data = data.reshape([batch_size, nodeNum, 1, 1]) return data, label x = tf.placeholder(tf.float32, shape=[None, nodeNum, 1, 1]) feature = conv2d(x, 512, [5, 1], [2, 1], prelu, 'ex_feature') en_h1 = conv2d(feature, 256, [5, 1], [2, 1], prelu, 'en_h1') en_h2 = conv2d(en_h1, 64, [5, 1], [2, 1], prelu, 'en_h2') de_h1 = deconv2d(en_h2, 256, [5, 1], [2, 1], prelu, 'de_h1') de_h2 = deconv2d(de_h1, 512, [5, 1], [2, 1], prelu, 'de_h2') rec_x = deconv2d(de_h2, 1, [5, 1], [2, 1], prelu, 'rec_x') mse = tf.reduce_mean(tf.pow(rec_x - x, 2)) optimizer = tf.train.AdamOptimizer(0.000001).minimize(mse) sess = tf.InteractiveSession() tf.global_variables_initializer().run()