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

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

Merged
merged 2 commits into from
Jan 14, 2020
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
44 changes: 19 additions & 25 deletions cvat-ui/src/components/model-runner-modal/model-runner-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Select,
Tooltip,
Checkbox,
notification,
} from 'antd';

import { Model } from '../../reducers/interfaces';
Expand Down Expand Up @@ -118,6 +119,12 @@ export default class ModelRunnerModalComponent extends React.PureComponent<Props
.filter((model) => model.name === selectedModel)[0];

if (!selectedModelInstance.primary) {
if (!selectedModelInstance.labels.length) {
notification.warning({
message: 'The selected model does not include any lables',
});
}

let taskLabels: string[] = taskInstance.labels
.map((label: any): string => label.name);
const [defaultMapping, defaultColors]: StringObject[] = selectedModelInstance.labels
Expand Down Expand Up @@ -304,45 +311,32 @@ export default class ModelRunnerModalComponent extends React.PureComponent<Props
const model = selectedModel && models
.filter((_model): boolean => _model.name === selectedModel)[0];

const excludedLabels: {
model: string[];
task: string[];
} = {
model: [],
task: [],
};

const excludedModelLabels: string[] = Object.keys(mapping);
const withMapping = model && !model.primary;
const tags = withMapping ? Object.keys(mapping)
.map((modelLabel: string) => {
const taskLabel = mapping[modelLabel];
excludedLabels.model.push(modelLabel);
excludedLabels.task.push(taskLabel);
return this.renderMappingTag(
modelLabel,
mapping[modelLabel],
);
}) : [];
const tags = withMapping ? excludedModelLabels
.map((modelLabel: string) => this.renderMappingTag(
modelLabel,
mapping[modelLabel],
)) : [];

const availableModelLabels = model ? model.labels
.filter(
(label: string) => !excludedLabels.model.includes(label),
(label: string) => !excludedModelLabels.includes(label),
) : [];
const availableTaskLabels = taskInstance.labels
.map(
(label: any) => label.name,
).filter((label: string): boolean => !excludedLabels.task.includes(label));
const taskLabels = taskInstance.labels.map(
(label: any) => label.name,
);

const mappingISAvailable = !!availableModelLabels.length
&& !!availableTaskLabels.length;
&& !!taskLabels.length;

return (
<div className='cvat-run-model-dialog'>
{ this.renderModelSelector() }
{ withMapping && tags}
{ withMapping
&& mappingISAvailable
&& this.renderMappingInput(availableModelLabels, availableTaskLabels)
&& this.renderMappingInput(availableModelLabels, taskLabels)
}
{ withMapping
&& (
Expand Down
5 changes: 3 additions & 2 deletions cvat-ui/src/containers/file-manager/file-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ interface DispatchToProps {
function mapStateToProps(state: CombinedState): StateToProps {
function convert(items: ShareItem[], path?: string): TreeNodeNormal[] {
return items.map((item): TreeNodeNormal => {
const key = `${path}${item.name}/`;
const isLeaf = item.type !== 'DIR';
const key = `${path}${item.name}${isLeaf ? '' : '/'}`;
return {
key,
isLeaf,
title: item.name || 'root',
isLeaf: item.type !== 'DIR',
children: convert(item.children, key),
};
});
Expand Down