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

Improved Ground truth tags #8586

Merged
merged 8 commits into from
Oct 29, 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
7 changes: 7 additions & 0 deletions changelog.d/20241023_120236_klakhov_improve_gt_tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Fixed

- Tags in ground truth job were displayed as `tag (GT)`
(<https://github.com/cvat-ai/cvat/pull/8586>)

- Tags in ground truth job couldn't be deleted via `x` button
(<https://github.com/cvat-ai/cvat/pull/8586>)
Original file line number Diff line number Diff line change
@@ -1,64 +1,34 @@
// Copyright (C) 2022 Intel Corporation
// Copyright (C) 2024 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

import './styles.scss';

import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useCallback } from 'react';
import Tag from 'antd/lib/tag';
import { connect } from 'react-redux';
import { Action } from 'redux';
import { ThunkDispatch } from 'redux-thunk';
import { shallowEqual, useDispatch, useSelector } from 'react-redux';

import {
removeObject as removeObjectAction,
} from 'actions/annotation-actions';
import { CombinedState, ObjectType, Workspace } from 'reducers';
import {
QualityConflict, ObjectState, AnnotationConflict, getCore,
} from 'cvat-core-wrapper';
import { CombinedState, ObjectType } from 'reducers';
import { ObjectState, AnnotationConflict } from 'cvat-core-wrapper';
import { filterAnnotations } from 'utils/filter-annotations';

const core = getCore();

interface StateToProps {
highlightedConflict: QualityConflict | null;
states: ObjectState[];
workspace: Workspace;
}

interface DispatchToProps {
removeObject(objectState: any): void;
}

function mapStateToProps(state: CombinedState): StateToProps {
const {
annotation: {
annotations: { highlightedConflict, states },
workspace,
},
} = state;
function FrameTags(): JSX.Element {
const dispatch = useDispatch();

return { highlightedConflict, states, workspace };
}

function mapDispatchToProps(dispatch: ThunkDispatch<CombinedState, {}, Action>): DispatchToProps {
return {
removeObject(objectState: ObjectState): void {
dispatch(removeObjectAction(objectState, false));
},
};
}

function FrameTags(props: StateToProps & DispatchToProps): JSX.Element {
const {
highlightedConflict, states, workspace, removeObject,
} = props;
const { highlightedConflict, states, workspace } = useSelector((state: CombinedState) => ({
highlightedConflict: state.annotation.annotations.highlightedConflict,
states: state.annotation.annotations.states,
workspace: state.annotation.workspace,
}), shallowEqual);

const [frameTags, setFrameTags] = useState([] as ObjectState[]);
const [frameTags, setFrameTags] = useState<ObjectState[]>([]);

const onRemoveState = (objectState: ObjectState): void => {
removeObject(objectState);
dispatch(removeObjectAction(objectState, false));
};

useEffect(() => {
Expand All @@ -67,16 +37,20 @@ function FrameTags(props: StateToProps & DispatchToProps): JSX.Element {
);
}, [states]);

const tagClassName = useCallback((tag: ObjectState): string => {
const tagHighlighted = (highlightedConflict?.annotationConflicts || [])
.find((conflict: AnnotationConflict) => conflict.serverID === tag.serverID);
return tagHighlighted ? 'cvat-frame-tag-highlighted' : 'cvat-frame-tag';
}, [highlightedConflict]);

return (
<>
<div>
<div className='cvat-canvas-annotation-frame-tags'>
{frameTags
.filter((tag: any) => tag.source !== core.enums.Source.GT)
.map((tag: any) => (
.filter((tag: ObjectState) => !tag.isGroundTruth)
.map((tag: ObjectState) => (
<Tag
className={
(highlightedConflict?.annotationConflicts || []).filter((conflict: AnnotationConflict) => conflict.serverID === tag.serverID).length !== 0 ? 'cvat-frame-tag-highlighted' : 'cvat-frame-tag'
}
className={tagClassName(tag)}
color={tag.label.color}
onClose={() => {
onRemoveState(tag);
Expand All @@ -88,14 +62,12 @@ function FrameTags(props: StateToProps & DispatchToProps): JSX.Element {
</Tag>
))}
</div>
<div>
<div className='cvat-canvas-ground-truth-frame-tags'>
{frameTags
.filter((tag: any) => tag.source === core.enums.Source.GT)
.map((tag: any) => (
.filter((tag: ObjectState) => tag.isGroundTruth)
.map((tag: ObjectState) => (
<Tag
className={
(highlightedConflict?.annotationConflicts || []).filter((conflict: AnnotationConflict) => conflict.serverID === tag.serverID).length !== 0 ? 'cvat-frame-tag-highlighted' : 'cvat-frame-tag'
}
className={tagClassName(tag)}
color={tag.label.color}
onClose={() => {
onRemoveState(tag);
Expand All @@ -112,4 +84,4 @@ function FrameTags(props: StateToProps & DispatchToProps): JSX.Element {
);
}

export default connect(mapStateToProps, mapDispatchToProps)(FrameTags);
export default React.memo(FrameTags);
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,7 @@

transform: scale(1.1);
}

.cvat-canvas-annotation-frame-tags {
margin-bottom: $grid-unit-size;
}
Loading