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

Enable multiclass prediction to be keeped by modify project_to_geojson #124

Merged
merged 8 commits into from
Oct 1, 2023
Merged
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
40 changes: 28 additions & 12 deletions detectree2/models/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def to_eval_geojson(directory=None): # noqa:N803
json.dump(geofile, dest)


def project_to_geojson(tiles_path, pred_fold=None, output_fold=None): # noqa:N803
def project_to_geojson(tiles_path, pred_fold=None, output_fold=None, Multi_class = False): # noqa:N803
"""Projects json predictions back in geographic space.

Takes a json and changes it to a geojson so it can overlay with orthomosaic. Another copy is produced to overlay
Expand Down Expand Up @@ -190,6 +190,9 @@ def project_to_geojson(tiles_path, pred_fold=None, output_fold=None): # noqa:N8

# json file is formated as a list of segmentation polygons so cycle through each one
for crown_data in datajson:
if Multi_class == True:
category = crown_data["category_id"]
# print(category)
crown = crown_data["segmentation"]
confidence_score = crown_data["score"]

Expand All @@ -205,17 +208,30 @@ def project_to_geojson(tiles_path, pred_fold=None, output_fold=None): # noqa:N8
rows=crown_coords_array[:, 1],
cols=crown_coords_array[:, 0])
moved_coords = list(zip(x_coords, y_coords))

geofile["features"].append({
"type": "Feature",
"properties": {
"Confidence_score": confidence_score
},
"geometry": {
"type": "Polygon",
"coordinates": [moved_coords],
},
})
if Multi_class == False:
geofile["features"].append({
"type": "Feature",
"properties": {
"Confidence_score": confidence_score
},
"geometry": {
"type": "Polygon",
"coordinates": [moved_coords],
},
})
if Multi_class == True:
geofile["features"].append({
"type": "Feature",
"properties": {
"Confidence_score": confidence_score,
"category": category,
},
"geometry": {
"type": "Polygon",
"coordinates": [moved_coords],
},
})
# print(geofile["features"])

output_geo_file = os.path.join(output_fold, filename.with_suffix(".geojson").name)

Expand Down
Loading