-
-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/issue-171_invalid_YOLO_annotations_exported_for_bboxes_on_the… (
#188) * feature/issue-171_invalid_YOLO_annotations_exported_for_bboxes_on_the_edge_of_an_image * done
- Loading branch information
Showing
6 changed files
with
200 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import {LabelName, LabelRect} from "../../../store/labels/types"; | ||
import {LabelStatus} from "../../../data/enums/LabelStatus"; | ||
import {ISize} from "../../../interfaces/ISize"; | ||
import {RectLabelsExporter} from "../../export/RectLabelsExporter"; | ||
|
||
const imageSize: ISize = { | ||
width: 1920, | ||
height: 1080 | ||
} | ||
const labelNames: LabelName[] = [ | ||
{ | ||
id: "label-000", | ||
name: "label-name-000" | ||
}, | ||
{ | ||
id: "label-001", | ||
name: "label-name-001" | ||
}, | ||
{ | ||
id: "label-002", | ||
name: "label-name-002" | ||
}, | ||
{ | ||
id: "label-003", | ||
name: "label-name-003" | ||
}, | ||
] | ||
|
||
describe('RectLabelsExporter wrapRectLabelIntoYOLO method', () => { | ||
it('should produce correct single label entry given issue #171 example 1', () => { | ||
// given | ||
const labelRect: LabelRect = { | ||
id: "label-rect-000", | ||
labelId: "label-002", | ||
rect: { | ||
x: 444, | ||
y: 998, | ||
width: 90, | ||
height: 82 | ||
}, | ||
isCreatedByAI: false, | ||
status: LabelStatus.ACCEPTED, | ||
suggestedLabel: "label-000" | ||
} | ||
// when | ||
const result = RectLabelsExporter.wrapRectLabelIntoYOLO(labelRect, labelNames, imageSize) | ||
// then | ||
let [classIdx, x, y, width, height] = result.split(" ").map((value: string) => parseFloat(value)) | ||
expect(classIdx).toBe(2) | ||
expect(x + width / 2 <= 1).toBeTruthy() | ||
expect(x - width / 2 >= 0).toBeTruthy() | ||
expect(y + height / 2 <= 1).toBeTruthy() | ||
expect(y - height / 2 >= 0).toBeTruthy() | ||
}) | ||
|
||
it('should produce correct single label entry given issue #171 example 2', () => { | ||
// given | ||
const labelRect: LabelRect = { | ||
id: "label-rect-000", | ||
labelId: "label-002", | ||
rect: { | ||
x: 1828, | ||
y: 710, | ||
width: 92, | ||
height: 104 | ||
}, | ||
isCreatedByAI: false, | ||
status: LabelStatus.ACCEPTED, | ||
suggestedLabel: "label-000" | ||
} | ||
// when | ||
const result = RectLabelsExporter.wrapRectLabelIntoYOLO(labelRect, labelNames, imageSize) | ||
// then | ||
let [classIdx, x, y, width, height] = result.split(" ").map((value: string) => parseFloat(value)) | ||
expect(classIdx).toBe(2) | ||
expect(x + width / 2 <= 1).toBeTruthy() | ||
expect(x - width / 2 >= 0).toBeTruthy() | ||
expect(y + height / 2 <= 1).toBeTruthy() | ||
expect(y - height / 2 >= 0).toBeTruthy() | ||
}) | ||
|
||
it('should produce correct single label entry given issue #171 example 3', () => { | ||
// given | ||
const labelRect: LabelRect = { | ||
id: "label-rect-000", | ||
labelId: "label-002", | ||
rect: { | ||
x: 0, | ||
y: 138, | ||
width: 80, | ||
height: 70 | ||
}, | ||
isCreatedByAI: false, | ||
status: LabelStatus.ACCEPTED, | ||
suggestedLabel: "label-000" | ||
} | ||
// when | ||
const result = RectLabelsExporter.wrapRectLabelIntoYOLO(labelRect, labelNames, imageSize) | ||
// then | ||
let [classIdx, x, y, width, height] = result.split(" ").map((value: string) => parseFloat(value)) | ||
expect(classIdx).toBe(2) | ||
expect(x + width / 2 <= 1).toBeTruthy() | ||
expect(x - width / 2 >= 0).toBeTruthy() | ||
expect(y + height / 2 <= 1).toBeTruthy() | ||
expect(y - height / 2 >= 0).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {NumberUtil} from "../NumberUtil"; | ||
|
||
describe('NumberUtil snapValueToRange method', () => { | ||
it('should return value rounded to the upper bound', () => { | ||
const result: number = NumberUtil.snapValueToRange(1.0000005, 0, 1) | ||
expect(result).toBe(1); | ||
}); | ||
it('should return value rounded to the lower bound', () => { | ||
const result: number = NumberUtil.snapValueToRange(-0.0000005, 0, 1) | ||
expect(result).toBe(0); | ||
}); | ||
it('should return unmodified value', () => { | ||
const result: number = NumberUtil.snapValueToRange(0.5, 0, 1) | ||
expect(result).toBe(0.5); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,43 @@ | ||
import {RectUtil} from "../RectUtil"; | ||
import {IRect} from "../../interfaces/IRect"; | ||
import {IPoint} from "../../interfaces/IPoint"; | ||
import {ISize} from "../../interfaces/ISize"; | ||
|
||
describe('RectUtil getRatio method', () => { | ||
it('should return correct value of rect ratio', () => { | ||
// given | ||
const rect: IRect = {x: 0, y: 0, width: 10, height: 5}; | ||
expect(RectUtil.getRatio(rect)).toBe(2); | ||
// when | ||
const result = RectUtil.getRatio(rect) | ||
// then | ||
expect(result).toBe(2); | ||
}); | ||
|
||
it('should return null', () => { | ||
expect(RectUtil.getRatio(null)).toBe(null); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('RectUtil getCenter method', () => { | ||
it('should return correct center value', () => { | ||
// given | ||
const rect: IRect = {x: 0, y: 0, width: 10, height: 20}; | ||
const expectedResult: IPoint = {x: 5, y: 10}; | ||
// when | ||
const result = RectUtil.getCenter(rect) | ||
// then | ||
expect(result).toMatchObject(expectedResult); | ||
}) | ||
}) | ||
|
||
describe('RectUtil getSize method', () => { | ||
it('should return correct size value', () => { | ||
// given | ||
const rect: IRect = {x: 0, y: 0, width: 10, height: 20}; | ||
const expectedSize: ISize = {width: 10, height: 20}; | ||
// when | ||
const result = RectUtil.getSize(rect) | ||
// then | ||
expect(result).toMatchObject(expectedSize); | ||
}) | ||
}) |