forked from lozuwa/impy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectDetectionDataset_test.py
executable file
·72 lines (62 loc) · 3.14 KB
/
ObjectDetectionDataset_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
Author: Rodrigo Loza
Email: [email protected]
Description: Testing units for ImageLocalizationDataset.
"""
import os
import unittest
from ObjectDetectionDataset import *
from Util import *
class ObjectDetectionDataset_test(unittest.TestCase):
def setUp(self):
self.imgs = os.path.join(os.getcwd(), "tests", "cars_dataset", "images")
self.annts = os.path.join(os.getcwd(), "tests", "cars_dataset", "annotations", "xmls")
self.imda = ObjectDetectionDataset(imagesDirectory = self.imgs,
annotationsDirectory = self.annts,
databaseName = "unit_test")
def tearDown(self):
pass
def test_bounding_boxes(self):
outputDirectory = os.path.join(os.getcwd(), "tests", "cars_dataset", "bounding_boxes")
os.system("rm {}/*".format(outputDirectory))
self.imda.saveBoundingBoxes(outputDirectory = outputDirectory, filterClasses = ["pedestrian", "car"])
def test_reduceDatasetByRois(self):
outputImageDirectory = os.path.join(os.getcwd(), "tests", "cars_dataset", "images_reduced")
outputAnnotationDirectory = os.path.join(os.getcwd(), "tests", "cars_dataset", "annotations_reduced", "xmls")
os.system("rm {}/*".format(outputImageDirectory))
os.system("rm {}/*".format(outputAnnotationDirectory))
# Reduce dataset by grouping ROIs into smaller frames.
self.imda.reduceDatasetByRois(offset = [300, 300],
outputImageDirectory = outputImageDirectory,
outputAnnotationDirectory = outputAnnotationDirectory)
def test_reduceImageDataPointByRoi(self):
outputImageDirectory = os.path.join(os.getcwd(), "tests", "cars_dataset", "images_reduced_single")
outputAnnotationDirectory = os.path.join(os.getcwd(), "tests", "cars_dataset", "annotations_reduced_single", "xmls")
os.system("rm {}/* {}/*".format(outputImageDirectory, outputAnnotationDirectory))
offset = 300
for i in range(1):
for each in os.listdir(self.imgs):
if True:
# Get extension
extension = Util.detect_file_extension(each)
if (extension == None):
raise ValueError("Extension not supported.")
img_name = os.path.join(self.imgs, each)
xml_name = os.path.join(self.annts, each.split(extension)[0]+".xml")
self.imda.reduceImageDataPointByRoi(imagePath = img_name,
annotationPath = xml_name,
offset = [offset, offset],
outputImageDirectory = outputImageDirectory,
outputAnnotationDirectory = outputAnnotationDirectory)
offset += 250
def test_applyDataAugmentation(self):
outputImageDirectory = os.path.join(os.getcwd(), "tests", "cars_dataset", "images_augmented")
outputAnnotationDirectory = os.path.join(os.getcwd(), "tests", "cars_dataset", "annotations_augmented", "xmls")
os.system("rm {}/*".format(outputImageDirectory))
os.system("rm {}/*".format(outputAnnotationDirectory))
aug_file = os.path.join(os.getcwd(), "tests", "cars_dataset", "aug_configuration_cars.json")
self.imda.applyDataAugmentation(configurationFile = aug_file,
outputImageDirectory = outputImageDirectory,
outputAnnotationDirectory = outputAnnotationDirectory)
if __name__ == "__main__":
unittest.main()