-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathconsensus.js
213 lines (197 loc) · 9.27 KB
/
consensus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Copyright (C) CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT
/// <reference types="cypress" />
import { translatePoints } from '../../support/utils';
context('Basic manipulations with consensus job replicas', () => {
const labelName = 'Consensus';
const taskName = 'Test consensus';
const serverFiles = ['archive.zip'];
const replicas = 4;
const taskSpec = {
name: taskName,
labels: [{
name: labelName,
attributes: [],
type: 'any',
}],
};
const dataSpec = {
server_files: serverFiles,
image_quality: 70,
};
const extras = { consensus_replicas: replicas };
before(() => {
cy.visit('auth/login');
cy.login();
cy.headlessCreateTask(taskSpec, dataSpec, extras);
cy.get('.cvat-create-task-dropdown').click();
cy.get('.cvat-create-task-button').should('be.visible').click();
});
describe('Consensus job creation', () => {
const maxReplicas = 10;
it('Check allowed number of replicas', () => {
cy.contains('Advanced configuration').click();
// 'Consensus Replicas' field cannot equal to 1
cy.get('#consensusReplicas').type(`{backspace}${1}`);
cy.get('.ant-form-item-explain-error')
.should('be.visible')
.invoke('text').should('eq', 'Value can not be equal to 1');
cy.contains('button', 'Submit & Continue').click();
cy.get('.ant-notification-notice-error').should('exist').and('be.visible');
cy.closeNotification('.ant-notification-notice-error');
// 'Consensus Replicas' field cannot be > 10
cy.get('#consensusReplicas').type(`{backspace}${maxReplicas + 1}`);
cy.get('.ant-form-item-explain-error').should('be.visible')
.invoke('text').should('eq', `Value must be less than ${maxReplicas}`);
cy.contains('button', 'Submit & Continue').click();
cy.get('.ant-notification-notice-error').should('exist').and('be.visible');
cy.closeNotification('.ant-notification-notice-error');
cy.get('#consensusReplicas').clear();
});
it('Check new consensus task has correct tags and drop-down with replicas', () => {
// Create task with consensus
cy.goToTaskList();
cy.openTask(taskName);
cy.get('.cvat-task-details-wrapper').should('be.visible');
cy.get('.ant-notification-notice-error').should('not.exist');
// Check tags
cy.get('.cvat-tag-consensus').then((tags) => {
expect(tags.length).to.equal(2);
cy.wrap(tags).each(($el) => {
cy.wrap($el).should('have.text', 'Consensus');
});
});
cy.get('.cvat-consensus-job-collapse').should('be.visible')
.within(($el) => {
expect($el.text()).to.equal(`${replicas} Replicas`);
cy.wrap($el).click();
});
});
});
describe('Cosensus jobs merging', () => {
const shape0 = {
objectType: 'shape',
labelName,
frame: 0,
type: 'rectangle',
points: [250, 64, 491, 228],
occluded: false,
};
const jobIDs = [];
before(() => {
cy.headlessCreateTask(taskSpec, dataSpec, extras);
cy.goToTaskList();
cy.openTask(taskName);
cy.get('.cvat-consensus-job-collapse').click();
});
it("Check new merge buttons exist and are visible. Trying to merge 'new' jobs should trigger errors", () => {
// Check asc order of jobs in drop-down
function parseJobId(jobItem) {
const jobItemText = jobItem.innerText;
const [start, stop] = [0, jobItemText.indexOf('\n')];
return +(jobItemText.substring(start, stop).split('#')[1]);
}
cy.get('.cvat-job-item').each(([$el], i) => {
const jobID = parseJobId($el);
jobIDs.push(jobID);
expect(jobID).equals(jobIDs[0] + i);
});
// Merge one consensus job
cy.then(() => {
cy.mergeConsensusJob(jobIDs[0], 400);
});
cy.get('.cvat-notification-notice-consensus-merge-task-failed')
.should('be.visible')
.invoke('text').should('include', 'Could not merge the job');
cy.closeNotification('.cvat-notification-notice-consensus-merge-task-failed');
// Merge all consensus jobs in task
cy.mergeConsensusTask(400);
cy.get('.cvat-notification-notice-consensus-merge-task-failed')
.should('be.visible')
.invoke('text')
.should('include', 'Could not merge the task');
cy.closeNotification('.cvat-notification-notice-consensus-merge-task-failed');
});
it('Check consensus management page', () => {
const defaultQuorum = 50;
const defaultIoU = 40;
cy.contains('button', 'Actions').click();
cy.contains('Consensus management').should('be.visible').click();
cy.get('.cvat-consensus-management-inner').should('be.visible');
// Save settings, confirm request is sent
cy.intercept('PATCH', 'api/consensus/settings/**').as('settingsMeta');
cy.contains('button', 'Save').click();
cy.wait('@settingsMeta');
cy.get('.ant-notification-notice-message')
.should('be.visible')
.invoke('text')
.should('eq', 'Settings have been updated');
cy.closeNotification('.ant-notification-notice-closable');
// Forms and invalid saving
function checkFieldSaving(selector, defaultValue) {
cy.get(selector).then(([$el]) => {
cy.wrap($el).invoke('val').should('eq', `${defaultValue}`);
cy.wrap($el).clear();
});
cy.get('.ant-form-item-explain-error').should('be.visible');
cy.contains('button', 'Save').click();
}
checkFieldSaving('#quorum', defaultQuorum);
checkFieldSaving('#iouThreshold', defaultIoU);
cy.get('.ant-notification-notice').should('not.exist');
// Go back to task page
cy.get('.cvat-back-btn').should('be.visible').click();
});
it('Create annotations and check that job replicas merge correctly', () => {
// Create annotations for job replicas
const delta = 50;
const [consensusJobID, ...replicaJobIDs] = jobIDs;
for (let i = 0, shape = shape0; i < replicas; i++) {
cy.headlessCreateObjects([shape], replicaJobIDs[i]); // only 'in progress' jobs can be merged
cy.headlessUpdateJob(replicaJobIDs[i], { state: 'in progress' });
const points = translatePoints(shape.points, delta, 'x');
shape = { ...shape, points };
}
// Merging of consensus job should go without errors in network and UI
cy.mergeConsensusJob(consensusJobID);
cy.get('.cvat-notification-notice-consensus-merge-job-failed').should('not.exist');
cy.get('.ant-notification-notice-message')
.should('be.visible')
.invoke('text')
.should('eq', `Consensus job #${consensusJobID} has been merged`);
cy.closeNotification('.ant-notification-notice-closable');
// Shapes in consensus job and a job replica in the middle should be equal
const middle = Math.floor(jobIDs.length / 2);
const consensusRect = {};
cy.openJob(0, false).then(() => {
cy.get('.cvat_canvas_shape').trigger('mousemove');
cy.get('.cvat_canvas_shape').then(($el) => {
consensusRect.x = $el.attr('x');
consensusRect.y = $el.attr('y');
consensusRect.width = $el.attr('width');
consensusRect.height = $el.attr('height');
});
cy.get('#cvat_canvas_text_content').should('be.visible')
.invoke('text')
.should('include', `${labelName}`)
.and('include', 'consensus');
});
cy.go('back'); // go to previous page
// After returning to task page, consensus job should be 'completed'
cy.get('.cvat-job-item').first()
.find('.cvat-job-item-state').first()
.invoke('text')
.should('eq', 'completed');
cy.contains('.cvat-job-item', `Job #${jobIDs[middle]}`).scrollIntoView();
cy.openJob(middle, false).then(() => {
cy.get('.cvat_canvas_shape').then(($el) => {
expect($el.attr('x')).to.equal(consensusRect.x);
expect($el.attr('y')).to.equal(consensusRect.y);
expect($el.attr('width')).to.equal(consensusRect.width);
expect($el.attr('height')).to.equal(consensusRect.height);
});
});
});
});
});