def write_back_to_shared_folder(self, labelme_document, aggregate): file_directory = current_user.get_shared_folder_with(aggregate.get_stripID()).get_mount_directory(aggregate.get_dataset_name()) json_file_finder = JsonFileFinder() json_file_size = json_file_finder.json_file_size(file_directory) if json_file_size > 1 or json_file_size == 0: err_msg = "Dataset folder {} can contain atmost one json file, please remove redundant json file or add json file".format(file_directory) raise ValueError(err_msg) json_file_path = json_file_finder.find_json_file_path_in_the(file_directory) JsonHelper.replace_document(json_file_path, labelme_document)
def load_json_string(self, json_file_path): try: return Result.success(JsonHelper.load_json_string(json_file_path)) except ValueError: err_msg = 'Decoding json file contained in folder {} has failed, please check the format of json file'.format( json_file_path) return Result.failure([err_msg])
def load_labelme_json_string(self): import os base_dir = os.path.dirname(__file__) return JsonHelper.load_json_string( base_dir + '/usecaseTestData/machine_labelme.json')
def partial_coco_json_string(): import os base_dir = os.path.dirname(__file__) return JsonHelper.load_json_string(base_dir + '/test_data/parital_coco.json')
def load_json_document(self): defect_code_file_path = "/worksapce/sharedFolder/ATWEX/label_map.json" json_document = JsonHelper.load_json_document(defect_code_file_path) return json_document
def labelme_json_string(): import os base_dir = os.path.dirname(__file__) return JsonHelper.load_json_string(base_dir + '/test_data/machine_labelme.json')
def load_coco_json(): return JsonHelper.load_json_string( "/Users/koushiken/Desktop/formatConverter/CoCo2LabelMeConverter/coco2labelme/multiple_category_coco.json" )
def test_replace_json_document(self, json_file_path): # json_file_path = self.get_labelme_json_path() document_want_to_replace = {"Labels": []} JsonHelper.replace_document(json_file_path, document_want_to_replace) result = JsonHelper.load_json_document(json_file_path) assert document_want_to_replace['Labels'] == result['Labels']
def json_file_path(): json_file_path = get_labelme_json_path() original_document = JsonHelper.load_json_document(json_file_path) yield json_file_path restore_document(json_file_path, original_document)
def restore_document(json_file_path, original_document): JsonHelper.write_json(json_file_path, original_document)
def prepare_label_json_str(self, json_file_directory, label_document_str): JsonHelper.write_json_str( self.label_json_directory(json_file_directory), label_document_str)
def find_json_in_the(self, directory): if self.there_is_no_json_file_contained_in(directory): return "" json_file_path = self.find_json_file_path_in_the(directory) return JsonHelper.load_json_string(json_file_path)