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

Consensus task creation #8939

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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
4 changes: 4 additions & 0 deletions changelog.d/20250113_203431_mzhiltso_consensus_tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Added

- An option to create tasks with consensus jobs
(<https://github.com/cvat-ai/cvat/pull/8939>)
1 change: 1 addition & 0 deletions cvat-core/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export enum JobState {
export enum JobType {
ANNOTATION = 'annotation',
GROUND_TRUTH = 'ground_truth',
CONSENSUS = 'consensus',
}

export enum DimensionType {
Expand Down
3 changes: 3 additions & 0 deletions cvat-core/src/server-response-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export interface SerializedTask {
subset: string;
updated_date: string;
url: string;
consensus_enabled: boolean;
}

export interface SerializedJob {
Expand All @@ -147,6 +148,8 @@ export interface SerializedJob {
url: string;
source_storage: SerializedStorage | null;
target_storage: SerializedStorage | null;
parent_job_id: number | null;
consensus_replicas: number;
}

export type AttrInputType = 'select' | 'radio' | 'checkbox' | 'number' | 'text';
Expand Down
4 changes: 4 additions & 0 deletions cvat-core/src/session-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@ export function implementTask(Task: typeof TaskClass): typeof TaskClass {
taskSpec.source_storage = this.sourceStorage.toJSON();
}

if (this.consensusReplicas) {
taskSpec.consensus_replicas = this.consensusReplicas;
}

const taskDataSpec = {
client_files: this.clientFiles,
server_files: this.serverFiles,
Expand Down
25 changes: 23 additions & 2 deletions cvat-core/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export class Job extends Session {
frame_count?: number;
project_id: number | null;
guide_id: number | null;
task_id: number | null;
task_id: number;
labels: Label[];
dimension?: DimensionType;
data_compressed_chunk_type?: ChunkType;
Expand All @@ -505,6 +505,8 @@ export class Job extends Session {
updated_date?: string,
source_storage: Storage,
target_storage: Storage,
parent_job_id: number | null;
consensus_replicas: number;
};

constructor(initialData: InitializerType) {
Expand Down Expand Up @@ -532,6 +534,8 @@ export class Job extends Session {
updated_date: undefined,
source_storage: undefined,
target_storage: undefined,
parent_job_id: null,
consensus_replicas: undefined,
};

this.#data.id = initialData.id ?? this.#data.id;
Expand All @@ -546,6 +550,8 @@ export class Job extends Session {
this.#data.data_chunk_size = initialData.data_chunk_size ?? this.#data.data_chunk_size;
this.#data.mode = initialData.mode ?? this.#data.mode;
this.#data.created_date = initialData.created_date ?? this.#data.created_date;
this.#data.parent_job_id = initialData.parent_job_id ?? this.#data.parent_job_id;
this.#data.consensus_replicas = initialData.consensus_replicas ?? this.#data.consensus_replicas;

if (Array.isArray(initialData.labels)) {
this.#data.labels = initialData.labels.map((labelData) => {
Expand Down Expand Up @@ -641,14 +647,22 @@ export class Job extends Session {
return this.#data.guide_id;
}

public get taskId(): number | null {
public get taskId(): number {
return this.#data.task_id;
}

public get dimension(): DimensionType {
return this.#data.dimension;
}

public get parentJobId(): number | null {
return this.#data.parent_job_id;
}

public get consensusReplicas(): number | null {
return this.#data.consensus_replicas;
}

public get dataChunkType(): ChunkType {
return this.#data.data_compressed_chunk_type;
}
Expand Down Expand Up @@ -751,6 +765,7 @@ export class Task extends Session {
public readonly organization: number | null;
public readonly progress: { count: number; completed: number };
public readonly jobs: Job[];
public readonly consensusEnabled: boolean;

public readonly startFrame: number;
public readonly stopFrame: number;
Expand Down Expand Up @@ -810,6 +825,7 @@ export class Task extends Session {
cloud_storage_id: undefined,
sorting_method: undefined,
files: undefined,
consensus_enabled: undefined,

validation_mode: null,
};
Expand Down Expand Up @@ -887,6 +903,8 @@ export class Task extends Session {
data_chunk_size: data.data_chunk_size,
target_storage: initialData.target_storage,
source_storage: initialData.source_storage,
parent_job_id: job.parent_job_id,
consensus_replicas: job.consensus_replicas,
});
data.jobs.push(jobInstance);
}
Expand Down Expand Up @@ -994,6 +1012,9 @@ export class Task extends Session {
copyData: {
get: () => data.copy_data,
},
consensusEnabled: {
get: () => data.consensus_enabled,
},
labels: {
get: () => [...data.labels],
set: (labels: Label[]) => {
Expand Down
16 changes: 16 additions & 0 deletions cvat-ui/src/actions/jobs-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export enum JobsActionTypes {
DELETE_JOB = 'DELETE_JOB',
DELETE_JOB_SUCCESS = 'DELETE_JOB_SUCCESS',
DELETE_JOB_FAILED = 'DELETE_JOB_FAILED',
COLLAPSE_REGULAR_JOB = 'COLLAPSE_REGULAR_JOB',
UNCOLLAPSE_REGULAR_JOB = 'UNCOLLAPSE_REGULAR_JOB',
}

interface JobsList extends Array<any> {
Expand Down Expand Up @@ -71,6 +73,12 @@ const jobsActions = {
deleteJobFailed: (jobID: number, error: any) => (
createAction(JobsActionTypes.DELETE_JOB_FAILED, { jobID, error })
),
collapseRegularJob: (jobID: number) => (
createAction(JobsActionTypes.COLLAPSE_REGULAR_JOB, { jobID })
),
uncollapseRegularJob: (jobID: number) => (
createAction(JobsActionTypes.UNCOLLAPSE_REGULAR_JOB, { jobID })
),
};

export type JobsActions = ActionUnion<typeof jobsActions>;
Expand Down Expand Up @@ -156,3 +164,11 @@ export const deleteJobAsync = (job: Job): ThunkAction => async (dispatch) => {

dispatch(jobsActions.deleteJobSuccess(job.id));
};

export const collapseRegularJob = (jobID: number, uncollapse: boolean): ThunkAction => async (dispatch) => {
if (uncollapse) {
dispatch(jobsActions.collapseRegularJob(jobID));
} else {
dispatch(jobsActions.uncollapseRegularJob(jobID));
}
};
8 changes: 6 additions & 2 deletions cvat-ui/src/actions/tasks-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ ThunkAction {
use_zip_chunks: data.advanced.useZipChunks,
use_cache: data.advanced.useCache,
sorting_method: data.advanced.sortingMethod,
source_storage: new Storage(data.advanced.sourceStorage ?? { location: StorageLocation.LOCAL }).toJSON(),
target_storage: new Storage(data.advanced.targetStorage ?? { location: StorageLocation.LOCAL }).toJSON(),
source_storage: new Storage(data.advanced.sourceStorage || { location: StorageLocation.LOCAL }).toJSON(),
target_storage: new Storage(data.advanced.targetStorage || { location: StorageLocation.LOCAL }).toJSON(),
consensus_replicas: data.advanced.consensusReplicas,
};

if (data.projectId) {
Expand Down Expand Up @@ -275,6 +276,9 @@ ThunkAction {
},
};
}
if (data.advanced.consensusReplicas) {
description.consensus_replicas = +data.advanced.consensusReplicas;
}
zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved

const taskInstance = new cvat.classes.Task(description);
taskInstance.clientFiles = data.files.local;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Text from 'antd/lib/typography/Text';
import { Store } from 'antd/lib/form/interface';
import CVATTooltip from 'components/common/cvat-tooltip';
import patterns from 'utils/validation-patterns';
import { isInteger } from 'utils/validate-integer';
import { StorageLocation } from 'reducers';
import SourceStorageField from 'components/storage/source-storage-field';
import TargetStorageField from 'components/storage/target-storage-field';
Expand Down Expand Up @@ -47,6 +48,7 @@ export interface AdvancedConfiguration {
sortingMethod: SortingMethod;
useProjectSourceStorage: boolean;
useProjectTargetStorage: boolean;
consensusReplicas: number;
sourceStorage: StorageData;
targetStorage: StorageData;
}
Expand All @@ -59,6 +61,7 @@ const initialValues: AdvancedConfiguration = {
sortingMethod: SortingMethod.LEXICOGRAPHICAL,
useProjectSourceStorage: true,
useProjectTargetStorage: true,
consensusReplicas: 0,

sourceStorage: {
location: StorageLocation.LOCAL,
Expand Down Expand Up @@ -93,30 +96,6 @@ function validateURL(_: RuleObject, value: string): Promise<void> {
return Promise.resolve();
}

const isInteger = ({ min, max }: { min?: number; max?: number }) => (
_: RuleObject,
value?: number | string,
): Promise<void> => {
if (typeof value === 'undefined' || value === '') {
return Promise.resolve();
}

const intValue = +value;
if (Number.isNaN(intValue) || !Number.isInteger(intValue)) {
return Promise.reject(new Error('Value must be a positive integer'));
}

if (typeof min !== 'undefined' && intValue < min) {
return Promise.reject(new Error(`Value must be more than ${min}`));
}

if (typeof max !== 'undefined' && intValue > max) {
return Promise.reject(new Error(`Value must be less than ${max}`));
}

return Promise.resolve();
};

const validateOverlapSize: RuleRender = ({ getFieldValue }): RuleObject => ({
validator(_: RuleObject, value?: string | number): Promise<void> {
if (typeof value !== 'undefined' && value !== '') {
Expand Down Expand Up @@ -405,6 +384,32 @@ class AdvancedConfigurationForm extends React.PureComponent<Props> {
);
}

private renderConsensusReplicas(): JSX.Element {
return (
<Form.Item
label='Consensus Replicas'
name='consensusReplicas'
rules={[
{
validator: isInteger({
min: 0,
max: 10,
filter: (intValue: number): boolean => intValue !== 1,
}),
},
]}
>
<Input
size='large'
type='number'
min={0}
max={10}
step={1}
/>
</Form.Item>
);
}

private renderSourceStorage(): JSX.Element {
const {
projectId,
Expand Down Expand Up @@ -486,6 +491,11 @@ class AdvancedConfigurationForm extends React.PureComponent<Props> {
<Row justify='start'>
<Col span={7}>{this.renderChunkSize()}</Col>
</Row>
<Row justify='start'>
<Col span={7}>
{this.renderConsensusReplicas()}
</Col>
</Row>

<Row>
<Col span={24}>{this.renderBugTracker()}</Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const defaultState: State = {
},
useProjectSourceStorage: true,
useProjectTargetStorage: true,
consensusReplicas: 0,
},
quality: {
validationMode: ValidationMode.NONE,
Expand Down
Loading
Loading