def __init__(self, weights: str): """ :weights : weights file path """ self.weights = weights self.model_path = SavePath.from_str(weights) config = self.model_path.model_name + '_config' set_cfg(config)
def __init__(self, checkpoint_path: Path = "../../checkpoints/yolact_darknet53_9999_120000.pth", config: str = "yolact_darknet53_config", output_dir_path: Optional[Path] = None, use_gpu: bool = True, verbose: bool = False, show_timing_perf: bool = False): """ Args: checkpoint_path (Path): Path to the checkpoint to use. config (str): The config to use output_dir_path (Path, Optional): use_gpu (bool): Controls wether to use a gpu or not verbose (bool): If true then prints information useful for debugging show_timing_perf (bool): If true then prints then time each operation takes """ if output_dir_path: output_dir_path: Path = output_dir_path output_dir_path.mkdir(parents=True, exist_ok=True) self.output_dir_path = output_dir_path self.verbose = verbose self.show_timing_perf = show_timing_perf # Set the yolact config and the default tensor type set_cfg(config) torch.set_default_tensor_type( "torch.cuda.FloatTensor" if use_gpu else "torch.FloatTensor") print("Loading yolact model...", end="\r") self.net = Yolact() self.net.load_weights(str(checkpoint_path)) self.net.eval() clean_print("Yolact model loaded") if use_gpu: self.net = self.net.cuda() # Use the default values self.net.detect.use_fast_nms = True # Whether to use a faster, but not entirely correct version of NMS self.net.detect.use_cross_class_nms = False # Whether compute NMS cross-class or per-class cfg.mask_proto_debug = False # Outputs stuff for scripts/compute_mask.py
print(make_sep(len(all_maps['box']) + 1)) for iou_type in ('box', 'mask'): print( make_row([iou_type] + [ '%.2f' % x if x < 100 else '%.1f' % x for x in all_maps[iou_type].values() ])) print(make_sep(len(all_maps['box']) + 1)) print() if __name__ == '__main__': parse_args() if args.config is not None: set_cfg(args.config) if args.trained_model == 'interrupt': args.trained_model = SavePath.get_interrupt('weights/') elif args.trained_model == 'latest': args.trained_model = SavePath.get_latest('weights/', cfg.name) if args.config is None: model_path = SavePath.from_str(args.trained_model) # TODO: Bad practice? Probably want to do a name lookup instead. args.config = model_path.model_name + '_config' print('Config not specified. Parsed %s from the file name.\n' % args.config) set_cfg(args.config) if args.detect: