ground_truth_jobs.js 11.3 KB
Newer Older
K
klakhov 已提交
1 2 3 4 5 6 7 8 9
// Copyright (C) 2023 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

/// <reference types="cypress" />

context('Ground truth jobs', () => {
    const caseId = 'Ground truth jobs';
    const labelName = 'car';
K
klakhov 已提交
10
    const taskName = `Annotation task for Case ${caseId}`;
K
klakhov 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    const attrName = `Attr for Case ${caseId}`;
    const textDefaultValue = 'Some default value for type Text';
    const imagesCount = 10;
    const imageFileName = 'ground_truth_1';
    const width = 800;
    const height = 800;
    const posX = 10;
    const posY = 10;
    const color = 'gray';
    const archiveName = `${imageFileName}.zip`;
    const archivePath = `cypress/fixtures/${archiveName}`;
    const imagesFolder = `cypress/fixtures/${imageFileName}`;
    const directoryToArchive = imagesFolder;

    const jobOptions = {
        jobType: 'Ground truth',
        frameSelectionMethod: 'Random',
K
klakhov 已提交
28
        fromTaskPage: true,
K
klakhov 已提交
29 30
    };

K
klakhov 已提交
31
    const groundTruthRectangles = [
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
        {
            id: 1,
            points: 'By 2 Points',
            type: 'Shape',
            labelName,
            firstX: 250,
            firstY: 350,
            secondX: 350,
            secondY: 450,
        },
        {
            id: 2,
            points: 'By 2 Points',
            type: 'Shape',
            labelName,
            firstX: 350,
            firstY: 450,
            secondX: 450,
            secondY: 550,
        },
        {
            id: 3,
            points: 'By 2 Points',
            type: 'Shape',
            labelName,
            firstX: 350,
            firstY: 550,
            secondX: 450,
            secondY: 650,
        },
    ];

K
klakhov 已提交
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
    const rectangles = [
        {
            points: 'By 2 Points',
            type: 'Shape',
            labelName,
            firstX: 270,
            firstY: 350,
            secondX: 370,
            secondY: 450,
        },
        {
            id: 2,
            points: 'By 2 Points',
            type: 'Shape',
            labelName,
            firstX: 350,
            firstY: 450,
            secondX: 450,
            secondY: 550,
        },
        {
            points: 'By 2 Points',
            type: 'Shape',
            labelName,
            firstX: 130,
            firstY: 200,
            secondX: 150,
            secondY: 250,
        },
    ];

95
    let groundTruthJobID = null;
K
klakhov 已提交
96
    let jobID = null;
K
klakhov 已提交
97 98
    let taskID = null;
    let qualityReportID = null;
K
klakhov 已提交
99

K
klakhov 已提交
100 101 102
    // With seed = 1, frameCount = 3, totalFrames = 10 - predifined ground truth frames are:
    const groundTruthFrames = [1, 6, 7];

K
klakhov 已提交
103 104 105 106 107 108 109 110 111
    function checkCardValue(className, value) {
        cy.get(className)
            .should('be.visible')
            .within(() => {
                cy.get('.cvat-analytics-card-value').should('have.text', value);
            });
    }

    function openQualityTab() {
112
        cy.clickInTaskMenu('View analytics', true);
K
klakhov 已提交
113 114 115 116 117 118
        cy.get('.cvat-task-analytics-tabs')
            .within(() => {
                cy.contains('span', 'Quality').click();
            });
    }

119 120 121 122 123 124 125 126
    function checkRectangle(rectangle) {
        cy.get(`#cvat_canvas_shape_${rectangle.id}`)
            .should('be.visible')
            .should('have.class', 'cvat_canvas_ground_truth');
        cy.get(`#cvat-objects-sidebar-state-item-${rectangle.id}`)
            .should('be.visible');
    }

K
klakhov 已提交
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
    function checkConflicts(type, amount) {
        switch (type) {
            case 'warning': {
                cy.get('.cvat-conflict-warning').should('have.length', amount);
                cy.get('.cvat-objects-sidebar-warning-item').should('have.length', amount);
                break;
            }
            case 'error': {
                cy.get('.cvat-conflict-error').should('have.length', amount);
                cy.get('.cvat-objects-sidebar-conflict-item').should('have.length', amount);
                break;
            }
            default: {
                cy.get('.cvat-conflict-warning').should('not.exist');
                cy.get('.cvat-conflict-error').should('not.exist');
                cy.get('.cvat-objects-sidebar-warning-item').should('not.exist');
                cy.get('.cvat-objects-sidebar-conflict-item').should('not.exist');
            }
        }
    }

K
klakhov 已提交
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
    function waitForReport(authKey, rqID) {
        cy.request({
            method: 'POST',
            url: `/api/quality/reports?rq_id=${rqID}`,
            headers: {
                Authorization: `Token ${authKey}`,
            },
            body: {
                task_id: taskID,
            },
        }).then((response) => {
            if (response.status === 201) {
                qualityReportID = response.body.id;
                return;
            }
            waitForReport(authKey, rqID);
        });
    }

K
klakhov 已提交
167 168 169
    before(() => {
        cy.visit('auth/login');
        cy.login();
K
klakhov 已提交
170
        cy.visit('/tasks');
K
klakhov 已提交
171 172 173
        cy.imageGenerator(imagesFolder, imageFileName, width, height, color, posX, posY, labelName, imagesCount);
        cy.createZipArchive(directoryToArchive, archivePath);
        cy.createAnnotationTask(taskName, labelName, attrName, textDefaultValue, archiveName);
174
        cy.openTask(taskName);
K
klakhov 已提交
175 176 177
        cy.url().then((url) => {
            taskID = Number(url.split('/').slice(-1)[0].split('?')[0]);
        });
178 179 180
        cy.get('.cvat-job-item').first().invoke('attr', 'data-row-id').then((val) => {
            jobID = val;
        });
K
klakhov 已提交
181 182 183 184 185 186 187 188
    });

    describe(`Testing case "${caseId}"`, () => {
        it('Create ground truth job from task page', () => {
            cy.createJob({
                ...jobOptions,
                quantity: 15,
            });
K
klakhov 已提交
189
            cy.url().then((url) => {
190
                groundTruthJobID = Number(url.split('/').slice(-1)[0].split('?')[0]);
K
klakhov 已提交
191 192

                cy.interactMenu('Open the task');
193
                cy.get('.cvat-job-item').contains('a', `Job #${groundTruthJobID}`)
K
klakhov 已提交
194 195 196 197
                    .parents('.cvat-job-item')
                    .find('.ant-tag')
                    .should('have.text', 'Ground truth');
            });
K
klakhov 已提交
198 199 200
        });

        it('Delete ground truth job', () => {
201
            cy.deleteJob(groundTruthJobID);
K
klakhov 已提交
202 203
        });

K
klakhov 已提交
204 205 206 207 208 209 210 211 212 213 214 215 216
        it('Check quality page, create ground truth job from quality page', () => {
            openQualityTab();
            checkCardValue('.cvat-task-mean-annotation-quality', 'N/A');
            checkCardValue('.cvat-task-gt-conflicts', 'N/A');
            checkCardValue('.cvat-task-issues', '0');

            cy.get('.cvat-job-empty-ground-truth-item')
                .should('be.visible')
                .within(() => {
                    cy.contains('button', 'Create new').click();
                });
            cy.createJob({
                ...jobOptions,
K
klakhov 已提交
217 218
                frameCount: 3,
                seed: 1,
K
klakhov 已提交
219 220 221 222
                fromTaskPage: false,
            });

            cy.url().then((url) => {
223
                groundTruthJobID = Number(url.split('/').slice(-1)[0].split('?')[0]);
K
klakhov 已提交
224 225 226

                cy.interactMenu('Open the task');
                openQualityTab();
227
                cy.get('.cvat-job-item').contains('a', `Job #${groundTruthJobID}`)
K
klakhov 已提交
228 229 230 231
                    .parents('.cvat-job-item')
                    .find('.ant-tag')
                    .should('have.text', 'Ground truth');
            });
K
klakhov 已提交
232
        });
K
klakhov 已提交
233

K
klakhov 已提交
234
        it('Frame navigation in ground truth job', () => {
235
            cy.get('.cvat-job-item').contains('a', `Job #${groundTruthJobID}`).click();
K
klakhov 已提交
236 237 238 239 240 241 242 243 244
            cy.get('.cvat-spinner').should('not.exist');

            groundTruthFrames.forEach((frame) => {
                cy.checkFrameNum(frame);
                cy.get('.cvat-player-next-button').click();
            });

            cy.checkFrameNum(groundTruthFrames[2]);
        });
245

K
klakhov 已提交
246
        it('Check ground truth annotations in regular job', () => {
247 248 249 250 251
            cy.interactMenu('Open the task');
            cy.get('.cvat-job-item').contains('a', `Job #${groundTruthJobID}`).click();

            groundTruthFrames.forEach((frame, index) => {
                cy.goCheckFrameNumber(frame);
K
klakhov 已提交
252
                cy.createRectangle(groundTruthRectangles[index]);
253 254
            });
            cy.saveJob();
K
klakhov 已提交
255 256 257 258
            cy.interactMenu('Finish the job');
            cy.get('.cvat-modal-content-finish-job').within(() => {
                cy.contains('button', 'Continue').click();
            });
259 260 261 262 263 264 265

            cy.get('.cvat-job-item').contains('a', `Job #${jobID}`).click();
            cy.changeWorkspace('Review');

            cy.get('.cvat-objects-sidebar-show-ground-truth').click();
            groundTruthFrames.forEach((frame, index) => {
                cy.goCheckFrameNumber(frame);
K
klakhov 已提交
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
                checkRectangle(groundTruthRectangles[index]);
            });
        });

        it('Add annotations to regular job, check quality report', () => {
            cy.changeWorkspace('Standard');
            groundTruthFrames.forEach((frame, index) => {
                cy.goCheckFrameNumber(frame);
                cy.createRectangle(rectangles[index]);
            });
            cy.saveJob();

            cy.logout();
            cy.getAuthKey().then((res) => {
                const authKey = res.body.key;
                cy.request({
                    method: 'POST',
                    url: '/api/quality/reports',
                    headers: {
                        Authorization: `Token ${authKey}`,
                    },
                    body: {
                        task_id: taskID,
                    },
                }).then((response) => {
                    const rqID = response.body.rq_id;
                    waitForReport(authKey, rqID);
                });
294
            });
K
klakhov 已提交
295 296
            cy.login();
            cy.visit('/tasks');
297 298
            cy.get('.cvat-spinner').should('not.exist');
            cy.intercept('GET', '/api/quality/reports**').as('getReport');
K
klakhov 已提交
299

300
            cy.openTask(taskName);
K
klakhov 已提交
301 302 303 304 305 306 307 308 309 310
            openQualityTab();
            cy.wait('@getReport');
            checkCardValue('.cvat-task-mean-annotation-quality', '50.0%');
            checkCardValue('.cvat-task-gt-conflicts', '3');
            checkCardValue('.cvat-task-issues', '0');
        });

        it('Check quality report is available for download', () => {
            cy.get('.cvat-analytics-download-report-button').click();
            cy.verifyDownload(`quality-report-task_${taskID}-${qualityReportID}.json`);
311
        });
K
klakhov 已提交
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343

        it('Conflicts on canvas and sidebar', () => {
            cy.get('.cvat-task-job-list').within(() => {
                cy.contains('a', `Job #${jobID}`).click();
            });
            cy.get('.cvat-spinner').should('not.exist');

            cy.changeWorkspace('Review');
            cy.get('.cvat-objects-sidebar-tabs').within(() => {
                cy.contains('span', 'Issues').click();
            });
            cy.get('.cvat-objects-sidebar-show-ground-truth').filter(':visible').click();

            cy.goCheckFrameNumber(groundTruthFrames[0]);
            checkConflicts('warning', 1);

            cy.goCheckFrameNumber(groundTruthFrames[1]);
            checkConflicts();

            cy.goCheckFrameNumber(groundTruthFrames[2]);
            checkConflicts('error', 2);
        });

        it('Frames with conflicts navigation', () => {
            cy.goCheckFrameNumber(0);

            cy.get('.cvat-issues-sidebar-next-frame').click();
            cy.checkFrameNum(groundTruthFrames[0]);

            cy.get('.cvat-issues-sidebar-next-frame').click();
            cy.checkFrameNum(groundTruthFrames[2]);
        });
K
klakhov 已提交
344 345
    });
});