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

Label deleting #2881

Merged
merged 14 commits into from
Mar 18, 2021
Merged
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"python.pythonPath": ".env/bin/python",
"eslint.enable": true,
"eslint.probe": [
"javascript",
"typescript",
Expand All @@ -19,8 +18,10 @@
"!cwd": true
}
],
"npm.exclude": "**/.env/**",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.testing.unittestEnabled": true,
"python.linting.pycodestyleEnabled": false,
"licenser.license": "Custom",
"licenser.customHeader": "Copyright (C) @YEAR@ Intel Corporation\n\nSPDX-License-Identifier: MIT",
"files.trimTrailingWhitespace": true
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Pre-built [cvat_server](https://hub.docker.com/r/openvino/cvat_server) and
[cvat_ui](https://hub.docker.com/r/openvino/cvat_ui) images were published on DockerHub (<https://github.com/openvinotoolkit/cvat/pull/2766>)
- Project task subsets (<https://github.com/openvinotoolkit/cvat/pull/2774>)
- [WiderFace](http://shuoyang1213.me/WIDERFACE/) format support (<https://github.com/openvinotoolkit/cvat/pull/2864>)
- [VGGFace2](https://github.com/ox-vgg/vgg_face2) format support (<https://github.com/openvinotoolkit/cvat/pull/2865>)
- [WiderFace](http://shuoyang1213.me/WIDERFACE/) format support (<https://github.com/openvinotoolkit/cvat/pull/2864>)
- Label deletion from tasks and projects (<https://github.com/openvinotoolkit/cvat/pull/2881>)

### Changed

Expand Down
19 changes: 18 additions & 1 deletion cvat-core/src/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

data.labels = [];
data.tasks = [];
data.deleted_labels = [];

if (Array.isArray(initialData.labels)) {
for (const label of initialData.labels) {
Expand Down Expand Up @@ -186,6 +187,12 @@
);
}

for (const label of data.labels) {
if (!labels.filter((_label) => _label.id === label.id).length) {
data.deleted_labels.push(label);
}
}
bsekachev marked this conversation as resolved.
Show resolved Hide resolved

data.labels = [...labels];
},
},
Expand All @@ -211,6 +218,9 @@
subsets: {
get: () => [...data.task_subsets],
},
_deletedLabels: {
get: () => [...data.deleted_labels],
},
}),
);
}
Expand Down Expand Up @@ -257,7 +267,14 @@
name: this.name,
assignee_id: this.assignee ? this.assignee.id : null,
bug_tracker: this.bugTracker,
labels: [...this.labels.map((el) => el.toJSON())],
labels: [
...this.labels.map((el) => el.toJSON()),
...this._deletedLabels.map((label) => {
const labelJSON = label.toJSON();
labelJSON.deleted = true;
return labelJSON;
bsekachev marked this conversation as resolved.
Show resolved Hide resolved
}),
],
};

await serverProxy.projects.save(this.id, projectData);
Expand Down
31 changes: 24 additions & 7 deletions cvat-core/src/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@
if (data.owner) data.owner = new User(data.owner);

data.labels = [];
data.deleted_labels = [];
data.jobs = [];
data.files = Object.freeze({
server_files: [],
Expand Down Expand Up @@ -1318,6 +1319,12 @@
}
}

for (const label of data.labels) {
if (!labels.filter((_label) => _label.id === label.id).length) {
data.deleted_labels.push(label);
}
}

updatedFields.labels = true;
data.labels = [...labels];
},
Expand Down Expand Up @@ -1485,12 +1492,6 @@
dataChunkType: {
get: () => data.data_compressed_chunk_type,
},
__updatedFields: {
get: () => updatedFields,
set: (fields) => {
updatedFields = fields;
},
},
dimension: {
/**
* @name enabled
Expand All @@ -1501,6 +1502,15 @@
*/
get: () => data.dimension,
},
__updatedFields: {
get: () => updatedFields,
set: (fields) => {
updatedFields = fields;
},
},
_deletedLabels: {
get: () => [...data.deleted_labels],
},
}),
);

Expand Down Expand Up @@ -1920,7 +1930,14 @@
taskData.subset = this.subset;
break;
case 'labels':
taskData.labels = [...this.labels.map((el) => el.toJSON())];
taskData.labels = [
...this.labels.map((el) => el.toJSON()),
...this._deletedLabels.map((label) => {
const labelJSON = label.toJSON();
labelJSON.deleted = true;
return labelJSON;
}),
];
break;
default:
break;
Expand Down
14 changes: 11 additions & 3 deletions cvat-core/tests/mocks/server-proxy.mock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2020 Intel Corporation
// Copyright (C) 2020-2021 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -97,7 +97,11 @@ class ServerProxy {
Object.prototype.hasOwnProperty.call(projectData, prop)
&& Object.prototype.hasOwnProperty.call(object, prop)
) {
object[prop] = projectData[prop];
if (prop === 'labels') {
object[prop] = projectData[prop].filter((label) => !label.deleted);
} else {
object[prop] = projectData[prop];
}
}
}
}
Expand Down Expand Up @@ -156,7 +160,11 @@ class ServerProxy {
Object.prototype.hasOwnProperty.call(taskData, prop)
&& Object.prototype.hasOwnProperty.call(object, prop)
) {
object[prop] = taskData[prop];
if (prop === 'labels') {
object[prop] = taskData[prop].filter((label) => !label.deleted);
} else {
object[prop] = taskData[prop];
}
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions cvat-ui/src/actions/annotation-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import {
AnyAction, Dispatch, ActionCreator, Store,
} from 'redux';
import { MutableRefObject } from 'react';
import notification from 'antd/lib/notification';
import { ThunkAction } from 'utils/redux';

import {
Expand All @@ -26,7 +28,6 @@ import getCore from 'cvat-core-wrapper';
import logger, { LogType } from 'cvat-logger';
import { RectDrawingMethod } from 'cvat-canvas-wrapper';
import { getCVATStore } from 'cvat-store';
import { MutableRefObject } from 'react';

interface AnnotationsParameters {
filters: string[];
Expand Down Expand Up @@ -919,8 +920,14 @@ export function getJobAsync(tid: number, jid: number, initialFrame: number, init
throw new Error(`Task ${tid} doesn't contain the job ${jid}`);
}

if (!task.labels.length && task.projectId) {
throw new Error(`Project ${task.projectId} does not contain any label`);
if (!task.labels.length) {
notification.warning({
message: 'No labels',
description: `${task.projectId ? 'Project' : 'Task'} ${
task.projectId || task.id
} does not contain any label`,
placement: 'topRight',
bsekachev marked this conversation as resolved.
Show resolved Hide resolved
});
}

const frameNumber = Math.max(Math.min(job.stopFrame, initialFrame), job.startFrame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// SPDX-License-Identifier: MIT

import React from 'react';
import GlobalHotKeys, { KeyMap } from 'utils/mousetrap-react';
import Layout from 'antd/lib/layout';
import GlobalHotKeys, { KeyMap } from 'utils/mousetrap-react';

import { ActiveControl, Rotation } from 'reducers/interfaces';
import { Canvas } from 'cvat-canvas-wrapper';
Expand Down Expand Up @@ -32,6 +32,7 @@ interface Props {
activeControl: ActiveControl;
keyMap: KeyMap;
normalizedKeyMap: Record<string, string>;
labels: any[];

mergeObjects(enabled: boolean): void;
groupObjects(enabled: boolean): void;
Expand Down Expand Up @@ -64,10 +65,11 @@ const ObservedSplitControl = ControlVisibilityObserver<SplitControlProps>(SplitC

export default function ControlsSideBarComponent(props: Props): JSX.Element {
const {
canvasInstance,
activeControl,
canvasInstance,
normalizedKeyMap,
keyMap,
labels,
mergeObjects,
groupObjects,
splitTrack,
Expand Down Expand Up @@ -114,6 +116,8 @@ export default function ControlsSideBarComponent(props: Props): JSX.Element {
ActiveControl.OPENCV_TOOLS,
].includes(activeControl);

if (!labels.length) return;
bsekachev marked this conversation as resolved.
Show resolved Hide resolved

if (!drawing) {
canvasInstance.cancel();
// repeateDrawShapes gets all the latest parameters
Expand All @@ -136,6 +140,7 @@ export default function ControlsSideBarComponent(props: Props): JSX.Element {
},
SWITCH_MERGE_MODE: (event: KeyboardEvent | undefined) => {
preventDefault(event);
if (!labels.length) return;
const merging = activeControl === ActiveControl.MERGE;
if (!merging) {
canvasInstance.cancel();
Expand All @@ -145,6 +150,7 @@ export default function ControlsSideBarComponent(props: Props): JSX.Element {
},
SWITCH_SPLIT_MODE: (event: KeyboardEvent | undefined) => {
preventDefault(event);
if (!labels.length) return;
const splitting = activeControl === ActiveControl.SPLIT;
if (!splitting) {
canvasInstance.cancel();
Expand All @@ -154,6 +160,7 @@ export default function ControlsSideBarComponent(props: Props): JSX.Element {
},
SWITCH_GROUP_MODE: (event: KeyboardEvent | undefined) => {
preventDefault(event);
if (!labels.length) return;
const grouping = activeControl === ActiveControl.GROUP;
if (!grouping) {
canvasInstance.cancel();
Expand Down Expand Up @@ -213,24 +220,29 @@ export default function ControlsSideBarComponent(props: Props): JSX.Element {
<ObservedDrawRectangleControl
canvasInstance={canvasInstance}
isDrawing={activeControl === ActiveControl.DRAW_RECTANGLE}
disabled={!labels.length}
bsekachev marked this conversation as resolved.
Show resolved Hide resolved
/>
<ObservedDrawPolygonControl
canvasInstance={canvasInstance}
isDrawing={activeControl === ActiveControl.DRAW_POLYGON}
disabled={!labels.length}
/>
<ObservedDrawPolylineControl
canvasInstance={canvasInstance}
isDrawing={activeControl === ActiveControl.DRAW_POLYLINE}
disabled={!labels.length}
/>
<ObservedDrawPointsControl
canvasInstance={canvasInstance}
isDrawing={activeControl === ActiveControl.DRAW_POINTS}
disabled={!labels.length}
/>
<ObservedDrawCuboidControl
canvasInstance={canvasInstance}
isDrawing={activeControl === ActiveControl.DRAW_CUBOID}
disabled={!labels.length}
/>
<ObservedSetupTagControl canvasInstance={canvasInstance} isDrawing={false} />
<ObservedSetupTagControl canvasInstance={canvasInstance} isDrawing={false} disabled={!labels.length} />

<hr />

Expand All @@ -239,19 +251,22 @@ export default function ControlsSideBarComponent(props: Props): JSX.Element {
canvasInstance={canvasInstance}
activeControl={activeControl}
mergeObjects={mergeObjects}
disabled={!labels.length}
/>
<ObservedGroupControl
switchGroupShortcut={normalizedKeyMap.SWITCH_GROUP_MODE}
resetGroupShortcut={normalizedKeyMap.RESET_GROUP}
canvasInstance={canvasInstance}
activeControl={activeControl}
groupObjects={groupObjects}
disabled={!labels.length}
/>
<ObservedSplitControl
canvasInstance={canvasInstance}
switchSplitShortcut={normalizedKeyMap.SWITCH_SPLIT_MODE}
activeControl={activeControl}
splitTrack={splitTrack}
disabled={!labels.length}
/>

<ExtraControlsControl />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import withVisibilityHandling from './handle-popover-visibility';
export interface Props {
canvasInstance: Canvas;
isDrawing: boolean;
disabled?: boolean;
}

const CustomPopover = withVisibilityHandling(Popover, 'draw-cuboid');
function DrawPolygonControl(props: Props): JSX.Element {
const { canvasInstance, isDrawing } = props;
const { canvasInstance, isDrawing, disabled } = props;
const dynamcPopoverPros = isDrawing ?
{
overlayStyle: {
Expand All @@ -41,7 +42,9 @@ function DrawPolygonControl(props: Props): JSX.Element {
className: 'cvat-draw-cuboid-control',
};

return (
return disabled ? (
<Icon className='cvat-draw-cuboid-control cvat-disabled-canvas-control' component={CubeIcon} />
) : (
<CustomPopover
{...dynamcPopoverPros}
overlayClassName='cvat-draw-shape-popover'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import withVisibilityHandling from './handle-popover-visibility';
export interface Props {
canvasInstance: Canvas;
isDrawing: boolean;
disabled?: boolean;
}

const CustomPopover = withVisibilityHandling(Popover, 'draw-points');
function DrawPointsControl(props: Props): JSX.Element {
const { canvasInstance, isDrawing } = props;
const { canvasInstance, isDrawing, disabled } = props;
const dynamcPopoverPros = isDrawing ?
{
overlayStyle: {
Expand All @@ -40,7 +41,9 @@ function DrawPointsControl(props: Props): JSX.Element {
className: 'cvat-draw-points-control',
};

return (
return disabled ? (
<Icon className='cvat-draw-points-control cvat-disabled-canvas-control' component={PointIcon} />
) : (
<CustomPopover
{...dynamcPopoverPros}
overlayClassName='cvat-draw-shape-popover'
Expand Down
Loading