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

Updated MIL tracker implementation #8942

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions changelog.d/20250115_125619_sekachev.bs_updated_mil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Changed

- Enhanced MIL tracker. Optimized memory usage. Now it is runnable on many frames, and applicable to drawn rectangles.
(<https://github.com/cvat-ai/cvat/pull/8942>)
10 changes: 7 additions & 3 deletions cvat-core/src/frames.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2022-2024 CVAT.ai Corporation
// Copyright (C) 2022-2025 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -300,7 +300,11 @@ export class FrameData {
);
}

async data(onServerRequest = () => {}): Promise<ImageBitmap | Blob> {
async data(onServerRequest = () => {}): Promise<{
renderWidth: number;
renderHeight: number;
imageData: ImageBitmap | Blob;
}> {
const result = await PluginRegistry.apiWrapper.call(this, FrameData.prototype.data, onServerRequest);
return result;
}
Expand Down Expand Up @@ -372,7 +376,7 @@ Object.defineProperty(FrameData.prototype.data, 'implementation', {
renderWidth: number;
renderHeight: number;
imageData: ImageBitmap | Blob;
} | Blob>((resolve, reject) => {
}>((resolve, reject) => {
const requestId = +_.uniqueId();
const requestedDataFrameNumber = meta.getDataFrameNumber(this.number - jobStartFrame);
const chunkIndex = meta.getFrameChunkIndex(requestedDataFrameNumber);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-2024 CVAT.ai Corporation
// Copyright (C) 2023-2025 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -37,7 +37,6 @@ const core = getCore();
interface State {
actions: BaseAction[];
activeAction: BaseAction | null;
initialized: boolean;
fetching: boolean;
progress: number | null;
progressMessage: string | null;
Expand All @@ -50,7 +49,6 @@ interface State {
}

enum ReducerActionType {
SET_INITIALIZED = 'SET_INITIALIZED',
SET_ANNOTATIONS_ACTIONS = 'SET_ANNOTATIONS_ACTIONS',
SET_ACTIVE_ANNOTATIONS_ACTION = 'SET_ACTIVE_ANNOTATIONS_ACTION',
UPDATE_PROGRESS = 'UPDATE_PROGRESS',
Expand All @@ -65,9 +63,6 @@ enum ReducerActionType {
}

export const reducerActions = {
setInitialized: (initialized: boolean) => (
createAction(ReducerActionType.SET_INITIALIZED, { initialized })
),
setAnnotationsActions: (actions: BaseAction[]) => (
createAction(ReducerActionType.SET_ANNOTATIONS_ACTIONS, { actions })
),
Expand Down Expand Up @@ -105,7 +100,6 @@ export const reducerActions = {

const defaultState = {
actions: [],
initialized: false,
fetching: false,
activeAction: null,
progress: null,
Expand All @@ -119,23 +113,13 @@ const defaultState = {
};

const reducer = (state: State = { ...defaultState }, action: ActionUnion<typeof reducerActions>): State => {
if (action.type === ReducerActionType.SET_INITIALIZED) {
return {
...state,
initialized: action.payload.initialized,
};
}

if (action.type === ReducerActionType.SET_ANNOTATIONS_ACTIONS) {
const { actions } = action.payload;
const { targetObjectState } = state;

const filteredActions = targetObjectState ? actions
.filter((_action) => _action.isApplicableForObject(targetObjectState)) : actions;
return {
...state,
actions,
activeAction: filteredActions[0] ?? null,
activeAction: state.activeAction ?? actions[0] ?? null,
};
}

Expand Down Expand Up @@ -246,7 +230,6 @@ type ActionParameterProps = NonNullable<BaseAction['parameters']>[keyof BaseActi

const componentStorage = createStore(reducer, {
actions: [],
initialized: false,
fetching: false,
activeAction: null,
progress: null,
Expand Down Expand Up @@ -319,15 +302,16 @@ function ActionParameterComponent(props: ActionParameterProps & { onChange: (val
interface Props {
onClose: () => void;
targetObjectState?: ObjectState;
defaultAnnotationAction?: string;
}

function AnnotationsActionsModalContent(props: Props): JSX.Element {
const { onClose, targetObjectState: defaultTargetObjectState } = props;
const { onClose, targetObjectState: defaultTargetObjectState, defaultAnnotationAction } = props;
const dispatch = useDispatch();
const storage = getCVATStore();
const cancellationRef = useRef<boolean>(false);
const {
initialized, actions, activeAction, fetching, targetObjectState, cancelled,
actions, activeAction, fetching, targetObjectState, cancelled,
progress, progressMessage, frameFrom, frameTo, actionParameters, modalVisible,
} = useSelector((state: State) => ({ ...state }), shallowEqual);

Expand All @@ -337,20 +321,25 @@ function AnnotationsActionsModalContent(props: Props): JSX.Element {
const currentFrameAction = activeAction instanceof BaseCollectionAction || targetObjectState !== null;

useEffect(() => {
dispatch(reducerActions.setVisible(true));
dispatch(reducerActions.updateFrameFrom(jobInstance.startFrame));
dispatch(reducerActions.updateFrameTo(jobInstance.stopFrame));
dispatch(reducerActions.updateTargetObjectState(defaultTargetObjectState ?? null));
}, []);
core.actions.list().then((list: BaseAction[]) => {
dispatch(reducerActions.setAnnotationsActions(list));

if (defaultAnnotationAction) {
const defaultAction = list.find((action) => action.name === defaultAnnotationAction);
if (
defaultAction &&
(!defaultTargetObjectState || defaultAction.isApplicableForObject(defaultTargetObjectState))
) {
dispatch(reducerActions.setActiveAnnotationsAction(defaultAction));
}
}

useEffect(() => {
if (!initialized) {
core.actions.list().then((list: BaseAction[]) => {
dispatch(reducerActions.setAnnotationsActions(list));
dispatch(reducerActions.setInitialized(true));
});
}
}, [initialized]);
dispatch(reducerActions.setVisible(true));
dispatch(reducerActions.updateFrameFrom(jobInstance.startFrame));
dispatch(reducerActions.updateFrameTo(jobInstance.stopFrame));
dispatch(reducerActions.updateTargetObjectState(defaultTargetObjectState ?? null));
});
}, []);

return (
<Modal
Expand Down Expand Up @@ -643,14 +632,23 @@ function AnnotationsActionsModalContent(props: Props): JSX.Element {

const MemoizedAnnotationsActionsModalContent = React.memo(AnnotationsActionsModalContent);

export function openAnnotationsActionModal(objectState?: ObjectState): void {
export function openAnnotationsActionModal({
defaultObjectState,
defaultAnnotationAction,
}: {
defaultObjectState?: ObjectState,
defaultAnnotationAction?: string,
} = {}): void {
window.document.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));

const div = window.document.createElement('div');
window.document.body.append(div);
const root = createRoot(div);
root.render(
<Provider store={componentStorage}>
<MemoizedAnnotationsActionsModalContent
targetObjectState={objectState}
targetObjectState={defaultObjectState}
defaultAnnotationAction={defaultAnnotationAction}
onClose={() => {
root.unmount();
div.remove();
Expand Down
Loading
Loading