def test_define_model(self, mock_eval): FLAGS.batch_size = 2 images_shape = [FLAGS.batch_size, 4, 4, 3] images_x_np = np.zeros(shape=images_shape) images_y_np = np.zeros(shape=images_shape) images_x = tf.constant(images_x_np, dtype=tf.float32) images_y = tf.constant(images_y_np, dtype=tf.float32) cyclegan_model = train._define_model(images_x, images_y) self.assertIsInstance(cyclegan_model, tfgan.CycleGANModel) self.assertShapeEqual(images_x_np, cyclegan_model.reconstructed_x) self.assertShapeEqual(images_y_np, cyclegan_model.reconstructed_y)
def test_define_model(self): FLAGS.batch_size = 2 images_shape = [FLAGS.batch_size, 4, 4, 3] images_np = np.zeros(shape=images_shape) images = tf.constant(images_np, dtype=tf.float32) labels = tf.one_hot([0] * FLAGS.batch_size, 2) model = train._define_model(images, labels) self.assertIsInstance(model, tfgan.StarGANModel) self.assertShapeEqual(images_np, model.generated_data) self.assertShapeEqual(images_np, model.reconstructed_data) self.assertTrue(isinstance(model.discriminator_variables, list)) self.assertTrue(isinstance(model.generator_variables, list)) self.assertIsInstance(model.discriminator_scope, tf.VariableScope) self.assertTrue(model.generator_scope, tf.VariableScope) self.assertTrue(callable(model.discriminator_fn)) self.assertTrue(callable(model.generator_fn))
def test_define_train_ops(self, mock_summary_scalar): FLAGS.batch_size = 2 FLAGS.generator_lr = 0.1 FLAGS.discriminator_lr = 0.01 images_shape = [FLAGS.batch_size, 4, 4, 3] images_x = tf.zeros(images_shape, dtype=tf.float32) images_y = tf.zeros(images_shape, dtype=tf.float32) cyclegan_model = train._define_model(images_x, images_y) cyclegan_loss = tfgan.cyclegan_loss(cyclegan_model, cycle_consistency_loss_weight=10.0) train_ops = train._define_train_ops(cyclegan_model, cyclegan_loss) self.assertIsInstance(train_ops, tfgan.GANTrainOps) mock_summary_scalar.assert_has_calls([ mock.call('generator_lr', mock.ANY), mock.call('discriminator_lr', mock.ANY) ])
def test_define_train_ops(self, mock_summary_scalar): FLAGS.batch_size = 2 FLAGS.generator_lr = 0.1 FLAGS.discriminator_lr = 0.01 images_shape = [FLAGS.batch_size, 4, 4, 3] images = tf.zeros(images_shape, dtype=tf.float32) labels = tf.one_hot([0] * FLAGS.batch_size, 2) model = train._define_model(images, labels) loss = tfgan.stargan_loss(model) train_ops = train._define_train_ops(model, loss) self.assertIsInstance(train_ops, tfgan.GANTrainOps) mock_summary_scalar.assert_has_calls([ mock.call('generator_lr', mock.ANY), mock.call('discriminator_lr', mock.ANY) ])
def test_define_train_ops(self, mock_summary_scalar): FLAGS.batch_size = 2 FLAGS.generator_lr = 0.1 FLAGS.discriminator_lr = 0.01 images_shape = [FLAGS.batch_size, 4, 4, 3] images_x = tf.zeros(images_shape, dtype=tf.float32) images_y = tf.zeros(images_shape, dtype=tf.float32) cyclegan_model = train._define_model(images_x, images_y) cyclegan_loss = tfgan.cyclegan_loss( cyclegan_model, cycle_consistency_loss_weight=10.0) train_ops = train._define_train_ops(cyclegan_model, cyclegan_loss) self.assertIsInstance(train_ops, tfgan.GANTrainOps) mock_summary_scalar.assert_has_calls([ mock.call('generator_lr', mock.ANY), mock.call('discriminator_lr', mock.ANY) ])