Skip to content

Commit

Permalink
Add YOLO annotation out-of-bounds error tolerance.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfl28 committed May 30, 2024
1 parent 9727ce7 commit 0eacaff
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,27 @@ private BoundingBoxData parseBoundingBoxData(String line, int lineNumber) {
double heightRelative = parseRatio(scanner, lineNumber);

double xMinRelative = xMidRelative - widthRelative / 2;
if(xMinRelative < 0 && -xMinRelative < 1e-6) {
xMinRelative = 0;
}
assertRatio(xMinRelative, INVALID_BOUNDING_BOX_COORDINATES_MESSAGE + lineNumber + ".");

double yMinRelative = yMidRelative - heightRelative / 2;
if(yMinRelative < 0 && -yMinRelative < 1e-6) {
yMinRelative = 0;
}
assertRatio(yMinRelative, INVALID_BOUNDING_BOX_COORDINATES_MESSAGE + lineNumber + ".");

double xMaxRelative = xMidRelative + widthRelative / 2;
if(xMaxRelative > 1 && xMaxRelative - 1 < 1e-6) {
xMaxRelative = 1;
}
assertRatio(xMaxRelative, INVALID_BOUNDING_BOX_COORDINATES_MESSAGE + lineNumber + ".");

double yMaxRelative = yMidRelative + heightRelative / 2;
if(yMaxRelative > 1 && yMaxRelative - 1 < 1e-6) {
yMaxRelative = 1;
}
assertRatio(yMaxRelative, INVALID_BOUNDING_BOX_COORDINATES_MESSAGE + lineNumber + ".");

String categoryName = categories.get(categoryId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import java.io.File;
import java.util.List;
import java.util.Map;

import static org.testfx.api.FxAssert.verifyThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,41 @@ void onReloadAnnotations_afterImageFilesReopened_shouldCorrectlyDisplayBoundingS
verifyThat(mainView.getObjectTree().getRoot().getChildren(), Matchers.hasSize(0), saveScreenshot(testinfo));
}

@Test
void onLoadAnnotation_YOLO_WhenAnnotationWithinYOLOPrecision_ShouldLoadBoundingBoxes(FxRobot robot,
TestInfo testinfo) {

final String referenceAnnotationDirectoryPath = "/testannotations/yolo/precision";

waitUntilCurrentImageIsLoaded(testinfo);
WaitForAsyncUtils.waitForFxEvents();
timeOutAssertServiceSucceeded(controller.getImageMetaDataLoadingService(), testinfo);

verifyThat(mainView.getStatusBar().getCurrentEventMessage(),
Matchers.startsWith("Successfully loaded 4 image-files from folder "), saveScreenshot(testinfo));

final File referenceAnnotationFolder =
new File(getClass().getResource(referenceAnnotationDirectoryPath).getFile());

// Load bounding-boxes defined in the reference annotation-file.
Platform.runLater(() -> controller
.initiateAnnotationImport(referenceAnnotationFolder, ImageAnnotationLoadStrategy.Type.YOLO));
WaitForAsyncUtils.waitForFxEvents();

timeOutAssertServiceSucceeded(controller.getAnnotationImportService(), testinfo);

final Map<String, Integer> counts = model.getCategoryToAssignedBoundingShapesCountMap();
Assertions.assertDoesNotThrow(() -> WaitForAsyncUtils.waitFor(TIMEOUT_DURATION_IN_SEC, TimeUnit.SECONDS,
() -> Objects.equals(counts.get("Test"), 2)),
() -> saveScreenshotAndReturnMessage(testinfo, "Correct bounding box " +
"per-category-counts were not read within " +
TIMEOUT_DURATION_IN_SEC + " sec."));

verifyThat(model.getCategoryToAssignedBoundingShapesCountMap().size(), Matchers.equalTo(1),
saveScreenshot(testinfo));
verifyThat(model.getObjectCategories(), Matchers.hasSize(1), saveScreenshot(testinfo));
}

private void userChoosesNoOnAnnotationImportDialogSubtest(FxRobot robot, File annotationFile, TestInfo testinfo) {
userChoosesToSaveExistingAnnotationsOnAnnotationImport(robot, annotationFile, testinfo);
userChoosesNotToSaveExistingAnnotationsOnAnnotationImport(robot, annotationFile, testinfo);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0 0.250000 0.250000 0.500001 0.500001
0 0.750000 0.750000 0.500001 0.500001
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test

0 comments on commit 0eacaff

Please sign in to comment.