def post_process(self): if self.svfolder_path: if not os.path.isdir(self.svfolder_path): tools.check_dir(self.svfolder_path) elif self.lab_flag: while (self.query_flag): print('\nThere already exists a folder on ' 'save folder path...') ans = input("choosing action\n" "1:Don't save, 2:overwrite? ") if ans == '1': print('Exit the post_process...') self.save_flag = False self.query_flag = False break elif ans == '2': shutil.rmtree(self.svfolder_path) tools.check_dir(self.svfolder_path) self.query_flag = False break else: self.save_flag = True if self.save_flag: basename = os.path.basename(self.img_path) json_name = tools.replace_extension(basename, 'json') o_json_path = os.path.join(self.svfolder_path, json_name) data.write_json(self.results, o_json_path) restore_ordered_json(o_json_path) else: print('Please set saving folder first !') sys.exit(0)
def main_process(self): base_name = self.metadata[0] inferencer_result = self.input_data[0] self.name_list.append(base_name) if not inferencer_result == []: self.data_list.append(inferencer_result) if len(self.data_list) == 2: # two nearest keyframes start_data = self.data_list[0] start_name = start_data['filename'].split('.')[0] start_index = self.name_list.index(start_name) end_data = self.data_list[1] end_name = end_data['filename'].split('.')[0] end_index = self.name_list.index(end_name) if len(start_data['filename'].split('.')) > 1: file_type = start_data['filename'].split('.')[1] else: file_type = '' for inter_index in range(start_index, end_index): inter_result = self.interpolate_by_track_id( start_index, start_data, end_index, end_data, inter_index) inter_name = tools.replace_extension( self.name_list[inter_index], file_type) inter_result['folder'] = start_data['folder'] inter_result['size'] = start_data['size'] inter_result['filename'] = inter_name self.result_list.append(inter_result) self.name_list = self.name_list[end_index:] self.data_list.pop(0) if len(self.result_list) > 0: self.results = self.result_list[0] self.result_list.pop(0) else: self.results = []
def find_xml_path(self, img_path): tmp_path = img_path.replace('Images', 'Annotations') xml_path = tools.replace_extension(tmp_path, 'xml') err_msg = "\n[ERROR] Folder is not in Labelme input format\n" +\ xml_path + " does not exists!" assert os.path.exists(xml_path), err_msg return xml_path
def post_process(self): if self.sv_flag: tools.check_dir(self.sv_folder) for data in self.output_data: sv_path = os.path.join(self.sv_folder, data["filename"]) sv_path = tools.replace_extension(sv_path, '.json') tools.write_json(data, sv_path) dict_tools.restore_ordered_json(sv_path)
def modify_path(self, result): """ modify folder and filename """ if 'force_folder' in self.param.keys(): result['folder'] = self.param['force_folder'] if 'set_basename_as_filename' in self.param.keys(): if self.param['set_basename_as_filename']: result['filename'] = self.metadata[0] if 'force_extension' in self.param.keys(): result['filename'] = tools.replace_extension( result['filename'], self.param['force_extension']) return result
def post_process(self): output_parent_folder = self.lab_output_folder tools.check_dir(output_parent_folder) output_folder = os.path.join(output_parent_folder, self.__class__.__name__) tools.check_dir(output_folder) if len(self.result_list) > 0: for i in range(len(self.result_list)): result = self.result_list[i] out_filename = os.path.join( output_folder, tools.replace_extension(result['filename'], 'json')) data.write_json(result, out_filename)
def post_process(self): if self.svfolder_path: if not os.path.isdir(self.svfolder_path): tools.check_dir(self.svfolder_path) if self.save_flag: i = 0 for out_meta in self.results['additional_info']: name = out_meta['filename'] out_meta['folder'] = os.path.abspath(self.svfolder_path) json_name = tools.replace_extension(name, 'json') json_path = os.path.join(self.svfolder_path, json_name) img_path = os.path.join(self.svfolder_path, name) data.write_json(out_meta, json_path) image.save_img(self.output_data[i], img_path) i += 1 else: print('Please set saving folder first !') sys.exit(0)
def post_process(self, out_folder_base): output_parent_folder = out_folder_base tools.check_dir(output_parent_folder) output_folder = os.path.join( output_parent_folder, self.__class__.__name__) tools.check_dir(output_folder) if 'filename' in self.results.keys(): # write json if self.param['folder'] == "": self.results['folder'] = os.path.join( output_parent_folder, 'IrConverter') out_filename = os.path.join( output_folder, tools.replace_extension(self.results['filename'], 'json')) tools.write_json(self.results, out_filename) log_info = '[TimeScaleShiftConverter] save json to: {}'.format( out_filename) print(log_info)
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 change_extension(self, path): """ Change extension from jpg to xml. """ return tools.replace_extension(path, 'xml')