Skip to content

Commit b71e77b

Browse files
authored
Using serverside paremeter min_pos_points, right colors of labels in … (#2162)
* Using serverside paremeter min_pos_points, right colors of labels in detector runner * Updated changelog & versions * Using color from consts instead of literal
1 parent a299796 commit b71e77b

File tree

12 files changed

+59
-66
lines changed

12 files changed

+59
-66
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
### Changed
2020
- UI models (like DEXTR) were redesigned to be more interactive (<https://github.com/opencv/cvat/pull/2054>)
2121
- Used Ubuntu:20.04 as a base image for CVAT Dockerfile (<https://github.com/opencv/cvat/pull/2101>)
22+
- Right colors of label tags in label mapping when a user runs automatic detection (<https://github.com/openvinotoolkit/cvat/pull/2162>)
2223

2324
### Deprecated
2425
-

cvat-core/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cvat-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cvat-core",
3-
"version": "3.6.1",
3+
"version": "3.7.0",
44
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
55
"main": "babel.config.js",
66
"scripts": {

cvat-core/src/lambda-manager.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ class LambdaManager {
2929

3030
for (const model of result) {
3131
models.push(new MLModel({
32-
id: model.id,
33-
name: model.name,
34-
description: model.description,
35-
framework: model.framework,
36-
labels: [...model.labels],
32+
...model,
3733
type: model.kind,
3834
}));
3935
}

cvat-core/src/ml-model.js

+15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ class MLModel {
1515
this._framework = data.framework;
1616
this._description = data.description;
1717
this._type = data.type;
18+
this._params = {
19+
canvas: {
20+
minPosVertices: data.min_pos_points,
21+
},
22+
};
1823
}
1924

2025
/**
@@ -68,6 +73,16 @@ class MLModel {
6873
get type() {
6974
return this._type;
7075
}
76+
77+
/**
78+
* @returns {object}
79+
* @readonly
80+
*/
81+
get params() {
82+
return {
83+
canvas: { ...this._params.canvas },
84+
};
85+
}
7186
}
7287

7388
module.exports = MLModel;

cvat-ui/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cvat-ui/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cvat-ui",
3-
"version": "1.9.3",
3+
"version": "1.9.4",
44
"description": "CVAT single-page application",
55
"main": "src/index.tsx",
66
"scripts": {

cvat-ui/src/actions/annotation-actions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ export function repeatDrawShapeAsync(): ThunkAction {
14461446
canvasInstance.interact({
14471447
enabled: true,
14481448
shapeType: 'points',
1449-
minPosVertices: 4, // TODO: Add parameter to interactor
1449+
...activeInteractor.params.canvas,
14501450
});
14511451
dispatch(interactWithCanvas(activeInteractor, activeLabelID));
14521452
}

cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/tools-control.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,8 @@ export class ToolsControlComponent extends React.PureComponent<Props, State> {
657657
canvasInstance.cancel();
658658
canvasInstance.interact({
659659
shapeType: 'points',
660-
minPosVertices: 4, // TODO: Add parameter to interactor
661660
enabled: true,
661+
...activeInteractor.params.canvas,
662662
});
663663

664664
onInteractionStart(activeInteractor, activeLabelID);

cvat-ui/src/components/model-runner-modal/detector-runner.tsx

+31-55
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,15 @@ import Select, { OptionProps } from 'antd/lib/select';
1010
import Checkbox, { CheckboxChangeEvent } from 'antd/lib/checkbox';
1111
import Tooltip from 'antd/lib/tooltip';
1212
import Tag from 'antd/lib/tag';
13-
import notification from 'antd/lib/notification';
1413
import Text from 'antd/lib/typography/Text';
1514
import InputNumber from 'antd/lib/input-number';
16-
17-
import { Model, StringObject } from 'reducers/interfaces';
1815
import Button from 'antd/lib/button';
16+
import notification from 'antd/lib/notification';
1917

18+
import { Model, StringObject } from 'reducers/interfaces';
2019

21-
function colorGenerator(): () => string {
22-
const values = [
23-
'magenta', 'green', 'geekblue',
24-
'orange', 'red', 'cyan',
25-
'blue', 'volcano', 'purple',
26-
];
27-
28-
let index = 0;
29-
30-
return (): string => {
31-
const color = values[index++];
32-
if (index >= values.length) {
33-
index = 0;
34-
}
35-
36-
return color;
37-
};
38-
}
3920

40-
const nextColor = colorGenerator();
21+
import consts from 'consts';
4122

4223
interface Props {
4324
withCleanup: boolean;
@@ -56,7 +37,6 @@ function DetectorRunner(props: Props): JSX.Element {
5637

5738
const [modelID, setModelID] = useState<string | null>(null);
5839
const [mapping, setMapping] = useState<StringObject>({});
59-
const [colors, setColors] = useState<StringObject>({});
6040
const [threshold, setThreshold] = useState<number>(0.5);
6141
const [distance, setDistance] = useState<number>(50);
6242
const [cleanup, setCleanup] = useState<boolean>(false);
@@ -90,21 +70,15 @@ function DetectorRunner(props: Props): JSX.Element {
9070
function updateMatch(modelLabel: string | null, taskLabel: string | null): void {
9171
if (match.model && taskLabel) {
9272
const newmatch: { [index: string]: string } = {};
93-
const newcolor: { [index: string]: string } = {};
9473
newmatch[match.model] = taskLabel;
95-
newcolor[match.model] = nextColor();
96-
setColors({ ...colors, ...newcolor });
9774
setMapping({ ...mapping, ...newmatch });
9875
setMatch({ model: null, task: null });
9976
return;
10077
}
10178

10279
if (match.task && modelLabel) {
10380
const newmatch: { [index: string]: string } = {};
104-
const newcolor: { [index: string]: string } = {};
10581
newmatch[modelLabel] = match.task;
106-
newcolor[modelLabel] = nextColor();
107-
setColors({ ...colors, ...newcolor });
10882
setMapping({ ...mapping, ...newmatch });
10983
setMatch({ model: null, task: null });
11084
return;
@@ -157,18 +131,15 @@ function DetectorRunner(props: Props): JSX.Element {
157131
onChange={(_modelID: string): void => {
158132
const newmodel = models
159133
.filter((_model): boolean => _model.id === _modelID)[0];
160-
const newcolors: StringObject = {};
161134
const newmapping = task.labels
162135
.reduce((acc: StringObject, label: any): StringObject => {
163136
if (newmodel.labels.includes(label.name)) {
164137
acc[label.name] = label.name;
165-
newcolors[label.name] = nextColor();
166138
}
167139
return acc;
168140
}, {});
169141

170142
setMapping(newmapping);
171-
setColors(newcolors);
172143
setMatch({ model: null, task: null });
173144
setModelID(_modelID);
174145
}}
@@ -180,29 +151,34 @@ function DetectorRunner(props: Props): JSX.Element {
180151
</Col>
181152
</Row>
182153
{ isDetector && !!Object.keys(mapping).length && (
183-
Object.keys(mapping).map((modelLabel: string) => (
184-
<Row key={modelLabel} type='flex' justify='start' align='middle'>
185-
<Col span={10}>
186-
<Tag color={colors[modelLabel]}>{modelLabel}</Tag>
187-
</Col>
188-
<Col span={10} offset={1}>
189-
<Tag color={colors[modelLabel]}>{mapping[modelLabel]}</Tag>
190-
</Col>
191-
<Col offset={1}>
192-
<Tooltip title='Remove the mapped values' mouseLeaveDelay={0}>
193-
<Icon
194-
className='cvat-danger-circle-icon'
195-
type='close-circle'
196-
onClick={(): void => {
197-
const newmapping = { ...mapping };
198-
delete newmapping[modelLabel];
199-
setMapping(newmapping);
200-
}}
201-
/>
202-
</Tooltip>
203-
</Col>
204-
</Row>
205-
))
154+
Object.keys(mapping).map((modelLabel: string) => {
155+
const label = task.labels
156+
.filter((_label: any): boolean => _label.name === mapping[modelLabel])[0];
157+
const color = label ? label.color : consts.NEW_LABEL_COLOR;
158+
return (
159+
<Row key={modelLabel} type='flex' justify='start' align='middle'>
160+
<Col span={10}>
161+
<Tag color={color}>{modelLabel}</Tag>
162+
</Col>
163+
<Col span={10} offset={1}>
164+
<Tag color={color}>{mapping[modelLabel]}</Tag>
165+
</Col>
166+
<Col offset={1}>
167+
<Tooltip title='Remove the mapped values' mouseLeaveDelay={0}>
168+
<Icon
169+
className='cvat-danger-circle-icon'
170+
type='close-circle'
171+
onClick={(): void => {
172+
const newmapping = { ...mapping };
173+
delete newmapping[modelLabel];
174+
setMapping(newmapping);
175+
}}
176+
/>
177+
</Tooltip>
178+
</Col>
179+
</Row>
180+
);
181+
})
206182
)}
207183
{ isDetector && !!taskLabels.length && !!modelLabels.length && (
208184
<>

cvat-ui/src/reducers/interfaces.ts

+3
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ export interface Model {
141141
framework: string;
142142
description: string;
143143
type: string;
144+
params: {
145+
canvas: object;
146+
};
144147
}
145148

146149
export enum RQStatus {

cvat/apps/lambda_manager/views.py

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def __init__(self, gateway, data):
109109
self.framework = data['metadata']['annotations'].get('framework')
110110
# display name for the function
111111
self.name = data['metadata']['annotations'].get('name', self.id)
112+
self.min_pos_points = int(data['metadata']['annotations'].get('min_pos_points', 1))
112113
self.gateway = gateway
113114

114115
def to_dict(self):
@@ -120,6 +121,7 @@ def to_dict(self):
120121
'description': self.description,
121122
'framework': self.framework,
122123
'name': self.name,
124+
'min_pos_points': self.min_pos_points
123125
}
124126

125127
return response

0 commit comments

Comments
 (0)