def setup_cfg(args): cfg = get_cfg() cfg = add_export_config(cfg) cfg.merge_from_file(args.config_file) cfg.merge_from_list(args.opts) cfg.freeze() return cfg
def _test_model(self, config_path, device="cpu"): # requires extra dependencies from detectron2.export import ( Caffe2Model, add_export_config, export_caffe2_model, ) cfg = get_cfg() cfg.merge_from_file(model_zoo.get_config_file(config_path)) cfg = add_export_config(cfg) cfg.MODEL.DEVICE = device model = build_model(cfg) DetectionCheckpointer(model).load( model_zoo.get_checkpoint_url(config_path)) inputs = [{"image": self._get_test_image()}] c2_model = export_caffe2_model(cfg, model, copy.deepcopy(inputs)) with tempfile.TemporaryDirectory(prefix="detectron2_unittest") as d: c2_model.save_protobuf(d) c2_model.save_graph(os.path.join(d, "test.svg"), inputs=copy.deepcopy(inputs)) c2_model = Caffe2Model.load_protobuf(d) c2_model(inputs)[0]["instances"]
def setup_cfg(args): cfg = get_cfg() # cuda context is initialized before creating dataloader, so we don't fork anymore cfg.DATALOADER.NUM_WORKERS = 0 cfg = add_export_config(cfg) cfg.merge_from_file(args.config_file) cfg.merge_from_list(args.opts) cfg.freeze() return cfg
def setup_cfg(args): cfg = get_cfg() cfg.DATALOADER.NUM_WORKERS = 0 cfg = add_export_config(cfg) add_pointrend_config(cfg) cfg.merge_from_file(args.config_file) cfg.merge_from_list(args.opts) cfg.freeze() return cfg
def _test_model(self, config_path, device="cpu"): # requires extra dependencies from detectron2.export import Caffe2Model, add_export_config, Caffe2Tracer cfg = model_zoo.get_config(config_path) add_export_config(cfg) cfg.MODEL.DEVICE = device model = model_zoo.get(config_path, trained=True, device=device) inputs = [{"image": get_sample_coco_image()}] c2_model = Caffe2Tracer(cfg, model, copy.deepcopy(inputs)).export_caffe2() with tempfile.TemporaryDirectory(prefix="detectron2_unittest") as d: c2_model.save_protobuf(d) c2_model.save_graph(os.path.join(d, "test.svg"), inputs=copy.deepcopy(inputs)) c2_model = Caffe2Model.load_protobuf(d) c2_model(inputs)[0]["instances"]
def setup_cfg(args): cfg = get_cfg() # cuda context is initialized before creating dataloader, so we don't fork anymore cfg.DATALOADER.NUM_WORKERS = 0 cfg = add_export_config(cfg) cfg.merge_from_file(args.config_file) cfg.merge_from_list(args.opts) cfg.freeze() if cfg.MODEL.DEVICE != "cpu": assert TORCH_VERSION >= (1, 5), "PyTorch>=1.5 required for GPU conversion!" return cfg
def _test_model(self, config_path, device="cpu"): cfg = model_zoo.get_config(config_path) add_export_config(cfg) cfg.MODEL.DEVICE = device model = model_zoo.get(config_path, trained=True, device=device) inputs = [{"image": get_sample_coco_image()}] tracer = Caffe2Tracer(cfg, model, copy.deepcopy(inputs)) with tempfile.TemporaryDirectory(prefix="detectron2_unittest") as d: if not os.environ.get("CI"): # This requires onnx, which is not yet available on public CI c2_model = tracer.export_caffe2() c2_model.save_protobuf(d) c2_model.save_graph(os.path.join(d, "test.svg"), inputs=copy.deepcopy(inputs)) c2_model = Caffe2Model.load_protobuf(d) c2_model(inputs)[0]["instances"] ts_model = tracer.export_torchscript() ts_model.save(os.path.join(d, "model.ts"))
def setup_cfg(args): MetadataCatalog.get("custom") cfg = get_cfg() # cuda context is initialized before creating dataloader, so we don't fork anymore cfg.DATALOADER.NUM_WORKERS = 0 cfg = add_export_config(cfg) # cfg.merge_from_file(args.config_file) cfg.merge_from_file( # "../detectron2-master/configs/COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml" # COCO "../../detectron2-master/configs/PascalVOC-Detection/faster_rcnn_R_50_FPN.yaml" # VOC ) cfg.merge_from_list(args.opts) cfg.MODEL.WEIGHTS = "../output/model_final.pth" cfg.DATASETS.TRAIN = ("custom",) cfg.MODEL.ROI_HEADS.NUM_CLASSES = 4 # num classes cfg.freeze() if cfg.MODEL.DEVICE != "cpu": assert TORCH_VERSION >= (1, 5), "PyTorch>=1.5 required for GPU conversion!" return cfg
def setup_cfg(args): DatasetCatalog.clear() MetadataCatalog.clear() keypoint_names = [ "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10" ] keypoint_connection_rules = [[1, 2, [255, 175, 100]], [2, 3, [255, 175, 100]], [3, 4, [255, 175, 100]], [4, 5, [255, 175, 100]], [5, 6, [255, 175, 100]], [6, 7, [255, 175, 100]], [7, 8, [255, 175, 100]], [8, 9, [255, 175, 100]], [9, 10, [255, 175, 100]]] keypoint_flip_map = [('c1', 'c10'), ('c2', 'c9'), ('c3', 'c8'), ('c4', 'c7'), ('c5', 'c6')] register_coco_instances("my_dataset_train", {}, "/content/keypointsl/annotations.json", "/content/VOC2007/JPEGImages") my_md = MetadataCatalog.get("my_dataset_train").set( thing_classes=["table", "r"], keypoint_names=keypoint_names, keypoint_connection_rules=keypoint_connection_rules, keypoint_flip_map=keypoint_flip_map) cfg = get_cfg() # cuda context is initialized before creating dataloader, so we don't fork anymore cfg.DATALOADER.NUM_WORKERS = 0 cfg = add_export_config(cfg) cfg.merge_from_file(args.config_file) cfg.merge_from_list(args.opts) cfg.DATASETS.my_dataset_train = ("my_dataset_train", ) cfg.DATASETS.TEST = ("my_dataset_train", ) cfg.DATASETS.TRAIN = ("my_dataset_train", ) cfg.freeze() if cfg.MODEL.DEVICE != "cpu": assert TORCH_VERSION >= ( 1, 5), "PyTorch>=1.5 required for GPU conversion!" return cfg
metadata.thing_classes = class_ids # metadata.thing_dataset_id_to_contiguous_id = id_map # log.info("metadata: {}".format(metadata)) return metadata name = "hmd" for subset in ["train", "val"]: metadata = load_and_register_dataset(name, subset, appcfg) cfg = config.get_cfg() # cfg.merge_from_file("/codehub/external/detectron2/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml") cfg.DATALOADER.NUM_WORKERS = 0 cfg = add_export_config(cfg) cfg.merge_from_file( model_zoo.get_config_file( "COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")) cfg.DATASETS.TRAIN = ("hmd_train", ) cfg.DATASETS.TEST = ("hmd_val", ) # cfg.DATASETS.TRAIN = ("balloon_train",) # cfg.DATASETS.TEST = ("balloon_val",) cfg.MODEL.ROI_HEADS.NUM_CLASSES = 3 # cfg.MODEL.WEIGHTS = "/codehub/tmp/model_final_balloon.pth" # cfg.MODEL.WEIGHTS = "/codehub/apps/detectron2/temp/model_final_balloon.pth" cfg.MODEL.WEIGHTS = "/codehub/apps/detectron2/release/model_final.pth"