Skip to content
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
16 changes: 9 additions & 7 deletions src/aws/osml/models/aircraft/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023-2024 Amazon.com, Inc. or its affiliates.
# Copyright 2023-2025 Amazon.com, Inc. or its affiliates.

import json
import os
Expand Down Expand Up @@ -112,19 +112,21 @@ def instances_to_feature_collection(
masks = instances.pred_masks.cpu()

for i in range(0, len(bboxes)):
bbox = bboxes[i]
feature = {
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [0.0, 0.0]},
"geometry": None,
"id": str(uuid.uuid4()),
"properties": {
"bounds_imcoords": bboxes[i],
"detection_score": float(scores[i]),
"feature_types": {"aircraft": float(scores[i])},
"image_id": image_id,
"imageGeometry": {"type": "Point", "coordinates": [0.0, 0.0]},
"imageBBox": bbox,
"featureClasses": [{"iri": "aircraft", "score": float(scores[i])}],
"modelMetadata": {"modelName": "aircraft", "ontologyName": "aircraft", "ontologyVersion": "1.0.0"},
"image_id": str(uuid.uuid4()),
},
}
if masks is not None:
feature["properties"]["geom_imcoords"] = mask_to_polygon(masks[i])
feature["properties"]["imageGeometry"] = {"type": "Polygon", "coordinates": [mask_to_polygon(masks[i])]}
app.logger.debug(feature)
geojson_feature_collection_dict["features"].append(feature)
else:
Expand Down
12 changes: 7 additions & 5 deletions src/aws/osml/models/server_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,21 @@ def detect_to_feature(
:param fixed_object_bbox: Bounding box to transform into a geojson feature
:return: dict: Dictionary representation of a geojson feature
"""

feature = {
"type": "Feature",
"geometry": {"coordinates": [0.0, 0.0], "type": "Point"},
"geometry": None,
"id": token_hex(16),
"properties": {
"bounds_imcoords": fixed_object_bbox,
"detection_score": detection_score,
"feature_types": {detection_type: detection_score},
"imageGeometry": {"type": "Point", "coordinates": [0.0, 0.0]},
"imageBBox": fixed_object_bbox,
"featureClasses": [{"iri": detection_type, "score": detection_score}],
"modelMetadata": {"modelName": "centerpoint", "ontologyName": "centerpoint", "ontologyVersion": "1.0.0"},
"image_id": token_hex(16),
},
}

if fixed_object_mask is not None:
feature["properties"]["geom_imcoords"] = fixed_object_mask
feature["properties"]["imageGeometry"] = {"type": "Polygon", "coordinates": [fixed_object_mask]}

return feature
12 changes: 6 additions & 6 deletions test/aws/osml/models/flood/test_flood_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023-2024 Amazon.com, Inc. or its affiliates.
# Copyright 2023-2025 Amazon.com, Inc. or its affiliates.

import json
import os
Expand Down Expand Up @@ -64,7 +64,7 @@ def compare_two_geojson_results(actual_geojson_result, expected_json_result):

The method checks the `type` and `features` fields and compares the geometries
and properties of the features. Due to the unique `image_id` and randomized
`bounds_imcoords`, these properties are overwritten for accurate comparison.
`imageBBox`, these properties are overwritten for accurate comparison.
"""
assert actual_geojson_result.get("type") == expected_json_result.get("type")
assert len(actual_geojson_result.get("features")) == len(expected_json_result.get("features"))
Expand All @@ -74,12 +74,12 @@ def compare_two_geojson_results(actual_geojson_result, expected_json_result):
):
assert actual_result.get("geometry") == expected_result.get("geometry")

# Handle image_id and bounds_imcoords differences
# Handle image_id and imageBBox differences
actual_image_id = actual_result["properties"]["image_id"]
expected_result["properties"]["image_id"] = actual_image_id

actual_bounds_imcoords = actual_result["properties"]["bounds_imcoords"]
expected_result["properties"]["bounds_imcoords"] = actual_bounds_imcoords
actual_image_bbox = actual_result["properties"]["imageBBox"]
expected_result["properties"]["imageBBox"] = actual_image_bbox

def test_predict_flood_model(self):
"""
Expand All @@ -90,7 +90,7 @@ def test_predict_flood_model(self):

The `compare_two_geojson_results` method is used to assert that the predicted
result is correct after accounting for differences in `image_id` and
`bounds_imcoords`.
`imageBBox`.
"""
data_binary = open("assets/images/2_planes.tiff", "rb")
response = self.client.post("/invocations", data=data_binary)
Expand Down
100 changes: 53 additions & 47 deletions test/sample_data/sample_centerpoint_model_output.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,66 @@
"type": "FeatureCollection",
"features": [
{
"geometry": {
"coordinates": [
0,
0
],
"type": "Point"
},
"id": "193ca21caf8b7a0ae6c82e0feca23336",
"geometry": null,
"id": "89abda35b0281bce6e5a3944c9480700",
"properties": {
"bounds_imcoords": [
"featureClasses": [
{
"iri": "sample_object",
"score": 1.0
}
],
"imageBBox": [
204.8,
204.8,
307.2,
307.2
],
"detection_score": 1,
"feature_types": {
"sample_object": 1
},
"image_id": "673c80a467182c1c1252d83631c52780",
"geom_imcoords": [
[
281.6,
307.2
],
[
259.4297,
294.4
],
[
259.4297,
268.8
"imageGeometry": {
"coordinates": [
[
[
281.6,
307.2
],
[
259.4297,
294.4
],
[
259.4297,
268.8
],
[
281.6,
256.0
],
[
303.7703,
268.8
],
[
303.7703,
294.4
],
[
281.6,
307.2
],
[
281.6,
307.2
]
]
],
[
281.6,
256
],
[
303.7703,
268.8
],
[
303.7703,
294.4
],
[
281.6,
307.2
],
[
281.6,
307.2
]
]
"type": "Polygon"
},
"image_id": "83f6562dd30066413abcaced63a51892",
"modelMetadata": {
"modelName": "centerpoint",
"ontologyName": "centerpoint",
"ontologyVersion": "1.0.0"
}
},
"type": "Feature"
}
Expand Down
Loading
Loading