Skip to content

Commit

Permalink
fix: don't override label class of objects (#629)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Encord-davids and frederik-encord authored Sep 7, 2023
1 parent 74b63cb commit 2292f44
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
28 changes: 16 additions & 12 deletions src/encord_active/frontend/src/components/explorer/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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}
Expand All @@ -449,8 +449,8 @@ export const Explorer = ({
scope === "prediction"
? scope
: !selectedItems.size
? "missing-target"
: undefined
? "missing-target"
: undefined
}
>
<BulkTaggingForm
Expand Down Expand Up @@ -843,7 +843,11 @@ const ItemPreview = ({
iou?: number;
allowTaggingAnnotations: boolean;
}) => {
const { data, isLoading } = useApi().fetchItem(id, iou);
const { data, isLoading } = useApi().fetchItem(
id,
scope === "prediction",
iou,
);
const { mutate } = useApi().itemTagsMutation;

if (isLoading || !data) return <Spinner />;
Expand Down
7 changes: 6 additions & 1 deletion src/encord_active/frontend/src/components/explorer/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() } : {}),
});

Expand Down
11 changes: 7 additions & 4 deletions src/encord_active/server/routers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions src/encord_active/server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2292f44

Please sign in to comment.