From 799ada9d325c9fd6af7fe92bbc1ddc322b0a70c0 Mon Sep 17 00:00:00 2001 From: John Lambert Date: Wed, 15 Nov 2023 21:36:33 -0500 Subject: [PATCH] Clean up cacher test docs (#728) * Add cacher to two view estimator * use two view cacher in configs * fix punctuation * add unit test * add more documentation * fix formatting * improve test * fix test * add repr method * fix test * turn on 2-view cacher * fix formatting * add helpful comment * fix docs --------- --- gtsfm/frontend/cacher/global_descriptor_cacher.py | 3 ++- tests/frontend/cacher/test_image_matcher_cacher.py | 7 ++++--- tests/frontend/cacher/test_matcher_cacher.py | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gtsfm/frontend/cacher/global_descriptor_cacher.py b/gtsfm/frontend/cacher/global_descriptor_cacher.py index 854479b6d..200dd6ceb 100644 --- a/gtsfm/frontend/cacher/global_descriptor_cacher.py +++ b/gtsfm/frontend/cacher/global_descriptor_cacher.py @@ -44,6 +44,7 @@ def __get_cache_path(self, cache_key: str) -> Path: def __generate_cache_key(self, image: Image) -> str: """Generates the cache key from the input image and underlying global descriptor.""" input_key = cache_utils.generate_hash_for_image(image) + # Concatenate class name and image array hash. return "{}_{}".format(self._global_descriptor_obj_cache_key, input_key) def __load_result_from_cache(self, image: Image) -> Optional[np.ndarray]: @@ -70,7 +71,7 @@ def describe(self, image: Image) -> np.ndarray: details about the output format. Args: - image: the input image. + image: The input image. Returns: Global image descriptor, of shape (D,). diff --git a/tests/frontend/cacher/test_image_matcher_cacher.py b/tests/frontend/cacher/test_image_matcher_cacher.py index 63ddbb0b1..8fa80c2ca 100644 --- a/tests/frontend/cacher/test_image_matcher_cacher.py +++ b/tests/frontend/cacher/test_image_matcher_cacher.py @@ -93,15 +93,16 @@ def test_cache_hit( self.assertEqual(computed_keypoints_i1, DUMMY_KEYPOINTS_I1) self.assertEqual(computed_keypoints_i2, DUMMY_KEYPOINTS_I2) - # assert that underlying object was not called + # Assert that underlying object was not called. underlying_matcher_mock.match.assert_not_called() - # assert that hash generation was called twice + # Assert that hash generation was called twice. generate_hash_for_image_mock.assert_called() - # assert that read function was called once and write function was called once + # Assert that read function was called once. cache_path = ROOT_PATH / "cache" / "image_matcher" / "mock_matcher_numpy_key_numpy_key.pbz2" read_mock.assert_called_once_with(cache_path) + # Assert that the write function was not called (as cache is mocked to already exist). write_mock.assert_not_called() diff --git a/tests/frontend/cacher/test_matcher_cacher.py b/tests/frontend/cacher/test_matcher_cacher.py index ab7c8e49f..9d7c96b58 100644 --- a/tests/frontend/cacher/test_matcher_cacher.py +++ b/tests/frontend/cacher/test_matcher_cacher.py @@ -102,13 +102,15 @@ def test_cache_hit( # assert that underlying object was not called underlying_matcher_mock.match.assert_not_called() - # assert that hash generation was called twice + # Assert that hash generation was called twice. # TODO(ayushbaid): this need proper values generate_hash_for_numpy_array_mock.assert_called() - # assert that read function was called once and write function was called once + # Assert that read function was called once cache_path = ROOT_PATH / "cache" / "matcher" / "mock_matcher_numpy_key.pbz2" read_mock.assert_called_once_with(cache_path) + + # Assert that the write function was not called (as cache is mocked to already exist). write_mock.assert_not_called()