Exemplo n.º 1
0
 def has_checkpoint(self):
     """
     Returns:
         bool: whether a checkpoint exists in the target directory.
     """
     save_file = os.path.join(self.save_dir, "last_checkpoint")
     return megfile.smart_exists(save_file)
Exemplo n.º 2
0
def convert_to_coco_json(dataset_name, output_file, allow_cached=True):
    """
    Converts dataset into COCO format and saves it to a json file.
    dataset_name must be registered in DatasetCatalog and in cvpods's standard format.
    Args:
        dataset_name:
            reference from the config file to the catalogs
            must be registered in DatasetCatalog and in cvpods's standard format
        output_file: path of json file that will be saved to
        allow_cached: if json file is already present then skip conversion
    """

    # TODO: The dataset or the conversion script *may* change,
    # a checksum would be useful for validating the cached data

    ensure_dir(os.path.dirname(output_file))
    with file_lock(output_file):
        if megfile.smart_exists(output_file) and allow_cached:
            logger.info(
                f"Cached annotations in COCO format already exist: {output_file}"
            )
        else:
            logger.info(
                f"Converting dataset annotations in '{dataset_name}' to COCO format ...)"
            )
            coco_dict = convert_to_coco_dict(dataset_name)

            with megfile.smart_open(output_file, "w") as json_file:
                logger.info(
                    f"Caching annotations in COCO format: {output_file}")
                json.dump(coco_dict, json_file)
Exemplo n.º 3
0
    def exists(path: str) -> bool:
        """
        Checks if there is a resource at the given URI.

        Args:
            path (str): A URI supported by this PathHandler

        Returns:
            bool: true if the path exists
        """
        return megfile.smart_exists(path)
Exemplo n.º 4
0
def get_valid_files(args, cfg, logger):

    if "MODEL.WEIGHTS" in args.opts:
        model_weights = cfg.MODEL.WEIGHTS
        assert megfile.smart_exists(model_weights), "{} not exist!!!".format(
            model_weights)
        return [model_weights]

    file_list = glob.glob(os.path.join(cfg.OUTPUT_DIR, "model_*.pth"))
    assert len(file_list) > 0, "Plz provide model to evaluate"

    file_list = filter_by_iters(file_list, args.start_iter, args.end_iter)
    assert file_list, "No checkpoint valid in {}.".format(cfg.OUTPUT_DIR)
    logger.info("All files below will be tested in order:\n{}".format(
        pformat(file_list)))
    return file_list
Exemplo n.º 5
0
    def inner_func(path, *args, **kwargs):
        cache_dir = get_cache_dir()
        protocol, path_without_protocol = megfile.SmartPath._extract_protocol(
            path)
        local_path = os.path.join(cache_dir, path_without_protocol)
        if megfile.smart_exists(local_path):  # already cached
            return megfile.smart_open(local_path, *args, **kwargs)

        # caching logic
        if protocol == "s3":
            with file_lock(local_path):
                megfile.s3_download(path, local_path)
        elif protocol == "http" or protocol == "https":
            with file_lock(local_path):
                if not isinstance(path, str):
                    path = path.abspath()
                download(path,
                         os.path.dirname(local_path),
                         filename=os.path.basename(local_path))

        return megfile.smart_open(local_path, *args, **kwargs)