From 2292f446f1a7bd1cd02fd74dfcdf93964084db73 Mon Sep 17 00:00:00 2001 From: David Sapiro <115489098+Encord-davids@users.noreply.github.com> Date: Thu, 7 Sep 2023 12:53:44 +0100 Subject: [PATCH] fix: don't override label class of objects (#629) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: don't override label class of objects * fix: don't show prediction outcomes if not predictions scope * fix: formatting --------- Co-authored-by: Frederik Hvilshøj --- .../src/components/explorer/Explorer.tsx | 28 +++++++++++-------- .../frontend/src/components/explorer/api.ts | 7 ++++- src/encord_active/server/routers/project.py | 11 +++++--- src/encord_active/server/utils.py | 7 +++-- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/encord_active/frontend/src/components/explorer/Explorer.tsx b/src/encord_active/frontend/src/components/explorer/Explorer.tsx index ec6215825..201b464b2 100644 --- a/src/encord_active/frontend/src/components/explorer/Explorer.tsx +++ b/src/encord_active/frontend/src/components/explorer/Explorer.tsx @@ -125,12 +125,12 @@ export const Explorer = ({ object_classes: labelClass, ...(scope === "prediction" && predictionType ? { - prediction_filters: { - type: predictionType, - outcome: predictionOutcome, - iou_threshold: iou, - }, - } + prediction_filters: { + type: predictionType, + outcome: predictionOutcome, + iou_threshold: iou, + }, + } : {}), } as Filters; }, [JSON.stringify(newFilters), predictionType, predictionOutcome, iou]); @@ -421,9 +421,9 @@ export const Explorer = ({ idValues={ (scope === "prediction" ? sortedItems?.map(({ id, ...item }) => ({ - ...item, - id: id.slice(0, id.lastIndexOf("_")), - })) + ...item, + id: id.slice(0, id.lastIndexOf("_")), + })) : sortedItems) || [] } filters={filters} @@ -449,8 +449,8 @@ export const Explorer = ({ scope === "prediction" ? scope : !selectedItems.size - ? "missing-target" - : undefined + ? "missing-target" + : undefined } > { - const { data, isLoading } = useApi().fetchItem(id, iou); + const { data, isLoading } = useApi().fetchItem( + id, + scope === "prediction", + iou, + ); const { mutate } = useApi().itemTagsMutation; if (isLoading || !data) return ; diff --git a/src/encord_active/frontend/src/components/explorer/api.ts b/src/encord_active/frontend/src/components/explorer/api.ts index 1c241ee42..e4b2f0fc2 100644 --- a/src/encord_active/frontend/src/components/explorer/api.ts +++ b/src/encord_active/frontend/src/components/explorer/api.ts @@ -266,8 +266,13 @@ export const getApi = (projectHash: string, authToken?: string | null) => { ).json(); return IdValueSchema.array().parse(result); }, - fetchProjectItem: async (id: string, iou?: number) => { + fetchProjectItem: async ( + id: string, + isPrediction = false, + iou?: number, + ) => { const queryParams = new URLSearchParams({ + is_prediction: isPrediction.toString(), ...(iou != null ? { iou: iou.toString() } : {}), }); diff --git a/src/encord_active/server/routers/project.py b/src/encord_active/server/routers/project.py index 2c00d7fef..e2b72d19a 100644 --- a/src/encord_active/server/routers/project.py +++ b/src/encord_active/server/routers/project.py @@ -285,12 +285,15 @@ def append_tags_to_row(project: ProjectFileStructureDep, row: dict): @router.get("/{project}/items/{id:path}") -def read_item(project: ProjectFileStructureDep, id: str, iou: Optional[float] = None): +def read_item(project: ProjectFileStructureDep, id: str, is_prediction: bool = False, iou: Optional[float] = None): lr_hash, du_hash, frame, *object_hash = id.split("_") - row = get_model_prediction_by_id(project, id, iou) - - if row: + if is_prediction: + row = get_model_prediction_by_id(project, id, iou) + if not row: + raise HTTPException( + status_code=404, detail=f'Prediction with id "{id}" was not found for project "{project}"' + ) return to_item(row, project, lr_hash, du_hash, frame, object_hash[0] if len(object_hash) else None) with DBConnection(project) as conn: diff --git a/src/encord_active/server/utils.py b/src/encord_active/server/utils.py index a042c12da..8feaa7804 100644 --- a/src/encord_active/server/utils.py +++ b/src/encord_active/server/utils.py @@ -169,9 +169,10 @@ def to_item( if classifications and metadata["labelClass"]: clf_instance = classifications[0] question = clf_instance["name"] - clf_hash = clf_instance["classificationHash"] - classification = label_row["classification_answers"][clf_hash]["classifications"][0] - metadata["labelClass"] = f"{question}: {classification['answers'][0]['name']}" + if question == metadata["labelClass"]: + clf_hash = clf_instance["classificationHash"] + classification = label_row["classification_answers"][clf_hash]["classifications"][0] + metadata["labelClass"] = f"{question}: {classification['answers'][0]['name']}" except: pass