Skip to content

Commit

Permalink
Fixed calculating statistics in case with removed frames (cvat-ai#6493)
Browse files Browse the repository at this point in the history
<!-- Raise an issue to propose your change
(https://github.com/opencv/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the [Contribution
guide](https://opencv.github.io/cvat/docs/contributing/). -->

<!-- Provide a general summary of your changes in the Title above -->

### Motivation and context
<!-- Why is this change required? What problem does it solve? If it
fixes an open
issue, please link to the issue here. Describe your changes in detail,
add
screenshots. -->

### How has this been tested?
<!-- Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc. -->

### Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply.
If an item isn't applicable for some reason, then ~~explicitly
strikethrough~~ the whole
line. If you don't do that, GitHub will show incorrect progress for the
pull request.
If you're unsure about any of these, don't hesitate to ask. We're here
to help! -->
- [x] I submit my changes into the `develop` branch
- [ ] I have added a description of my changes into the
[CHANGELOG](https://github.com/opencv/cvat/blob/develop/CHANGELOG.md)
file
- [ ] I have updated the documentation accordingly
- [x] I have added tests to cover my changes
- [ ] I have linked related issues (see [GitHub docs](

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))
- [x] I have increased versions of npm packages if it is necessary

([cvat-canvas](https://github.com/opencv/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/opencv/cvat/tree/develop/cvat-core#versioning),

[cvat-data](https://github.com/opencv/cvat/tree/develop/cvat-data#versioning)
and

[cvat-ui](https://github.com/opencv/cvat/tree/develop/cvat-ui#versioning))

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/opencv/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.
  • Loading branch information
bsekachev authored Jul 19, 2023
1 parent 783c414 commit 19fefc5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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

0 comments on commit 19fefc5

Please sign in to comment.