Example #1
0
 def load(self, target, verbose: bool = False):
     if type(target) is str:
         extension = get_extension_from_path(target)
         if extension == 'yaml':
             check_file_exists(target)
             loaded_data = yaml.load(open(target, 'r'),
                                     Loader=yaml.FullLoader)
         elif extension == 'json':
             check_file_exists(target)
             loaded_data = json.load(open(target, 'r'))
         else:
             logger.error(f"Invalid extension: {extension}")
             logger.error(
                 f"Note that string targets are assumed to be paths.")
             logger.error(f"Valid file extensions: {self.valid_extensions}")
             raise Exception
     elif type(target) is list:
         loaded_data = target
     elif type(target) is dict:
         loaded_data = [target]
     else:
         logger.error(f"Invalid target type: {type(target)}")
         raise Exception
     self.check_valid_config(collection_dict_list=loaded_data)
     self.data = loaded_data
     if verbose:
         logger.good(f"Dataset path config has been loaded successfully.")
Example #2
0
def init_dir(dir_path: str, ask_permission: bool=True):
    dir_name = dir_path.split('/')[-1]
    if not dir_exists(dir_path):
        make_dir(dir_path)
        logger.info("Created directory {}".format(dir_name))
    else:
        delete_all_files_in_dir(dir_path, ask_permission)
        logger.info("All files have been deleted from directory {}".format(dir_name))
    logger.good('Directory {} has been initialized'.format(dir_name))
Example #3
0
 def write_config(self, dest_path: str, verbose: bool = False):
     extension = get_extension_from_path(dest_path)
     if extension == 'yaml':
         yaml.dump(self.data, open(dest_path, 'w'), allow_unicode=True)
     elif extension == 'json':
         json.dump(self.data,
                   open(dest_path, 'w'),
                   indent=2,
                   ensure_ascii=False)
     else:
         logger.error(f"Invalid extension: {extension}")
         logger.error(f"Valid file extensions: {self.valid_extensions}")
         raise Exception
     if verbose:
         logger.good(
             f"Dataset path config written successfully to:\n{dest_path}")
Example #4
0
 def write_split(self, verbose: bool=False):
     for target_dir, target_buffer, unique_key in \
         zip(
             [self.train_dir, self.test_dir, self.val_dir],
             [self.train_buffer, self.test_buffer, self.val_buffer],
             ['train', 'test', 'val']
         ):
             if verbose:
                 logger.info(f"Writting {unique_key}.json from split...")
             ann_dir = f"{target_dir}/{self.target_ann_dir}"
             output_path = f"{ann_dir}/{unique_key}.json"
             writer = COCO_Writer.from_buffer(buffer=target_buffer, output_path=output_path)
             json_dict = writer.build_json_dict(verbose=verbose)
             writer.write_json_dict(json_dict=json_dict, verbose=verbose)
     if verbose:
         logger.good(f"Writing of split annotations is complete.")
from logger import logger
from annotation_utils.coco.structs import COCO_Category

coco_cat = COCO_Category(id=0, supercategory=1.0, name=2)
assert type(coco_cat.supercategory) is str
assert type(coco_cat.name) is str
coco_cat0 = COCO_Category.from_dict(coco_cat.to_dict())
assert type(coco_cat0.supercategory) is str
assert type(coco_cat0.name) is str

coco_cat = COCO_Category(id=0, supercategory='a', name='b')
assert type(coco_cat.supercategory) is str
assert type(coco_cat.name) is str
coco_cat0 = COCO_Category.from_dict(coco_cat.to_dict())
assert type(coco_cat0.supercategory) is str
assert type(coco_cat0.name) is str

logger.good(f'Test passed')
Example #6
0
 def load_combined(self,
                   update_img_paths: bool = True,
                   verbose: bool = False,
                   detailed_verbose: bool = False):
     for i, [img_dir, ann_path
             ] in enumerate(zip(self.img_dir_list, self.ann_path_list)):
         if verbose: logger.info(f"{i}: Parsing {img_dir}, {ann_path}")
         parser = COCO_AnnotationFileParser(annotation_path=ann_path)
         parser.load(verbose=verbose)
         if verbose: logger.good("Annotations Loaded")
         self.add_licenses(ann_key=ann_path,
                           coco_license_handler=parser.licenses,
                           verbose=detailed_verbose)
         if verbose: logger.good(f"Licenses Updated")
         self.add_images(ann_key=ann_path,
                         coco_image_handler=parser.images,
                         img_dir=img_dir,
                         update_img_paths=update_img_paths,
                         verbose=detailed_verbose)
         if verbose: logger.good(f"Images Updated")
         self.add_categories(ann_key=ann_path,
                             coco_category_handler=parser.categories,
                             verbose=detailed_verbose)
         if verbose: logger.good(f"Categories Updated")
         self.add_annotations(ann_key=ann_path,
                              coco_annotation_handler=parser.annotations,
                              verbose=detailed_verbose)
         if verbose: logger.good(f"Annotations Updated")
     if verbose: logger.good(f"Finished Loaded Combined Annotations")
Example #7
0
def test():
    test_func_d()
    logger.good(f'Success!')
Example #8
0
    test_func_d()
    logger.good(f'Success!')


for i in range(3):
    print(f'i: {i}')
    test()

logger.info(f'Class Test')


class TestObj:
    def __init__(self):
        pass

    @bypass_error_in_classmethod(logger.error)
    def method_a(self):
        test_func_c()

    @classmethod
    @bypass_error_in_classmethod(logger.error)
    def classmethod_a(cls):
        test_func_c()


test_obj = TestObj()
test_obj.method_a()
logger.good('Success!')

TestObj.classmethod_a()
logger.good('Success!')