def _get_model_config(config_file): cfg = get_cfg() add_densepose_config(cfg) cfg.merge_from_file(config_file) if not torch.cuda.is_available(): cfg.MODEL_DEVICE = "cpu" return cfg
def setup(args): # Regist own dataset. from detectron2.data.datasets import register_coco_instances folder_data = "/root/detectron2/MADS_data_train_test/80_20_tonghop" # train_data name = "mads_train" json_file = os.path.join(folder_data, "train.json") image_root = os.path.join(folder_data, "train", "images") # test data name_val = "mads_val" json_file_val = os.path.join(folder_data, "val.json") image_root_val = os.path.join(folder_data, "val", "images") # registr register_coco_instances(name, {}, json_file, image_root) register_coco_instances(name_val, {}, json_file_val, image_root_val) cfg = get_cfg() add_densepose_config(cfg) cfg.merge_from_file(args.config_file) cfg.merge_from_list(args.opts) cfg.freeze() default_setup(cfg, args) # Setup logger for "densepose" module setup_logger(output=cfg.OUTPUT_DIR, distributed_rank=comm.get_rank(), name="densepose") return cfg
def __init__(self, config_path, model_path): cfg = get_cfg() add_densepose_config(cfg) cfg.merge_from_file(config_path) cfg.MODEL.WEIGHTS = model_path cfg.MODEL.DEVICE = 'cpu' cfg.freeze() super().__init__(cfg)
def setup_config(config_fpath: str, model_fpath: str, args: dict): cfg = get_cfg() add_densepose_config(cfg) cfg.merge_from_file(config_fpath) cfg.merge_from_list(args['opts']) cfg.MODEL.WEIGHTS = model_fpath cfg.freeze() return cfg
def setup(args): cfg = get_cfg() add_densepose_config(cfg) add_efficientnet_config(cfg) add_roi_shared_config(cfg) cfg.merge_from_file(args.config_file) cfg.merge_from_list(args.opts) cfg.freeze() return cfg
def setup_config(cls: type, config_fpath: str, model_fpath: str, args: argparse.Namespace, opts: List[str]): cfg = get_cfg() add_densepose_config(cfg) cfg.merge_from_file(config_fpath) if opts: cfg.merge_from_list(opts) cfg.MODEL.WEIGHTS = model_fpath cfg.freeze() return cfg
def setup_config(): cfg = get_cfg() add_densepose_config(cfg) cfg.merge_from_file(config_fpath) if opts: cfg.merge_from_list(opts) cfg.MODEL.WEIGHTS = model_fpath cfg.MODEL.DEVICE = 'cpu' cfg.freeze() return cfg
def setup(args): cfg = get_cfg() add_densepose_config(cfg) cfg.merge_from_file(args.config_file) cfg.merge_from_list(args.opts) cfg.freeze() default_setup(cfg, args) # Setup logger for "densepose" module setup_logger(output=cfg.OUTPUT_DIR, distributed_rank=comm.get_rank(), name="densepose") return cfg
def get_model_config(config_file): """ Load and return the configuration from the specified file (relative to the base configuration directory) """ cfg = get_cfg() add_densepose_config(cfg) path = os.path.join(_get_base_config_dir(), config_file) cfg.merge_from_file(path) if not torch.cuda.is_available(): cfg.MODEL_DEVICE = "cpu" return cfg
def setup_config(config_fpath: str, model_fpath: str, opts: List[str]): opts.append("MODEL.ROI_HEADS.SCORE_THRESH_TEST") opts.append(0.8) # Min score cfg = get_cfg() add_densepose_config(cfg) add_hrnet_config(cfg) cfg.merge_from_file(config_fpath) if opts: cfg.merge_from_list(opts) cfg.MODEL.WEIGHTS = model_fpath cfg.freeze() return cfg
def setup(args): cfg = get_cfg() add_densepose_config(cfg) add_efficientnet_config(cfg) add_roi_shared_config(cfg) cfg.merge_from_file(args.config_file) cfg.SOLVER.BASE_LR = 0.001 # Avoid NaNs. Not useful in this script anyway. cfg.merge_from_list(args.opts) cfg.freeze() setup_logger(distributed_rank=comm.get_rank()) return cfg
def prepare_predictor(threshold=0.5): print('prepare predictor...') cfg = get_cfg() add_densepose_config(cfg) model_file = './projects/DensePose/configs/densepose_rcnn_R_101_FPN_DL_s1x.yaml' model_weights = 'https://dl.fbaipublicfiles.com/densepose/densepose_rcnn_R_101_FPN_DL_s1x/165712116/model_final_844d15.pkl' cfg.merge_from_file(model_file) cfg.MODEL.WEIGHTS = model_weights cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = threshold cfg.freeze() predictor = DefaultPredictor(cfg) # print(cfg.dump()) return predictor
def __init__(self, configFile, poseModelFile, accuracyThreshold,numberGpus): cfg = get_cfg() add_densepose_config(cfg) cfg.merge_from_file(configFile) cfg.MODEL.WEIGHTS = poseModelFile cfg.freeze() self.cfg = cfg self.accuracyThreshold = accuracyThreshold mp.set_start_method("spawn", force=True) smp = mp.get_context("spawn") self.queues = [smp.Manager().list(), smp.Manager().list()] self.procs = [] for i in range(numberGpus): cfgProc = cfg.clone() cfgProc.defrost() cfgProc.MODEL.DEVICE = "cuda:" + str(i) self.procs.append(PosePredictorMultiGPU.PredictWorker(cfgProc, self.queues[i], i, self.accuracyThreshold))
def _test_setup(self, config_file): cfg = get_cfg() add_densepose_config(cfg) cfg.merge_from_file(config_file) cfg.freeze() default_setup(cfg, {})
edges_x.append(i) edges_y.append(j) left = min(edges_x) #左边界 right = max(edges_x) #右边界 width = right - left #宽度 bottom = min(edges_y) #底部 top = max(edges_y) #顶部 height = top - bottom #高度 pre1_picture = img[left:left + width, bottom:bottom + height] #图片截取 return pre1_picture #返回图片数据 cfg = get_cfg() add_densepose_config(cfg) cfg.merge_from_file( "~/detectron2-master/projects/Densepose/configs/densepose_rcnn_R_50_FPN_s1x.yaml" ) cfg.MODEL.WEIGHTS = "~/detectron2-master/projects/Densepose/model_final_162be9.pkl" cfg.freeze() predictor = DefaultPredictor(cfg) img = cv2.imread("~/signLanguageAssesment/data/1.jpg") print(img.shape) outputs = predictor(img)["instances"]
def __init__( self, model=MODELS["chimps"], model_cache_dir: Path = Path(".zamba_cache"), download_region=RegionEnum("us"), ): """Create a DensePoseManager object. Parameters ---------- model : dict, optional (default MODELS['chimps']) A dictionary with the densepose model defintion like those defined in MODELS. """ if not DENSEPOSE_AVAILABLE: raise ImportError( "Densepose not installed. See: https://zamba.drivendata.org/docs/stable/models/densepose/#installation" ) # setup configuration for densepose self.cfg = get_cfg() add_densepose_config(self.cfg) self.cfg.merge_from_file(model["config"]) if not (model_cache_dir / model["weights"]).exists(): model_cache_dir.mkdir(parents=True, exist_ok=True) self.cfg.MODEL.WEIGHTS = download_weights(model["weights"], model_cache_dir, download_region) # automatically use CPU if no cuda available if not torch.cuda.is_available(): self.cfg.MODEL.DEVICE = "cpu" self.cfg.freeze() logging.getLogger("fvcore").setLevel( "CRITICAL") # silence noisy detectron2 logging # set up predictor with the configuration self.predictor = DefaultPredictor(self.cfg) # we have a specific texture atlas for chimps with relevant regions # labeled that we can use instead of the default segmentation self.visualizer = model["viz_class"]( self.cfg, device=self.cfg.MODEL.DEVICE, **model.get("viz_class_kwargs", {}), ) # set up utilities for use with visualizer self.vis_extractor = create_extractor(self.visualizer) self.vis_embedder = build_densepose_embedder(self.cfg) self.vis_class_to_mesh_name = get_class_to_mesh_name_mapping(self.cfg) self.vis_mesh_vertex_embeddings = { mesh_name: self.vis_embedder(mesh_name).to(self.cfg.MODEL.DEVICE) for mesh_name in self.vis_class_to_mesh_name.values() if self.vis_embedder.has_embeddings(mesh_name) } if "anatomy_color_mapping" in model: self.anatomy_color_mapping = pd.read_csv( model["anatomy_color_mapping"], index_col=0) else: self.anatomy_color_mapping = None