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

Initial working version of VOC XML import #280

Merged
merged 7 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add notification information
  • Loading branch information
hartmannr76 committed Oct 10, 2022
commit 746dadead9d97e82d0f167fae206e9d622c4e60f
4 changes: 3 additions & 1 deletion src/data/enums/Notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ export enum Notification {
MODEL_DOWNLOAD_ERROR = 2,
MODEL_INFERENCE_ERROR = 3,
MODEL_LOAD_ERROR = 4,
LABELS_FILE_UPLOAD_ERROR = 5
LABELS_FILE_UPLOAD_ERROR = 5,
ANNOTATION_FILE_PARSE_ERROR = 6,
ANNOTATION_IMPORT_ASSERTION_ERROR = 7,
}
10 changes: 10 additions & 0 deletions src/data/info/NotificationsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,15 @@ export const NotificationsDataMap: ExportFormatDataMap = {
header: 'Labels file was not uploaded',
description: 'Looks like you forgot to upload text file containing list of detected classes names. We need ' +
'it to map YOLOv5 model output to labels. Please re-upload all model files once again.'
},
[Notification.ANNOTATION_FILE_PARSE_ERROR]: {
header: 'Annotation files could not be parsed',
description: 'The contents of an annotation file is not valid JSON, CSV, or XML. Please fix the files selected' +
'to import and try again.',
},
[Notification.ANNOTATION_IMPORT_ASSERTION_ERROR]: {
header: 'Annotation files did not contain valid data',
description: 'Missing or invalid annotations provied during import. Please fix the files selected ' +
'to import and try again.',
}
}
18 changes: 9 additions & 9 deletions src/logic/import/voc/VOCImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ type VOCImportResult = {
fileParseResults: FileParseResult[],
};

class DocumentParsingError extends Error {
export class DocumentParsingError extends Error {
constructor(message?: string) {
super(message);
this.name = "DocumentParsingError";
}
}
class AnnotationParsingError extends Error {

export class AnnotationAssertionError extends Error {
constructor(message?: string) {
super(message);
this.name = "AnnotationParsingError";
this.name = "AnnotationAssertionError";
}
}

Expand Down Expand Up @@ -64,8 +65,8 @@ export class VOCImporter extends AnnotationImporter {
} catch (e) {
if (e instanceof DocumentParsingError) {
throw new DocumentParsingError(`Failed trying to parse ${fileName} as VOC XML document.`)
} else if (e instanceof AnnotationParsingError) {
throw new AnnotationParsingError(`Failed trying to find required VOC annotations for ${fileName}.`)
} else if (e instanceof AnnotationAssertionError) {
throw new AnnotationAssertionError(`Failed trying to find required VOC annotations for ${fileName}.`)
} else {
throw e;
}
Expand All @@ -87,10 +88,9 @@ export class VOCImporter extends AnnotationImporter {
}

protected static parseDocumentIntoImageData(document: Document, { fileParseResults, labelNames }: VOCImportResult): VOCImportResult {
const root = document.getElementsByTagName('annotation')[0];
const filename = root.getElementsByTagName('filename')[0].textContent;

try {
const root = document.getElementsByTagName('annotation')[0];
const filename = root.getElementsByTagName('filename')[0].textContent;
const [labeledBoxes, newLabelNames] = this.parseAnnotationsFromFileString(document, labelNames);

return {
Expand All @@ -101,7 +101,7 @@ export class VOCImporter extends AnnotationImporter {
}),
};
} catch {
throw new AnnotationParsingError();
throw new AnnotationAssertionError();
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/views/PopupView/ImportLabelPopup/ImportLabelPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import { updateActiveLabelType, updateImageData, updateLabelNames } from '../../
import { ImporterSpecData } from '../../../data/ImporterSpecData';
import { AnnotationFormatType } from '../../../data/enums/AnnotationFormatType';
import { ILabelFormatData } from '../../../interfaces/ILabelFormatData';
import { submitNewNotification } from '../../../store/notifications/actionCreators';
import { NotificationUtil } from '../../../utils/NotificationUtil';
import { NotificationsDataMap } from '../../../data/info/NotificationsData';
import { DocumentParsingError } from '../../../logic/import/voc/VOCImporter';
import { Notification } from '../../../data/enums/Notification';

interface IProps {
activeLabelType: LabelType,
Expand Down Expand Up @@ -59,6 +64,8 @@ const ImportLabelPopup: React.FC<IProps> = (
setLoadedLabelNames([]);
setLoadedImageData([]);
setAnnotationsLoadedError(error);
const notification = error instanceof DocumentParsingError ? Notification.ANNOTATION_FILE_PARSE_ERROR : Notification.ANNOTATION_IMPORT_ASSERTION_ERROR;
submitNewNotification(NotificationUtil.createErrorNotification(NotificationsDataMap[notification]));
};

const { getRootProps, getInputProps } = useDropzone({
Expand Down