def test_get_local_env_and_origin_3d(self):
        res = [0.01, 0.01]
        full_h_rows = 5
        full_w_cols = 5
        full_c_channels = 5
        local_h_rows = 3
        local_w_cols = 3
        local_c_channels = 3

        center_point = np.array([[0, 0, 0], [-0.01, 0.01, 0.01]], np.float32)

        full_env = np.zeros([2, full_h_rows, full_w_cols, full_c_channels],
                            dtype=np.float32)
        full_env_origin = np.array(
            [[full_h_rows / 2, full_w_cols / 2, full_c_channels / 2],
             [full_h_rows / 2, full_w_cols / 2, full_c_channels / 2]],
            dtype=np.float32)
        full_env[:, 1, 2, 1] = 1
        full_env[:, 2, 3, 3] = 1

        local_env, local_env_origin = get_local_env_and_origin_3d_tf(
            center_point, full_env, full_env_origin, res, local_h_rows,
            local_w_cols, local_c_channels)
        expected_origins = tf.constant([[1.5, 1.5, 1.5], [0.5, 2.5, 0.5]],
                                       dtype=tf.float32)
        expected_env_occupied_indicies = tf.constant([
            [0, 0, 1, 0],
            [0, 1, 2, 2],
        ],
                                                     dtype=tf.float32)
        assert_close_tf(local_env_origin, expected_origins)
        assert_close_tf(tf.cast(tf.where(local_env > 0.5), tf.float32),
                        expected_env_occupied_indicies)
    def test_get_local_env_and_origin_2d(self):
        res = [0.01, 0.01]
        full_h_rows = 5
        full_w_cols = 5
        local_h_rows = 3
        local_w_cols = 3

        center_point = np.array([[0, 0], [-0.01, 0.01]], np.float32)

        full_env = np.zeros([2, full_h_rows, full_w_cols], dtype=np.float32)
        full_env_origin = np.array([[full_h_rows / 2, full_w_cols / 2],
                                    [full_h_rows / 2, full_w_cols / 2]],
                                   dtype=np.float32)
        full_env[:, 1, 2] = 1
        full_env[:, 2, 3] = 1

        local_env, local_env_origin = get_local_env_and_origin_2d_tf(
            center_point, full_env, full_env_origin, res, local_h_rows,
            local_w_cols)
        expected_origins = tf.constant([[1.5, 1.5], [0.5, 2.5]],
                                       dtype=tf.float32)
        expected_env = tf.constant([[[0, 1, 0], [0, 0, 1], [0, 0, 0]],
                                    [[0, 0, 0], [0, 0, 0], [0, 0, 0]]],
                                   dtype=tf.float32)
        assert_close_tf(local_env_origin, expected_origins)
        assert_close_tf(local_env, expected_env)
Exemplo n.º 3
0
 def test_batch_outer_product(self):
     a = tf.constant([[1, 2], [0, 2]], dtype=tf.float32)
     b = tf.constant([[3, 4, 5], [1, 4, 2]], dtype=tf.float32)
     out = batch_outer_product(a, b)
     expected = tf.constant(
         [[[3, 4, 5], [6, 8, 10]], [[0, 0, 0], [2, 8, 4]]],
         dtype=tf.float32)
     assert_close_tf(out, expected)
Exemplo n.º 4
0
 def test_inflate_tf1(self):
     env = np.array(
         [[0, 0, 0, 0], [0, 0, 0, 0], [0, 1, 0, 0], [0, 1, 1, 0]],
         dtype=np.float32)
     expected_inflated_env = np.array(
         [[0, 0, 0, 0], [1, 1, 1, 0], [1, 1, 1, 1], [1, 1, 1, 1]],
         dtype=np.float32)
     inflated_env = inflate_tf(env, radius_m=0.01, res=0.01)
     assert_close_tf(inflated_env, expected_inflated_env)
 def test_to_rope_local_frame(self):
     rope_states = tf.constant([[0, 0, 1, 0, 1, 1],
                                [2, 2, 2, 1, 3, 1],
                                [-2, -2, -2, -1, -3, -1],
                                [1, 0, 1, 1, 2, 1]],
                               dtype=tf.float32)
     expected_states = tf.constant([[-1, 1, -1, 0, 0, 0],
                                    [-1, 1, -1, 0, 0, 0],
                                    [-1, 1, -1, 0, 0, 0],
                                    [-1, -1, -1, 0, 0, 0]],
                                   dtype=tf.float32)
     out_states = LinkBotScenario.to_rope_local_frame_tf(rope_states)
     assert_close_tf(out_states, expected_states, atol=1e-5)
 def test_negative_weighted_binary_classification_sequence_loss_function_incorrect(
         self):
     data = {
         'is_close':
         tf.constant([[1, 1, 1], [1, 1, 1], [1, 1, 0], [1, 0, 1]],
                     tf.float32)
     }
     pred = {
         'logits':
         tf.constant([[[100], [-100]], [[100], [-100]], [[100], [-100]],
                      [[-100], [-100]]], tf.float32),
         'mask':
         tf.constant([[True, True, False], [True, True, True],
                      [True, True, True], [True, True, True]], tf.bool),
     }
     expected_loss = tf.constant([9.52381])
     out_loss = negative_weighted_binary_classification_sequence_loss_function(
         data, pred)
     assert_close_tf(expected_loss, out_loss)
 def test_to_rope_local_frame_with_reference(self):
     rope_states = tf.constant([[0, 0, 1, 0, 1, 1]], dtype=tf.float32)
     reference_rope_states = tf.constant([[0, 0, 1, 0, 2, 0]], dtype=tf.float32)
     expected_states = tf.constant([[-2, 0, -1, 0, -1, 1]], dtype=tf.float32)
     out_states = LinkBotScenario.to_rope_local_frame_tf(rope_states, reference_rope_states)
     assert_close_tf(out_states, expected_states, atol=1e-5)