Skip to content

Commit

Permalink
Clean up cacher test docs (#728)
Browse files Browse the repository at this point in the history
* 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

---------
  • Loading branch information
johnwlambert authored Nov 16, 2023
1 parent efe1778 commit 799ada9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion gtsfm/frontend/cacher/global_descriptor_cacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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,).
Expand Down
7 changes: 4 additions & 3 deletions tests/frontend/cacher/test_image_matcher_cacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
6 changes: 4 additions & 2 deletions tests/frontend/cacher/test_matcher_cacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down

0 comments on commit 799ada9

Please sign in to comment.