Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No public description #184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/skai/model/inference_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def predict_scores(self, batch: list[tf.train.Example]) -> np.ndarray:
raise NotImplementedError()


def _extract_image_or_blank(
def extract_image_or_blank(
example: tf.train.Example, feature: str, image_size: int
) -> np.ndarray:
"""Extracts an image from a TF Example.
Expand Down Expand Up @@ -188,12 +188,12 @@ def _extract_images_or_blanks(
Returns:
Numpy array representing the concatenated images.
"""
post_image = _extract_image_or_blank(
post_image = extract_image_or_blank(
example, post_image_feature, self._image_size
)
if self._post_image_only:
return post_image
pre_image = _extract_image_or_blank(
pre_image = extract_image_or_blank(
example, pre_image_feature, self._image_size
)
return np.concatenate([pre_image, post_image], axis=2)
Expand Down Expand Up @@ -355,7 +355,7 @@ def _key_example_by_encoded_coordinates(
)


def _example_to_row(
def example_to_row(
example: tf.train.Example,
threshold: float,
high_precision_threshold: float,
Expand All @@ -372,7 +372,12 @@ def _example_to_row(
Returns:
Inference row.
"""
example_id = utils.get_int64_feature(example, 'int64_id')[0]

try:
example_id = utils.get_int64_feature(example, 'int64_id')[0]
except IndexError:
example_id = utils.get_bytes_feature(example, 'example_id')[0].decode()

building_id = utils.get_bytes_feature(example, 'encoded_coordinates')[
0
].decode()
Expand Down Expand Up @@ -431,7 +436,7 @@ def examples_to_csv(
| 'reshuffle_for_output' >> beam.Reshuffle()
| 'examples_to_rows'
>> beam.Map(
_example_to_row,
example_to_row,
threshold=threshold,
high_precision_threshold=high_precision_threshold,
high_recall_threshold=high_recall_threshold,
Expand Down
4 changes: 2 additions & 2 deletions src/skai/model/inference_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ def test_tf2_model_prediction_no_small_images(self):

def test_example_to_row(self):
example = _create_test_example(224, False, True, 0.7)
row = inference_lib._example_to_row(example, 0.5, 0.75, 0.25)
row = inference_lib.example_to_row(example, 0.5, 0.75, 0.25)
self.assertTrue(row.damaged)
self.assertFalse(row.damaged_high_precision)
self.assertTrue(row.damaged_high_recall)

low_score_example = _create_test_example(224, False, True, 0.1)
row = inference_lib._example_to_row(low_score_example, 0.5, 0.75, 0.25)
row = inference_lib.example_to_row(low_score_example, 0.5, 0.75, 0.25)
self.assertFalse(row.damaged)
self.assertFalse(row.damaged_high_precision)
self.assertFalse(row.damaged_high_recall)
Expand Down