Skip to content
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
4 changes: 3 additions & 1 deletion client/dive-common/apispec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ interface DatasetMetaMutable {
confidenceFilters?: Record<string, number>;
attributes?: Readonly<Record<string, Attribute>>;
}
const DatasetMetaMutableKeys = ['attributes', 'confidenceFilters', 'customTypeStyles'];

interface DatasetMeta extends DatasetMetaMutable {
id: Readonly<string>;
Expand Down Expand Up @@ -144,10 +145,11 @@ export {
useApi,
};

export type {
export {
Api,
DatasetMeta,
DatasetMetaMutable,
DatasetMetaMutableKeys,
DatasetType,
SubType,
FrameImage,
Expand Down
4 changes: 1 addition & 3 deletions client/platform/desktop/backend/ipcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ export default function register() {
});

ipcMain.handle('import-annotation', async (event, { id, path }: { id: string; path: string }) => {
const ret = await common.annotationImport(
settings.get(), id, path,
);
const ret = await common.dataFileImport(settings.get(), id, path);
return ret;
});

Expand Down
33 changes: 32 additions & 1 deletion client/platform/desktop/backend/native/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ const convertMedia = async (settingsVal: Settings, args: ConversionArgs,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const console = new Console(process.stdout, process.stderr);

const emptyCsvString = '# comment line\n# metadata,fps: 32,"whatever"\n#comment line';

mockfs({
'/opt/viame': {
configs: {
Expand All @@ -116,6 +118,11 @@ mockfs({
},
},
'/home/user/data': {
annotationImport: {
'viame.csv': emptyCsvString,
'foreign.meta.json': '{ "confidenceFilters": {"default": 0.8}, "type": "invalidtype" }',
'dive.json': '{ "0": { "trackId": 0 } }', // fake track file
},
imageSuccess: {
'foo.png': '',
'bar.png': '',
Expand Down Expand Up @@ -165,7 +172,7 @@ mockfs({
imageSuccessWithAnnotations: {
'foo.png': '',
'bar.png': '',
'file1.csv': '# comment line\n# metadata,fps: 32,"whateever"\n#comment line',
'file1.csv': emptyCsvString,
},
videoSuccess: {
'video1.avi': '',
Expand Down Expand Up @@ -488,6 +495,30 @@ describe('native.common', () => {
)).rejects.toThrowError('Found non-image type data in image list file');
});

it('dataFileImport', async () => {
const payload = await common.beginMediaImport(
settings, '/home/user/data/imageLists/success/image_list.txt', checkMedia,
);
const final = await common.finalizeMediaImport(settings, payload, updater, convertMedia);
const tracks = await common.loadDetections(settings, final.id);
expect(Object.keys(tracks)).toHaveLength(0);

await common.dataFileImport(settings, final.id, '/home/user/data/annotationImport/dive.json');
const tracks1 = await common.loadDetections(settings, final.id);
expect(Object.keys(tracks1)).toHaveLength(1);

await common.dataFileImport(settings, final.id, '/home/user/data/annotationImport/viame.csv');
const tracks2 = await common.loadDetections(settings, final.id);
expect(Object.keys(tracks2)).toHaveLength(0);
const meta = await common.loadMetadata(settings, final.id, urlMapper);
expect(meta.fps).toBe(32);

await common.dataFileImport(settings, final.id, '/home/user/data/annotationImport/foreign.meta.json');
const meta2 = await common.loadMetadata(settings, final.id, urlMapper);
expect(meta2.confidenceFilters).toStrictEqual({ "default": 0.8 });
expect(meta2.type).toBe("image-sequence"); // Ensure meta import cannot change immutable fields.
});

it('import with CSV annotations without specifying track file', async () => {
const payload = await common.beginMediaImport(settings, '/home/user/data/imageSuccessWithAnnotations', checkMedia);
payload.trackFileAbsPath = ''; //It returns null be default but users change it.
Expand Down
Loading