def test_main_process(self): # pull test data from gitlab input_url = 'https://gitlab.com/DT42/galaxy42/dt42-dyda/uploads/'\ 'b7abe78697075dc2e47de5327c9f2de3/cv_classifier_input_list.json' input_list = lab_tools.pull_json_from_gitlab(input_url) output_url = 'https://gitlab.com/DT42/galaxy42/dt42-dyda/uploads/'\ 'c9c8c98992abdf43036eed69d0e5fc3f/cv_output_list.json' output_list = lab_tools.pull_json_from_gitlab(output_url) # initialization classifier_ = ClassifierSimpleCV() classifier_.param["bkg_ref_path"] = '/home/shared/DT42/test_data/'\ 'test_demo_app_with_calibration/ref_bkg.png' image_list = [] for i in range(len(input_list)): image_list.append(image.read_img(input_list[i])) # run classifier classifier_.reset() classifier_.input_data = image_list classifier_.run() # compare results with reference for j in range(len(classifier_.results)): ref_data = output_list[j]['annotations'][0]['label'] tar_data = classifier_.results[j]['annotations'][0]['label'] self.assertEqual(ref_data, tar_data)
def __init__(self, dyda_config_path="", param=None): """Initialization function of dyda component. This is called when an object is created from the class and it allows the class to initialize the attributes of a class. """ super(ClassifierFrameDiff, self).__init__(dyda_config_path=dyda_config_path) class_name = self.__class__.__name__ self.set_param(class_name, param=param) self.check_param_keys(["bkg_path", "thre"]) self.bkg_path = self.param["bkg_path"] self.thre = self.param["thre"] self.sel_min = 0 if "sel_min" in self.param.keys(): self.sel_min = self.param["sel_min"] self.sel_max = -1 if "sel_max" in self.param.keys(): self.sel_max = self.param["sel_max"] self.mean_axis = 1 if "mean_axis" in self.param.keys(): self.mean_axis = self.param["mean_axis"] try: self.bkg_img = image.read_img(self.bkg_path) except: self.logger.error("Fail to read background image %s" % self.bkg_path) sys.exit(0)
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'], [])
def read_image(self, input_data): try: img_data = image.read_img(input_data, log=False) if img_data is None or img_data.shape[0] == 0: print('[dyda] Error: Cannot read %s' % input_data) self.terminate_flag = True return img_data except Exception: traceback.print_exc(file=sys.stdout) self.terminate_flag = True
def set_config(self, input_data, config_data, use_key): self.input_data = input_data self.config_data = config_data self.draw_tool.config_data = config_data self.use_key = use_key self.output_data = self.input_data img_path = self.input_data['img_path'] self.init_img = image.read_img(img_path) img_sz = self.init_img.shape img_sz = np.multiply([img_sz[1], img_sz[0]], 1.0) self.disp_scale = np.divide(img_sz, self.disp_sz)
def __init__(self, dyda_config_path=''): """ __init__ of ClassifierSimpleCV Variables: input_data: a list of image array results: defined by lab_tools.output_pred_classification (dict) """ super(ClassifierSimpleCV, self).__init__(dyda_config_path=dyda_config_path) self.set_param(self.class_name) self.check_param_keys([ "bkg_ref_path", "re_width", "diff_thre", "pixel_num_min", "kernel_size", "iter_num", "seg_margin" ]) self.orig_input_path = "BINARY_INPUT" self.bkg_ref = image.read_img(self.param["bkg_ref_path"])
def test_main_process(self): # pull test data from gitlab config_url = 'https://gitlab.com/DT42/galaxy42/dt42-dyda/uploads/'\ 'abc67841cfb173c22cc13087fdd4d7b2/dyda.config' dyda_config = lab_tools.pull_json_from_gitlab(config_url) input_url = 'https://gitlab.com/DT42/galaxy42/dt42-dyda/uploads/'\ '83db1facaef1bc83efc2b9ed25256ad1/park_input_list.json' input_list = lab_tools.pull_json_from_gitlab(input_url) output_url = 'https://gitlab.com/DT42/galaxy42/dt42-dyda/uploads/'\ '775252d8456257f3364f788556bb553c/park_output_list.json' output_list = lab_tools.pull_json_from_gitlab(output_url) frame_url = 'https://gitlab.com/DT42/galaxy42/dt42-dyda/uploads/'\ 'aa4675a8057f3ae79bf5c0153cdfc69e/'\ 'DeterminatorParkingLotStatus_frame_list.json' frame_list = lab_tools.pull_json_from_gitlab(frame_url) # initialization determinator_ = DeterminatorParkingLotStatus( dyda_config_path=dyda_config) # run determinator for i in range(len(output_list)): # run determinator determinator_.reset() determinator_.input_data.append([image.read_img(frame_list[i])]) determinator_.input_data.append(input_list[i][0]) determinator_.input_data.append(input_list[i][1]) determinator_.input_data.append(input_list[i][2]) determinator_.run() # compare results with reference if not determinator_.results == []: ref_data = output_list[i][0] tar_data = determinator_.results[0] report = dict_comparator.get_diff(ref_data, tar_data) self.assertEqual(report['extra_field'], []) self.assertEqual(report['missing_field'], []) self.assertEqual(report['mismatch_val'], [])
def test_main_process(self): # pull test data from gitlab config_url = 'https://gitlab.com/DT42/galaxy42/dt42-dyda/uploads/'\ '36356e92cad4a608d4c84bba769c0d53/'\ 'dyda.config.DeterminatorCharacter' dyda_config = lab_tools.pull_json_from_gitlab(config_url) input_url = 'https://gitlab.com/DT42/galaxy42/dt42-dyda/uploads/'\ '521feb8def6e63d6e187622b171b7233/input_list.json' input_list = lab_tools.pull_json_from_gitlab(input_url) output_url = 'https://gitlab.com/DT42/galaxy42/dt42-dyda/uploads/'\ '9f25865b93a133bdec459ace16de8ccd/output_list.json' output_list = lab_tools.pull_json_from_gitlab(output_url) # initialization determinator_ = DeterminatorCharacter(dyda_config_path=dyda_config) # run determinator for i in range(len(input_list)): # run determinator determinator_.reset() determinator_.input_data.append(image.read_img(input_list[i])) determinator_.input_data.append( tools.parse_json(tools.replace_extension( input_list[i], 'json'))) determinator_.run() # compare results with reference if not determinator_.results == []: ref_data = output_list[i] tar_data = determinator_.results for j in range(len(ref_data)): for k in range(len(ref_data[j])): report = dict_comparator.get_diff( ref_data[j][k], tar_data[j][k]) self.assertEqual(report['extra_field'], []) self.assertEqual(report['missing_field'], []) self.assertEqual(report['mismatch_val'], [])
def test_main_process(self): # pull test data from gitlab input_url = 'https://gitlab.com/DT42/galaxy42/dt42-dyda/uploads/'\ 'b7abe78697075dc2e47de5327c9f2de3/cv_classifier_input_list.json' input_list = lab_tools.pull_json_from_gitlab(input_url) output_url = 'https://gitlab.com/DT42/galaxy42/dt42-dyda/uploads/'\ '01fd55515c6373ced2541f0aec287f44/ref_bkg.jpg' ref_output = lab_tools.pull_img_from_gitlab(output_url) # initialization learner_ = LearnerSimpleCV() image_list = [] for i in range(len(input_list)): image_list.append(image.read_img(input_list[i])) # run classifier learner_.reset() learner_.input_data = image_list learner_.run() diff = tinycv.l1_norm_diff_cv2(learner_.output_data, ref_output) self.assertEqual(sum(sum(diff)), 0.0)
def test_main_process(): dyda_config = { 'ClassifierTensorRT': { 'model_file': '/home/nvidia/mobilenet_v1_1p0_224.engine', 'label_file': '/home/nvidia/tf_to_trt_image_classification/data/imagenet_labels_1001.txt' } } classifier_trt = ClassifierTensorRT(dyda_config_path=dyda_config) input_path = '/home/nvidia/tf_to_trt_image_classification/data/images/golden_retriever.jpg' classifier_trt.input_data = [image.read_img(input_path)] # tr = tracker.SummaryTracker() for i in range(int(sys.argv[1])): print('Run #{}'.format(i)) s = time.time() classifier_trt.run() tar_data = classifier_trt.results[0] print(tar_data) print('classifier_trt.run() takes: {} ms'.format( (time.time() - s) * 1000))