|
|
|
"""
|
|
|
|
from data.params import SYS_ARGS
|
|
|
|
self.BATCHSIZE_PER_GPU = PROPOSED_BATCH_PER_GPU
|
|
|
|
|
|
|
|
elif not os.path.exists(path):
|
|
|
|
name = args['name']
|
|
|
|
# super().load_meta(**args)
|
|
|
|
class Discriminator(GNet):
|
|
|
|
y_hat = self.network(inputs=x_hat, label=label)
|
|
|
|
|
|
|
|
grad = tf.gradients(y_hat, [x_hat])[0]
|
|
|
|
slopes = tf.sqrt(tf.reduce_sum(tf.square(grad), 1))
|
|
|
|
gradient_penalty = tf.reduce_mean((slopes - 1.) ** 2)
|
|
|
|
#all_regs = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)
|
|
|
|
all_regs = tf.compat.v1.get_collection(tf.compat.v1.GraphKeys.REGULARIZATION_LOSSES)
|
|
|
|
w_distance = -tf.reduce_mean(y_hat_real) + tf.reduce_mean(y_hat_fake)
|
|
|
|
loss = w_distance + 10 * gradient_penalty + sum(all_regs)
|
|
|
|
#tf.add_to_collection('dlosses', loss)
|
|
|
|
tf.compat.v1.add_to_collection('dlosses', loss)
|
|
|
|
|
|
|
|
return w_distance, loss
|
|
|
|
total_loss = tf.add_n(losses, name='total_loss')
|
|
|
|
per_gpu_w = []
|
|
|
|
def apply(self,**args):
|
|
|
|
# max_epochs = args['max_epochs'] if 'max_epochs' in args else 10
|
|
|
|
REAL = self._REAL
|
|
|
|
LABEL= self._LABEL
|
|
|
|
if (self.logger):
|
|
|
|
pass
|
|
|
|
|
|
|
|
with tf.device('/cpu:0'):
|
|
|
|
opt_d = tf.compat.v1.train.AdamOptimizer(1e-4)
|
|
|
|
opt_g = tf.compat.v1.train.AdamOptimizer(1e-4)
|
|
|
|
|
|
|
|
train_d, w_distance, iterator_d, features_placeholder_d, labels_placeholder_d = self.network(stage='D', opt=opt_d)
|
|
|
|
train_g, _, iterator_g, features_placeholder_g, labels_placeholder_g = self.network(stage='G', opt=opt_g)
|
|
|
|
# saver = tf.train.Saver()
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# model_dir = os.sep.join([self.train_dir,str(self.MAX_EPOCHS)])
|
|
|
|
# x = df.sum(axis=1).values
|
|
|
|
# # Log the findings here in terms of ratio, missing, candidate count
|
|
|
|
# # print ([np.max(ratio),len(missing),len(found),i])
|
|
|
|
# i = np.where(ii == 0)[0]
|