def test_disabled_coordinate_encoding_returns_features_unchanged(self): model = self.create_model() model.set_mparam('encode_coordinates_fn', enabled=False) conv_w_coords_tf = model.encode_coordinates_fn(self.fake_conv_tower) with self.test_session() as sess: conv_w_coords = sess.run(conv_w_coords_tf) self.assertAllEqual(conv_w_coords, self.fake_conv_tower_np)
def test_sequence_loss_function_without_label_smoothing(self): model = self.create_model() model.set_mparam('sequence_loss_fn', label_smoothing=0) loss = model.sequence_loss_fn(self.fake_logits, self.fake_labels) with self.test_session() as sess: loss_np = sess.run(loss) # This test checks that the loss function is 'runnable'. self.assertEqual(loss_np.shape, tuple())
def test_alt_implementation_of_coordinate_encoding_returns_same_values(self): model = self.create_model() model.set_mparam('encode_coordinates_fn', enabled=True) conv_w_coords_tf = model.encode_coordinates_fn(self.fake_conv_tower) conv_w_coords_alt_tf = self.encode_coordinates_alt(self.fake_conv_tower) with self.test_session() as sess: conv_w_coords_tf, conv_w_coords_alt_tf = sess.run( [conv_w_coords_tf, conv_w_coords_alt_tf]) self.assertAllEqual(conv_w_coords_tf, conv_w_coords_alt_tf)
def test_encoded_coordinates_have_correct_shape(self): model = self.create_model() model.set_mparam('encode_coordinates_fn', enabled=True) conv_w_coords_tf = model.encode_coordinates_fn(self.fake_conv_tower) with self.test_session() as sess: conv_w_coords = sess.run(conv_w_coords_tf) batch_size, height, width, feature_size = self.conv_tower_shape self.assertEqual(conv_w_coords.shape, (batch_size, height, width, feature_size + height + width))
def test_coordinate_encoding_is_correct_for_simple_example(self): shape = (1, 2, 3, 4) # batch_size, height, width, feature_size fake_conv_tower = tf.constant(2 * np.ones(shape), dtype=tf.float32) model = self.create_model() model.set_mparam('encode_coordinates_fn', enabled=True) conv_w_coords_tf = model.encode_coordinates_fn(fake_conv_tower) with self.test_session() as sess: conv_w_coords = sess.run(conv_w_coords_tf) # Original features self.assertAllEqual(conv_w_coords[0, :, :, :4], [[[2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2]], [[2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2]]]) # Encoded coordinates self.assertAllEqual(conv_w_coords[0, :, :, 4:], [[[1, 0, 1, 0, 0], [1, 0, 0, 1, 0], [1, 0, 0, 0, 1]], [[0, 1, 1, 0, 0], [0, 1, 0, 1, 0], [0, 1, 0, 0, 1]]])