Added ability to match many model labels to one task labels (#1051)

* Added ability to match many model labels to one task labels

* Fixed grammar
main
Boris Sekachev 6 years ago committed by Nikita Manovich
parent e5b4c194bb
commit 247d7f04ec

@ -11,6 +11,7 @@ import {
Select, Select,
Tooltip, Tooltip,
Checkbox, Checkbox,
notification,
} from 'antd'; } from 'antd';
import { Model } from '../../reducers/interfaces'; import { Model } from '../../reducers/interfaces';
@ -118,6 +119,12 @@ export default class ModelRunnerModalComponent extends React.PureComponent<Props
.filter((model) => model.name === selectedModel)[0]; .filter((model) => model.name === selectedModel)[0];
if (!selectedModelInstance.primary) { if (!selectedModelInstance.primary) {
if (!selectedModelInstance.labels.length) {
notification.warning({
message: 'The selected model does not include any lables',
});
}
let taskLabels: string[] = taskInstance.labels let taskLabels: string[] = taskInstance.labels
.map((label: any): string => label.name); .map((label: any): string => label.name);
const [defaultMapping, defaultColors]: StringObject[] = selectedModelInstance.labels const [defaultMapping, defaultColors]: StringObject[] = selectedModelInstance.labels
@ -304,37 +311,24 @@ export default class ModelRunnerModalComponent extends React.PureComponent<Props
const model = selectedModel && models const model = selectedModel && models
.filter((_model): boolean => _model.name === selectedModel)[0]; .filter((_model): boolean => _model.name === selectedModel)[0];
const excludedLabels: { const excludedModelLabels: string[] = Object.keys(mapping);
model: string[];
task: string[];
} = {
model: [],
task: [],
};
const withMapping = model && !model.primary; const withMapping = model && !model.primary;
const tags = withMapping ? Object.keys(mapping) const tags = withMapping ? excludedModelLabels
.map((modelLabel: string) => { .map((modelLabel: string) => this.renderMappingTag(
const taskLabel = mapping[modelLabel]; modelLabel,
excludedLabels.model.push(modelLabel); mapping[modelLabel],
excludedLabels.task.push(taskLabel); )) : [];
return this.renderMappingTag(
modelLabel,
mapping[modelLabel],
);
}) : [];
const availableModelLabels = model ? model.labels const availableModelLabels = model ? model.labels
.filter( .filter(
(label: string) => !excludedLabels.model.includes(label), (label: string) => !excludedModelLabels.includes(label),
) : []; ) : [];
const availableTaskLabels = taskInstance.labels const taskLabels = taskInstance.labels.map(
.map( (label: any) => label.name,
(label: any) => label.name, );
).filter((label: string): boolean => !excludedLabels.task.includes(label));
const mappingISAvailable = !!availableModelLabels.length const mappingISAvailable = !!availableModelLabels.length
&& !!availableTaskLabels.length; && !!taskLabels.length;
return ( return (
<div className='cvat-run-model-dialog'> <div className='cvat-run-model-dialog'>
@ -342,7 +336,7 @@ export default class ModelRunnerModalComponent extends React.PureComponent<Props
{ withMapping && tags} { withMapping && tags}
{ withMapping { withMapping
&& mappingISAvailable && mappingISAvailable
&& this.renderMappingInput(availableModelLabels, availableTaskLabels) && this.renderMappingInput(availableModelLabels, taskLabels)
} }
{ withMapping { withMapping
&& ( && (

@ -26,11 +26,12 @@ interface DispatchToProps {
function mapStateToProps(state: CombinedState): StateToProps { function mapStateToProps(state: CombinedState): StateToProps {
function convert(items: ShareItem[], path?: string): TreeNodeNormal[] { function convert(items: ShareItem[], path?: string): TreeNodeNormal[] {
return items.map((item): TreeNodeNormal => { return items.map((item): TreeNodeNormal => {
const key = `${path}${item.name}/`; const isLeaf = item.type !== 'DIR';
const key = `${path}${item.name}${isLeaf ? '' : '/'}`;
return { return {
key, key,
isLeaf,
title: item.name || 'root', title: item.name || 'root',
isLeaf: item.type !== 'DIR',
children: convert(item.children, key), children: convert(item.children, key),
}; };
}); });

Loading…
Cancel
Save