本文整理汇总了Python中detectron2.config.get_cfg方法的典型用法代码示例。如果您正苦于以下问题:Python config.get_cfg方法的具体用法?Python config.get_cfg怎么用?Python config.get_cfg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类detectron2.config
的用法示例。
在下文中一共展示了config.get_cfg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_cfg
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
def setup_cfg(config_file, weights_file=None, config_opts=[], confidence_threshold=None, cpu=False):
# load config from file and command-line arguments
cfg = get_cfg()
cfg.merge_from_file(config_file)
cfg.merge_from_list(config_opts)
if confidence_threshold is not None:
# Set score_threshold for builtin models
cfg.MODEL.RETINANET.SCORE_THRESH_TEST = confidence_threshold
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = confidence_threshold
cfg.MODEL.PANOPTIC_FPN.COMBINE.INSTANCES_CONFIDENCE_THRESH = confidence_threshold
if weights_file is not None:
cfg.MODEL.WEIGHTS = weights_file
if cpu or not torch.cuda.is_available():
cfg.MODEL.DEVICE = "cpu"
cfg.freeze()
return cfg
示例2: test_apply_rotated_boxes
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
def test_apply_rotated_boxes(self):
np.random.seed(125)
cfg = get_cfg()
is_train = True
augs = detection_utils.build_augmentation(cfg, is_train)
image = np.random.rand(200, 300)
image, transforms = T.apply_augmentations(augs, image)
image_shape = image.shape[:2] # h, w
assert image_shape == (800, 1200)
annotation = {"bbox": [179, 97, 62, 40, -56]}
boxes = np.array([annotation["bbox"]], dtype=np.float64) # boxes.shape = (1, 5)
transformed_bbox = transforms.apply_rotated_box(boxes)[0]
expected_bbox = np.array([484, 388, 248, 160, 56], dtype=np.float64)
err_msg = "transformed_bbox = {}, expected {}".format(transformed_bbox, expected_bbox)
assert np.allclose(transformed_bbox, expected_bbox), err_msg
示例3: testInitWithCfg
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
def testInitWithCfg(self):
cfg = get_cfg()
cfg.ARG1 = 1
cfg.ARG2 = 2
cfg.ARG3 = 3
_ = _TestClassA(cfg)
_ = _TestClassB(cfg, input_shape="shape")
_ = _TestClassC(cfg, input_shape="shape")
_ = _TestClassD(cfg, input_shape="shape")
_ = _LegacySubClass(cfg, input_shape="shape")
_ = _NewSubClassNewInit(cfg, input_shape="shape")
_ = _LegacySubClassNotCfg(cfg, input_shape="shape")
with self.assertRaises(TypeError):
# disallow forwarding positional args to __init__ since it's prone to errors
_ = _TestClassD(cfg, "shape")
# call with kwargs instead
_ = _TestClassA(cfg=cfg)
_ = _TestClassB(cfg=cfg, input_shape="shape")
_ = _TestClassC(cfg=cfg, input_shape="shape")
_ = _TestClassD(cfg=cfg, input_shape="shape")
_ = _LegacySubClass(cfg=cfg, input_shape="shape")
_ = _NewSubClassNewInit(cfg=cfg, input_shape="shape")
_ = _LegacySubClassNotCfg(config=cfg, input_shape="shape")
示例4: testInitWithCfgOverwrite
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
def testInitWithCfgOverwrite(self):
cfg = get_cfg()
cfg.ARG1 = 1
cfg.ARG2 = 999 # wrong config
with self.assertRaises(AssertionError):
_ = _TestClassA(cfg, arg3=3)
# overwrite arg2 with correct config later:
_ = _TestClassA(cfg, arg2=2, arg3=3)
_ = _TestClassB(cfg, input_shape="shape", arg2=2, arg3=3)
_ = _TestClassC(cfg, input_shape="shape", arg2=2, arg3=3)
_ = _TestClassD(cfg, input_shape="shape", arg2=2, arg3=3)
# call with kwargs cfg=cfg instead
_ = _TestClassA(cfg=cfg, arg2=2, arg3=3)
_ = _TestClassB(cfg=cfg, input_shape="shape", arg2=2, arg3=3)
_ = _TestClassC(cfg=cfg, input_shape="shape", arg2=2, arg3=3)
_ = _TestClassD(cfg=cfg, input_shape="shape", arg2=2, arg3=3)
示例5: _test_model
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
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"]
示例6: test_apply_rotated_boxes
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
def test_apply_rotated_boxes(self):
np.random.seed(125)
cfg = get_cfg()
is_train = True
transform_gen = detection_utils.build_transform_gen(cfg, is_train)
image = np.random.rand(200, 300)
image, transforms = T.apply_transform_gens(transform_gen, image)
image_shape = image.shape[:2] # h, w
assert image_shape == (800, 1200)
annotation = {"bbox": [179, 97, 62, 40, -56]}
boxes = np.array([annotation["bbox"]], dtype=np.float64) # boxes.shape = (1, 5)
transformed_bbox = transforms.apply_rotated_box(boxes)[0]
expected_bbox = np.array([484, 388, 248, 160, 56], dtype=np.float64)
err_msg = "transformed_bbox = {}, expected {}".format(transformed_bbox, expected_bbox)
assert np.allclose(transformed_bbox, expected_bbox), err_msg
示例7: setup_cfg
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
def setup_cfg(args):
# load config from file and command-line arguments
cfg = get_cfg()
cfg.merge_from_file(args.config_file)
cfg.merge_from_list(args.opts)
# Set score_threshold for builtin models
cfg.MODEL.RETINANET.SCORE_THRESH_TEST = args.confidence_threshold
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = args.confidence_threshold
cfg.MODEL.PANOPTIC_FPN.COMBINE.INSTANCES_CONFIDENCE_THRESH = args.confidence_threshold
cfg.freeze()
return cfg
示例8: setup
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
def setup(args):
"""
Create configs and perform basic setups.
"""
cfg = get_cfg()
add_pointrend_config(cfg)
cfg.merge_from_file(args.config_file)
cfg.merge_from_list(args.opts)
cfg.freeze()
default_setup(cfg, args)
return cfg
示例9: setup
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
def setup(args):
"""
Create configs and perform basic setups.
"""
cfg = get_cfg()
add_tridentnet_config(cfg)
cfg.merge_from_file(args.config_file)
cfg.merge_from_list(args.opts)
cfg.freeze()
default_setup(cfg, args)
return cfg
示例10: setup_config
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
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)
cfg.merge_from_list(args.opts)
if opts:
cfg.merge_from_list(opts)
cfg.MODEL.WEIGHTS = model_fpath
cfg.freeze()
return cfg
示例11: _get_model_config
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
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_dataset_category_config(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
示例12: setup
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
def setup(args):
"""
Create configs and perform basic setups.
"""
cfg = get_cfg()
add_tensormask_config(cfg)
cfg.merge_from_file(args.config_file)
cfg.merge_from_list(args.opts)
cfg.freeze()
default_setup(cfg, args)
return cfg
示例13: get_model_zoo
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
def get_model_zoo(config_path):
"""
Like model_zoo.get, but do not load any weights (even pretrained)
"""
cfg_file = model_zoo.get_config_file(config_path)
cfg = get_cfg()
cfg.merge_from_file(cfg_file)
if not torch.cuda.is_available():
cfg.MODEL.DEVICE = "cpu"
return build_model(cfg)
示例14: test_upgrade_downgrade_consistency
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
def test_upgrade_downgrade_consistency(self):
cfg = get_cfg()
# check that custom is preserved
cfg.USER_CUSTOM = 1
down = downgrade_config(cfg, to_version=0)
up = upgrade_config(down)
self.assertTrue(up == cfg)
示例15: test_auto_upgrade
# 需要导入模块: from detectron2 import config [as 别名]
# 或者: from detectron2.config import get_cfg [as 别名]
def test_auto_upgrade(self):
cfg = get_cfg()
latest_ver = cfg.VERSION
cfg.USER_CUSTOM = 1
self._merge_cfg_str(cfg, _V0_CFG)
self.assertEqual(cfg.MODEL.RPN.HEAD_NAME, "TEST")
self.assertEqual(cfg.VERSION, latest_ver)