Esempio n. 1
0
  def testFirstSampleIsReturnedDuringInference(self):
    with self.session() as sess:
      tf.keras.backend.set_learning_phase(0)
      chosen_latent, chosen_keypoints = dynamics._choose_sample(
          self.sampled_latent, self.sampled_keypoints, self.sample_losses)
      chosen_latent, chosen_keypoints = sess.run(
          [chosen_latent, chosen_keypoints])

    # Check that the 0th sample is chosen for each example in the batch:
    np.testing.assert_array_equal(chosen_latent, 0.0 * chosen_latent)
    np.testing.assert_array_equal(chosen_keypoints, 0.0 * chosen_keypoints)
Esempio n. 2
0
  def testBestSampleIsReturnedDuringTraining(self):
    with self.session() as sess:
      tf.keras.backend.set_learning_phase(1)
      chosen_latent, chosen_keypoints = dynamics._choose_sample(
          self.sampled_latent, self.sampled_keypoints, self.sample_losses)
      chosen_latent, chosen_keypoints = sess.run(
          [chosen_latent, chosen_keypoints])

    # Check output shapes:
    self.assertEqual(chosen_latent.shape,
                     (self.batch_size, self.latent_code_size))
    self.assertEqual(chosen_keypoints.shape,
                     (self.batch_size, self.latent_code_size * 2))

    # Check that the correct sample is chosen for each example in the batch:
    self.assertEqual(list(chosen_latent[:, 0]), self.best_samples)
    self.assertEqual(list(chosen_keypoints[:, 0]), self.best_samples)