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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
import unittest
from dyda_utils import lab_tools
from dyda_utils import image
from dyda.components.yolo_detector import DetectorYOLO
from dyda.components.detector import FaceDetector
from dyda_utils import dict_comparator
class TestDetectorYOLO(unittest.TestCase):
def test_main_process(self):
# pull test data from gitlab
config_url = ("https://gitlab.com/DT42/galaxy42/dt42-dyda/uploads/"
"dbd906035055b99da05308aa927b9f4a/DetectorYOLO.config")
dyda_config = lab_tools.pull_json_from_gitlab(config_url)
ref_url = ("https://gitlab.com/DT42/galaxy42/dt42-dyda/uploads/"
"6ce02b726d96edaf4cb4e4108fb9ba9f/DetectorYOLO_output.json")
ref_data = lab_tools.pull_json_from_gitlab(ref_url)
detector_yolo = DetectorYOLO(dyda_config_path=dyda_config)
input_path = '/home/shared/DT42/test_data/test_detector/dog.jpg'
detector_yolo.input_data = [image.read_img(input_path)]
detector_yolo.run()
tar_data = detector_yolo.results[0]
report = dict_comparator.get_diff(ref_data, tar_data)
self.assertEqual(report['extra_field'], [])
self.assertEqual(report['missing_field'], [])
# Since the filename depending on time stamp, it wont match anyway
for mis_match in report['mismatch_val']:
for tar_key in mis_match['tar_key']:
if tar_key == 'filename':
continue
else:
self.assertEqual(report['mismatch_val'], [])
class TestFaceDetector(unittest.TestCase):
def test_main_process(self):
# test the case with using HOG
dyda_config = {"FaceDetector": {"model": "hog"}}
ref_data = {'filename': '', 'size': {'width': 960, 'height': 544},
'annotations': [{'left': 414, 'right': 637, 'top': 192,
'labinfo': {}, 'bottom': 415,
'type': 'detection', 'id': 0,
'label': 'face', 'confidence': -1.0}],
'folder': ''}
face_detector = FaceDetector(dyda_config_path=dyda_config)
input_url = 'https://gitlab.com/DT42/galaxy42/dt42-dyda/uploads/'\
'a73f92e9b271420d48f70481f56944c4/2019-03-15-111527.jpg'
input_data = lab_tools.pull_img_from_gitlab(input_url)
face_detector.input_data = input_data.copy()
face_detector.run()
tar_data = face_detector.results
report = dict_comparator.get_diff(ref_data, tar_data)
self.assertEqual(report['extra_field'], [])
self.assertEqual(report['missing_field'], [])
# Since the filename depending on time stamp, it wont match anyway
for mis_match in report['mismatch_val']:
for tar_key in mis_match['tar_key']:
if tar_key == 'filename':
continue
else:
self.assertEqual(report['mismatch_val'], [])
# test the case with list input
dyda_config = {"FaceDetector": {"model": "hog"}}
face_detector = FaceDetector(dyda_config_path=dyda_config)
input_data = lab_tools.pull_img_from_gitlab(input_url)
face_detector.input_data = [input_data.copy()]
face_detector.run()
tar_data = face_detector.results
report = dict_comparator.get_diff([ref_data], tar_data)
self.assertEqual(report['extra_field'], [])
self.assertEqual(report['missing_field'], [])
# Since the filename depending on time stamp, it wont match anyway
for mis_match in report['mismatch_val']:
for tar_key in mis_match['tar_key']:
if tar_key == 'filename':
continue
else:
self.assertEqual(report['mismatch_val'], [])
# test the case with using CNN
dyda_config = {"FaceDetector": {"model": "cnn"}}
ref_data = {'annotations': [{'top': 200, 'confidence': -1.0,
'labinfo': {}, 'type': 'detection',
'right': 627, 'bottom': 404,
'label': 'face', 'left': 424, 'id': 0}],
'filename': '', 'folder': '',
'size': {'width': 960, 'height': 544}}
face_detector = FaceDetector(dyda_config_path=dyda_config)
face_detector.input_data = input_data.copy()
face_detector.run()
tar_data = face_detector.results
report = dict_comparator.get_diff(ref_data, tar_data)
self.assertEqual(report['extra_field'], [])
self.assertEqual(report['missing_field'], [])
# Since the filename depending on time stamp, it wont match anyway
for mis_match in report['mismatch_val']:
for tar_key in mis_match['tar_key']:
if tar_key == 'filename':
continue
else:
self.assertEqual(report['mismatch_val'], [])
# test the case with specify upsample_times
dyda_config = {"FaceDetector": {"model": "cnn",
"upsample_times": 3}}
ref_data = {'folder': '', 'filename': '',
'annotations': [{'right': 613, 'top': 165, 'left': 394,
'label': 'face', 'bottom': 384,
'id': 0, 'confidence': -1.0,
'labinfo': {}, 'type': 'detection'}],
'size': {'width': 960, 'height': 544}}
face_detector = FaceDetector(dyda_config_path=dyda_config)
face_detector.input_data = input_data.copy()
face_detector.run()
tar_data = face_detector.results
report = dict_comparator.get_diff(ref_data, tar_data)
self.assertEqual(report['extra_field'], [])
self.assertEqual(report['missing_field'], [])
# Since the filename depending on time stamp, it wont match anyway
for mis_match in report['mismatch_val']:
for tar_key in mis_match['tar_key']:
if tar_key == 'filename':
continue
else:
self.assertEqual(report['mismatch_val'], [])
if __name__ == '__main__':
unittest.main()
|