Skip to content

Commit

Permalink
Implemented propagate backward (#5355)
Browse files Browse the repository at this point in the history
<!-- Raised an issue to propose your change
(https://github.com/cvat-ai/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](https://github.com/cvat-ai/cvat/blob/develop/CONTRIBUTING.md)
guide. -->

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

### Motivation and context
Resolved #2998

<img width="428" alt="image"
src="https://user-images.githubusercontent.com/40690378/203806586-1367477b-cfff-46f1-947b-d0292cd6f02e.png">


### 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 by a reason then ~~explicitly
strikethrough~~ the whole
line. If you don't do that github will show an incorrect process 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
- [x] I have added a description of my changes into
[CHANGELOG](https://github.com/cvat-ai/cvat/blob/develop/CHANGELOG.md)
file
- [ ] I have updated the [documentation](
https://github.com/cvat-ai/cvat/blob/develop/README.md#documentation)
accordingly
- [x] I have added tests to cover my changes
- [x] I have linked related issues ([read 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/cvat-ai/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/cvat-ai/cvat/tree/develop/cvat-core#versioning),
[cvat-data](https://github.com/cvat-ai/cvat/tree/develop/cvat-data#versioning)
and
[cvat-ui](https://github.com/cvat-ai/cvat/tree/develop/cvat-ui#versioning))

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/cvat-ai/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.
  • Loading branch information
bsekachev authored Nov 29, 2022
1 parent 2ecd8c7 commit 460df33
Show file tree
Hide file tree
Showing 17 changed files with 302 additions and 303 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ from online detectors & interactors) (<https://github.com/opencv/cvat/pull/4543>
- Added Webhooks (<https://github.com/opencv/cvat/pull/4863>)
- Authentication with social accounts google & github (<https://github.com/opencv/cvat/pull/5147>, <https://github.com/opencv/cvat/pull/5181>, <https://github.com/opencv/cvat/pull/5295>)
- REST API tests to export job datasets & annotations and validate their structure (<https://github.com/opencv/cvat/pull/5160>)
- Propagation backward on UI (<https://github.com/opencv/cvat/pull/5355>)

### Changed
- `api/docs`, `api/swagger`, `api/schema`, `server/about` endpoints now allow unauthorized access (<https://github.com/opencv/cvat/pull/4928>, <https://github.com/opencv/cvat/pull/4935>)
Expand Down
2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.44.1",
"version": "1.44.2",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
96 changes: 53 additions & 43 deletions cvat-ui/src/actions/annotation-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,9 @@ export enum AnnotationActionTypes {
REMOVE_OBJECT = 'REMOVE_OBJECT',
REMOVE_OBJECT_SUCCESS = 'REMOVE_OBJECT_SUCCESS',
REMOVE_OBJECT_FAILED = 'REMOVE_OBJECT_FAILED',
PROPAGATE_OBJECT = 'PROPAGATE_OBJECT',
PROPAGATE_OBJECT_SUCCESS = 'PROPAGATE_OBJECT_SUCCESS',
PROPAGATE_OBJECT_FAILED = 'PROPAGATE_OBJECT_FAILED',
CHANGE_PROPAGATE_FRAMES = 'CHANGE_PROPAGATE_FRAMES',
SWITCH_PROPAGATE_VISIBILITY = 'SWITCH_PROPAGATE_VISIBILITY',
SWITCH_SHOWING_STATISTICS = 'SWITCH_SHOWING_STATISTICS',
SWITCH_SHOWING_FILTERS = 'SWITCH_SHOWING_FILTERS',
COLLECT_STATISTICS = 'COLLECT_STATISTICS',
Expand Down Expand Up @@ -404,9 +403,32 @@ export function showFilters(visible: boolean): AnyAction {
};
}

export function propagateObjectAsync(sessionInstance: any, objectState: any, from: number, to: number): ThunkAction {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
export function switchPropagateVisibility(visible: boolean): AnyAction {
return {
type: AnnotationActionTypes.SWITCH_PROPAGATE_VISIBILITY,
payload: { visible },
};
}

export function propagateObjectAsync(from: number, to: number): ThunkAction {
return async (dispatch: ActionCreator<Dispatch>, getState): Promise<void> => {
const state = getState();
const {
job: {
instance: sessionInstance,
},
annotations: {
activatedStateID,
states: objectStates,
},
} = state.annotation;

try {
const objectState = objectStates.find((_state: any) => _state.clientID === activatedStateID);
if (!objectState) {
throw new Error('There is not an activated object state to be propagated');
}

const getCopyFromState = (_objectState: any): any => ({
attributes: _objectState.attributes,
points: _objectState.shapeType === 'skeleton' ? null : _objectState.points,
Expand All @@ -423,9 +445,10 @@ export function propagateObjectAsync(sessionInstance: any, objectState: any, fro
});

const copy = getCopyFromState(objectState);
await sessionInstance.logger.log(LogType.propagateObject, { count: to - from + 1 });
await sessionInstance.logger.log(LogType.propagateObject, { count: Math.abs(to - from) });
const states = [];
for (let frame = from; frame <= to; frame++) {
const sign = Math.sign(to - from);
for (let frame = from + sign; sign > 0 ? frame <= to : frame >= to; frame += sign) {
copy.frame = frame;
copy.elements.forEach((element: any) => { element.frame = frame; });
const newState = new cvat.classes.ObjectState(copy);
Expand All @@ -437,40 +460,17 @@ export function propagateObjectAsync(sessionInstance: any, objectState: any, fro

dispatch({
type: AnnotationActionTypes.PROPAGATE_OBJECT_SUCCESS,
payload: {
objectState,
history,
},
payload: { history },
});
} catch (error) {
dispatch({
type: AnnotationActionTypes.PROPAGATE_OBJECT_FAILED,
payload: {
error,
},
payload: { error },
});
}
};
}

export function propagateObject(objectState: any | null): AnyAction {
return {
type: AnnotationActionTypes.PROPAGATE_OBJECT,
payload: {
objectState,
},
};
}

export function changePropagateFrames(frames: number): AnyAction {
return {
type: AnnotationActionTypes.CHANGE_PROPAGATE_FRAMES,
payload: {
frames,
},
};
}

export function removeObjectAsync(sessionInstance: any, objectState: any, force: boolean): ThunkAction {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
try {
Expand Down Expand Up @@ -661,6 +661,13 @@ export function getPredictionsAsync(): ThunkAction {
};
}

export function confirmCanvasReady(): AnyAction {
return {
type: AnnotationActionTypes.CONFIRM_CANVAS_READY,
payload: {},
};
}

export function changeFrameAsync(
toFrame: number,
fillBuffer?: boolean,
Expand All @@ -670,16 +677,24 @@ export function changeFrameAsync(
return async (dispatch: ActionCreator<Dispatch>, getState: () => CombinedState): Promise<void> => {
const state: CombinedState = getState();
const { instance: job } = state.annotation.job;
const {
propagate: {
visible: propagateVisible,
},
statistics: {
visible: statisticsVisible,
},
} = state.annotation;
const { filters, frame, showAllInterpolationTracks } = receiveAnnotationsParameters();

try {
if (toFrame < job.startFrame || toFrame > job.stopFrame) {
throw Error(`Required frame ${toFrame} is out of the current job`);
}

const abortAction = (): AnyAction => {
const abortAction = (): void => {
const currentState = getState();
return ({
dispatch({
type: AnnotationActionTypes.CHANGE_FRAME_SUCCESS,
payload: {
number: currentState.annotation.player.frame.number,
Expand All @@ -694,6 +709,8 @@ export function changeFrameAsync(
curZ: currentState.annotation.annotations.zLayer.cur,
},
});

dispatch(confirmCanvasReady());
};

dispatch({
Expand All @@ -702,17 +719,17 @@ export function changeFrameAsync(
});

if (toFrame === frame && !forceUpdate) {
dispatch(abortAction());
abortAction();
return;
}

const data = await job.frames.get(toFrame, fillBuffer, frameStep);
const states = await job.annotations.get(toFrame, showAllInterpolationTracks, filters);

if (!isAbleToChangeFrame()) {
if (!isAbleToChangeFrame() || statisticsVisible || propagateVisible) {
// while doing async actions above, canvas can become used by a user in another way
// so, we need an additional check and if it is used, we do not update state
dispatch(abortAction());
abortAction();
return;
}

Expand Down Expand Up @@ -933,13 +950,6 @@ export function resetCanvas(): AnyAction {
};
}

export function confirmCanvasReady(): AnyAction {
return {
type: AnnotationActionTypes.CONFIRM_CANVAS_READY,
payload: {},
};
}

export function closeJob(): ThunkAction {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
const { jobInstance } = receiveAnnotationsParameters();
Expand Down
Loading

0 comments on commit 460df33

Please sign in to comment.