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

Add longitude and latitude to labeling example metadata. #258

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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
35 changes: 25 additions & 10 deletions src/skai/labeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class LabelingExample:
combined_image_path: str
tfrecord_path: str
serialized_example: bytes
longitude: float
latitude: float


def _annotate_image(image: Image, caption: str) -> Image:
Expand Down Expand Up @@ -441,6 +443,8 @@ def create_labeling_images(
i.pre_image_path,
i.post_image_path,
i.tfrecord_path,
i.longitude,
i.latitude,
)
for i in labeling_examples
],
Expand All @@ -453,6 +457,8 @@ def create_labeling_images(
'pre_image_path',
'post_image_path',
'tfrecord_source_path',
'longitude',
'latitude',
),
)
with tf.io.gfile.GFile(image_metadata_csv, 'w') as f:
Expand Down Expand Up @@ -656,6 +662,9 @@ def _create_labeling_assets_from_example_file(
.decode()
)

if example_id not in allowed_example_ids:
continue

try:
int64_id = utils.get_int64_feature(example, 'int64_id')[0]
except IndexError as error:
Expand All @@ -668,8 +677,9 @@ def _create_labeling_assets_from_example_file(
else:
plus_code = 'unknown'

if example_id not in allowed_example_ids:
continue
longitude, latitude = example.features.feature[
'coordinates'
].float_list.value

before_image = utils.deserialize_image(
example.features.feature['pre_image_png_large'].bytes_list.value[0],
Expand Down Expand Up @@ -697,14 +707,19 @@ def _create_labeling_assets_from_example_file(
with tf.io.gfile.GFile(combined_image_path, 'wb') as f:
f.write(utils.serialize_image(combined_image, 'png'))

labeling_examples.append(LabelingExample(
int64_id=int64_id,
example_id=str(example_id),
pre_image_path=pre_image_path,
post_image_path=post_image_path,
combined_image_path=combined_image_path,
tfrecord_path=example_file,
serialized_example=example.SerializeToString()))
labeling_examples.append(
LabelingExample(
int64_id=int64_id,
example_id=str(example_id),
pre_image_path=pre_image_path,
post_image_path=post_image_path,
combined_image_path=combined_image_path,
tfrecord_path=example_file,
serialized_example=example.SerializeToString(),
longitude=longitude,
latitude=latitude,
)
)

return labeling_examples

Expand Down
15 changes: 15 additions & 0 deletions src/skai/labeling_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,21 @@ def test_create_labeling_images(self):
image_metadata['example_id'],
allowed_example_ids,
)
self.assertCountEqual(
image_metadata.columns,
[
'id',
'int64_id',
'example_id',
'image',
'image_source_path',
'pre_image_path',
'post_image_path',
'tfrecord_source_path',
'longitude',
'latitude',
],
)

import_file_df = pd.read_csv(
f'{output_dir}/import_file.csv', names=['path']
Expand Down
Loading