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

Fixed calculating statistics in case with removed frames #6493

Merged
merged 3 commits into from
Jul 19, 2023
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- TDB

### Fixed
- Calculating number of objects on annotation view when frames are deleted
(<https://github.com/opencv/cvat/pull/6493>)
- \[SDK\] Ability to create attributes with blank default values
(<https://github.com/opencv/cvat/pull/6454>)
- \[SDK\] SDK should not change input data in models (<https://github.com/opencv/cvat/pull/6455>)
Expand Down
2 changes: 1 addition & 1 deletion cvat-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-core",
"version": "9.2.0",
"version": "9.2.1",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "src/api.ts",
"scripts": {
Expand Down
24 changes: 19 additions & 5 deletions cvat-core/src/annotations-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,18 +659,32 @@ export default class Collection {
fillBody(Object.values(this.labels).filter((label) => !label.hasParent));

const scanTrack = (track, prefix = ''): void => {
const countInterpolatedFrames = (start: number, stop: number, lastIsKeyframe: boolean): number => {
let count = stop - start;
if (lastIsKeyframe) {
count -= 1;
}
for (let i = start + 1; lastIsKeyframe ? i < stop : i <= stop; i++) {
if (this.frameMeta.deleted_frames[i]) {
count--;
}
}
return count;
};

const pref = prefix ? `${prefix}${sep}` : '';
const label = `${pref}${track.label.name}`;
labels[label][track.shapeType].track++;
const keyframes = Object.keys(track.shapes)
.sort((a, b) => +a - +b)
.map((el) => +el);
.map((el) => +el)
.filter((frame) => !this.frameMeta.deleted_frames[frame]);

let prevKeyframe = keyframes[0];
let visible = false;
for (const keyframe of keyframes) {
if (visible) {
const interpolated = keyframe - prevKeyframe - 1;
const interpolated = countInterpolatedFrames(prevKeyframe, keyframe, true);
labels[label].interpolated += interpolated;
labels[label].total += interpolated;
}
Expand All @@ -692,7 +706,7 @@ export default class Collection {
}

if (lastKey !== this.stopFrame && !track.get(lastKey).outside) {
const interpolated = this.stopFrame - lastKey;
const interpolated = countInterpolatedFrames(lastKey, this.stopFrame, false);
labels[label].interpolated += interpolated;
labels[label].total += interpolated;
}
Expand All @@ -719,13 +733,13 @@ export default class Collection {
}

const { name: label } = object.label;
if (objectType === 'tag') {
if (objectType === 'tag' && !this.frameMeta.deleted_frames[object.frame]) {
labels[label].tag++;
labels[label].manually++;
labels[label].total++;
} else if (objectType === 'track') {
scanTrack(object);
} else {
} else if (!this.frameMeta.deleted_frames[object.frame]) {
const { shapeType } = object as Shape;
labels[label][shapeType].shape++;
labels[label].manually++;
Expand Down
22 changes: 22 additions & 0 deletions cvat-core/tests/api/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,29 @@ describe('Feature: get statistics', () => {
expect(statistics.label[labelName].manually).toBe(2);
expect(statistics.label[labelName].interpolated).toBe(3);
expect(statistics.label[labelName].total).toBe(5);
});

test('get statistics from a job with skeletons', async () => {
const job = (await window.cvat.jobs.get({ jobID: 102 }))[0];
await job.annotations.clear(true);
let statistics = await job.annotations.statistics();
expect(statistics.total.manually).toBe(5);
expect(statistics.total.interpolated).toBe(443);
expect(statistics.total.tag).toBe(1);
expect(statistics.total.rectangle.shape).toBe(1);
expect(statistics.total.rectangle.track).toBe(1);
await job.frames.delete(500); // track frame
await job.frames.delete(510); // rectangle shape frame
await job.frames.delete(550); // the first keyframe of a track
statistics = await job.annotations.statistics();
expect(statistics.total.manually).toBe(2);
expect(statistics.total.tag).toBe(0);
expect(statistics.total.rectangle.shape).toBe(0);
expect(statistics.total.interpolated).toBe(394);
await job.frames.delete(650); // intermediate frame in a track
statistics = await job.annotations.statistics();
expect(statistics.total.interpolated).toBe(393);
await job.close();
});
});

Expand Down