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

Project import simple implementation #3790

Merged
merged 73 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
457358b
temp
ActiveChooN Aug 28, 2021
ec977dd
drafgt ui implementation
ActiveChooN Sep 3, 2021
37d73c0
Merge branch 'develop' into dk/project-import-prototype
ActiveChooN Sep 7, 2021
874bc28
Added tooltip
ActiveChooN Sep 7, 2021
2ca1fb6
Minor fixes
ActiveChooN Sep 24, 2021
197151c
Simple task creation without data
ActiveChooN Sep 24, 2021
f5554a0
temp
ActiveChooN Sep 27, 2021
5adc197
WIP on adding data
ActiveChooN Sep 28, 2021
292ace2
Finished data parsing
ActiveChooN Oct 5, 2021
4ddcbcb
Added labels creating
ActiveChooN Oct 5, 2021
7c1d8ac
Removed restriction
ActiveChooN Oct 5, 2021
29b69e8
Added annotation import for dataset importing
ActiveChooN Oct 7, 2021
e75106b
Task creating via serializer
ActiveChooN Oct 7, 2021
f46c364
Merge branch 'develop' into dk/project-import-prototype
ActiveChooN Oct 7, 2021
70c2104
Added soft attribute import
ActiveChooN Oct 11, 2021
7e66ad9
Merge branch 'develop' into dk/project-import-prototype
ActiveChooN Oct 14, 2021
9bbb5c6
Added some formats
ActiveChooN Oct 14, 2021
652246e
Added 3d format support
ActiveChooN Oct 14, 2021
8f3f2ed
Related images support and setting proper dataset root
ActiveChooN Oct 19, 2021
b3a6e50
Simplified related images support
ActiveChooN Oct 19, 2021
d65f71b
Added project import from cvat format (without annotations)
ActiveChooN Oct 21, 2021
1337c40
Moved to datumaro cvat extractor
ActiveChooN Oct 28, 2021
d1e19bd
Merge branch 'develop' into dk/project-import-prototype
ActiveChooN Oct 28, 2021
df67aab
Added CHANGELOG, increased packages version
ActiveChooN Oct 28, 2021
bf9f7c3
Added styles
ActiveChooN Oct 28, 2021
3ed1794
Fixed linters problem
ActiveChooN Oct 28, 2021
0474934
Added import progress modal
ActiveChooN Nov 1, 2021
29204ba
Fixed menu items
ActiveChooN Nov 1, 2021
e2b27c2
Merge branch 'develop' into dk/project-import-prototype
ActiveChooN Nov 1, 2021
da769f3
Fixed linters
ActiveChooN Nov 1, 2021
9a0c1ac
Fixed imports
ActiveChooN Nov 1, 2021
ea8516f
Fixed TODOs
ActiveChooN Nov 2, 2021
1b6af26
Update cvat/apps/dataset_manager/bindings.py
ActiveChooN Nov 2, 2021
e30e5e7
Update cvat/apps/dataset_manager/bindings.py
ActiveChooN Nov 2, 2021
307b557
Fixed comments
ActiveChooN Nov 2, 2021
7958c00
Fixed tests issues with CVAT format
ActiveChooN Nov 10, 2021
792a4ef
Merge branch 'develop' into dk/project-import-prototype
ActiveChooN Nov 10, 2021
a4b02fb
Fixed cypress tests
ActiveChooN Nov 10, 2021
b86bd5e
Merge branch 'develop' into dk/project-import-prototype
ActiveChooN Nov 16, 2021
199308b
Update cvat-core/src/annotations.js
ActiveChooN Nov 16, 2021
65c4768
Update cvat-core/src/annotations.js
ActiveChooN Nov 16, 2021
f1e9bf6
Update cvat-ui/src/actions/import-actions.ts
ActiveChooN Nov 16, 2021
9193692
Update cvat-ui/src/components/import-dataset-modal/import-dataset-mod…
ActiveChooN Nov 16, 2021
f754353
Update cvat-ui/src/components/import-dataset-modal/import-dataset-mod…
ActiveChooN Nov 16, 2021
ba52e9d
Update cvat-ui/src/components/import-dataset-modal/import-dataset-mod…
ActiveChooN Nov 16, 2021
a30b4d4
Update cvat-core/src/server-proxy.js
ActiveChooN Nov 16, 2021
99d522a
Update cvat-ui/src/components/import-dataset-modal/import-dataset-sta…
ActiveChooN Nov 16, 2021
2df9ab0
Update cvat-ui/src/components/import-dataset-modal/import-dataset-sta…
ActiveChooN Nov 16, 2021
ee67763
Merge branch 'dk/project-import-prototype' of https://github.com/open…
ActiveChooN Nov 16, 2021
993b6f4
Fixed comments
ActiveChooN Nov 16, 2021
b98124e
Fixed callback arguments
ActiveChooN Nov 16, 2021
18068b4
Added other simple formats
ActiveChooN Nov 19, 2021
be6fbbc
Fixed comments
ActiveChooN Nov 23, 2021
c043831
Merge branch 'develop' into dk/project-import-prototype
ActiveChooN Nov 23, 2021
c82bffa
Added openimages format import
ActiveChooN Nov 23, 2021
1a84181
Merge branch 'develop' into dk/project-import-prototype
ActiveChooN Nov 24, 2021
e9a9921
Merge branch 'develop' into dk/project-import-prototype
ActiveChooN Nov 29, 2021
91d7153
Added simple tests
ActiveChooN Nov 30, 2021
22c17d5
Reworked import progress
ActiveChooN Dec 1, 2021
2ac9e09
Merge branch 'develop' into dk/project-import-prototype
Dec 3, 2021
ab7a935
Merge branch 'develop' into dk/project-import-prototype
ActiveChooN Dec 7, 2021
e1f0861
Fixed tracks importing in cvat format
ActiveChooN Dec 8, 2021
e24301e
Fixed dataset root
ActiveChooN Dec 9, 2021
edda65e
Fixed methods
ActiveChooN Dec 9, 2021
4b4dff7
Fixed export status update
ActiveChooN Dec 13, 2021
11602de
Merge branch 'develop' into dk/project-import-prototype
ActiveChooN Dec 13, 2021
c3f310c
Fixed name
ActiveChooN Dec 13, 2021
0fe7619
Fixed import error with subsets
ActiveChooN Dec 14, 2021
59fc825
Merge branch 'develop' into dk/project-import-prototype
ActiveChooN Dec 14, 2021
48f044b
Fixed label colors import
ActiveChooN Dec 14, 2021
285d2d0
Fixed label colors
ActiveChooN Dec 14, 2021
4a50366
Merge branch 'develop' into dk/project-import-prototype
Dec 16, 2021
c1110da
Added cvat-ui version
ActiveChooN Dec 17, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Data sorting option (<https://github.com/openvinotoolkit/cvat/pull/3937>)
- Options to change font size & position of text labels on the canvas (<https://github.com/openvinotoolkit/cvat/pull/3972>)
- Add "tag" return type for automatic annotation in Nuclio (<https://github.com/openvinotoolkit/cvat/pull/3896>)
- Dataset importing to a project (<https://github.com/openvinotoolkit/cvat/pull/3790>)

### Changed
- TDB
Expand Down
4 changes: 2 additions & 2 deletions cvat-core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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": "3.21.1",
"version": "3.22.0",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "babel.config.js",
"scripts": {
Expand Down
17 changes: 17 additions & 0 deletions cvat-core/src/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,22 @@
return result;
}

function importDataset(instance, format, file, updateStatusCallback = () => {}) {
if (!(typeof format === 'string')) {
throw new ArgumentError('Format must be a string');
}
if (!(instance instanceof Project)) {
throw new ArgumentError('Instance should be a Project instance');
}
if (!(typeof updateStatusCallback === 'function')) {
throw new ArgumentError('Callback should be a function');
}
if (!(['application/zip', 'application/x-zip-compressed'].includes(file.type))) {
throw new ArgumentError('File should be file instance with ZIP extension');
ActiveChooN marked this conversation as resolved.
Show resolved Hide resolved
}
return serverProxy.projects.importDataset(instance.id, format, file, updateStatusCallback);
}

function undoActions(session, count) {
const sessionType = session instanceof Task ? 'task' : 'job';
const cache = getCache(sessionType);
Expand Down Expand Up @@ -366,6 +382,7 @@
importAnnotations,
exportAnnotations,
exportDataset,
importDataset,
undoActions,
redoActions,
freezeHistory,
Expand Down
13 changes: 11 additions & 2 deletions cvat-core/src/project-implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const { getPreview } = require('./frames');

const { Project } = require('./project');
const { exportDataset } = require('./annotations');
const { exportDataset, importDataset } = require('./annotations');

function implementProject(projectClass) {
projectClass.prototype.save.implementation = async function () {
Expand Down Expand Up @@ -61,11 +61,20 @@
};

projectClass.prototype.annotations.exportDataset.implementation = async function (
format, saveImages, customName,
format,
saveImages,
customName,
) {
const result = exportDataset(this, format, customName, saveImages);
return result;
};
projectClass.prototype.annotations.importDataset.implementation = async function (
format,
file,
updateStatusCallback,
) {
return importDataset(this, format, file, updateStatusCallback);
};

return projectClass;
}
Expand Down
11 changes: 11 additions & 0 deletions cvat-core/src/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
// So, we need return it
this.annotations = {
exportDataset: Object.getPrototypeOf(this).annotations.exportDataset.bind(this),
importDataset: Object.getPrototypeOf(this).annotations.importDataset.bind(this),
};
}

Expand Down Expand Up @@ -310,6 +311,16 @@
);
return result;
},
async importDataset(format, file, updateStatusCallback = null) {
const result = await PluginRegistry.apiWrapper.call(
this,
Project.prototype.annotations.importDataset,
format,
file,
updateStatusCallback,
);
return result;
},
},
writable: true,
}),
Expand Down
45 changes: 42 additions & 3 deletions cvat-core/src/server-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,44 @@
};
}

async function importDataset(id, format, file, onUpdate) {
const { backendAPI } = config;
const url = `${backendAPI}/projects/${id}/dataset`;

const formData = new FormData();
formData.append('dataset_file', file);

return new Promise((resolve, reject) => {
async function requestStatus() {
try {
const response = await Axios.get(`${url}?action=import_status`, {
proxy: config.proxy,
});
if (response.status === 202) {
if (onUpdate && response.data.message !== '') {
onUpdate(response.data.message, response.data.progress || 0);
}
setTimeout(requestStatus, 3000);
} else if (response.status === 201) {
resolve();
} else {
reject(generateError(response));
}
} catch (error) {
reject(generateError(error));
}
}

Axios.post(`${url}?format=${format}`, formData, {
proxy: config.proxy,
}).then(() => {
setTimeout(requestStatus, 2000);
}).catch((error) => {
reject(generateError(error));
});
});
}

async function exportTask(id) {
const { backendAPI } = config;
const url = `${backendAPI}/tasks/${id}`;
Expand Down Expand Up @@ -577,7 +615,7 @@
const response = await Axios.get(`${backendAPI}/tasks/${id}/status`);
if (['Queued', 'Started'].includes(response.data.state)) {
if (response.data.message !== '') {
onUpdate(response.data.message);
onUpdate(response.data.message, response.data.progress || 0);
}
setTimeout(checkStatus, 1000);
} else if (response.data.state === 'Finished') {
Expand Down Expand Up @@ -637,7 +675,7 @@

let response = null;

onUpdate('The task is being created on the server..');
onUpdate('The task is being created on the server..', null);
try {
response = await Axios.post(`${backendAPI}/tasks`, JSON.stringify(taskSpec), {
proxy: config.proxy,
Expand All @@ -649,7 +687,7 @@
throw generateError(errorData);
}

onUpdate('The data are being uploaded to the server 0%');
onUpdate('The data are being uploaded to the server..', null);

async function chunkUpload(taskId, file) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -1438,6 +1476,7 @@
create: createProject,
delete: deleteProject,
exportDataset: exportDataset('projects'),
importDataset,
}),
writable: false,
},
Expand Down
59 changes: 59 additions & 0 deletions cvat-ui/src/actions/import-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (C) 2021 Intel Corporation
//
// SPDX-License-Identifier: MIT

import { createAction, ActionUnion, ThunkAction } from 'utils/redux';
import { CombinedState } from 'reducers/interfaces';
import { getProjectsAsync } from './projects-actions';

export enum ImportActionTypes {
OPEN_IMPORT_MODAL = 'OPEN_IMPORT_MODAL',
CLOSE_IMPORT_MODAL = 'CLOSE_IMPORT_MODAL',
IMPORT_DATASET = 'IMPORT_DATASET',
IMPORT_DATASET_SUCCESS = 'IMPORT_DATASET_SUCCESS',
IMPORT_DATASET_FAILED = 'IMPORT_DATASET_FAILED',
IMPORT_DATASET_UPDATE_STATUS = 'IMPORT_DATASET_UPDATE_STATUS',
}

export const importActions = {
openImportModal: (instance: any) => createAction(ImportActionTypes.OPEN_IMPORT_MODAL, { instance }),
closeImportModal: () => createAction(ImportActionTypes.CLOSE_IMPORT_MODAL),
importDataset: (projectId: number) => (
createAction(ImportActionTypes.IMPORT_DATASET, { id: projectId })
),
importDatasetSuccess: () => (
createAction(ImportActionTypes.IMPORT_DATASET_SUCCESS)
),
importDatasetFailed: (instance: any, error: any) => (
createAction(ImportActionTypes.IMPORT_DATASET_FAILED, {
instance,
error,
})
),
importDatasetUpdateStatus: (progress: number, status: string) => (
createAction(ImportActionTypes.IMPORT_DATASET_UPDATE_STATUS, { progress, status })
),
};

export const importDatasetAsync = (instance: any, format: string, file: File): ThunkAction => (
async (dispatch, getState) => {
try {
const state: CombinedState = getState();
if (state.import.importingId !== null) {
throw Error('Only one importing of dataset allowed at the same time');
}
dispatch(importActions.importDataset(instance.id));
await instance.annotations.importDataset(format, file, (message: string, progress: number) => (
dispatch(importActions.importDatasetUpdateStatus(progress * 100, message))
));
} catch (error) {
dispatch(importActions.importDatasetFailed(instance, error));
return;
}

dispatch(importActions.importDatasetSuccess());
dispatch(getProjectsAsync({ id: instance.id }));
}
);

export type ImportActions = ActionUnion<typeof importActions>;
4 changes: 2 additions & 2 deletions cvat-ui/src/actions/tasks-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ export function createTaskAsync(data: any): ThunkAction<Promise<void>, {}, {}, A

dispatch(createTask());
try {
const savedTask = await taskInstance.save((status: string): void => {
dispatch(createTaskUpdateStatus(status));
const savedTask = await taskInstance.save((status: string, progress: number): void => {
dispatch(createTaskUpdateStatus(status + (progress !== null ? ` ${Math.floor(progress * 100)}%` : '')));
});
dispatch(createTaskSuccess(savedTask.id));
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function ExportDatasetModal(): JSX.Element {

useEffect(() => {
initActivities();
}, [instance?.id, instance instanceof core.classes.Project]);
}, [instance?.id, instance instanceof core.classes.Project, taskExportActivities, projectExportActivities]);

const closeModal = (): void => {
form.resetFields();
Expand Down
Loading