Use config files relative to the base config directory
Summary: Use config files relative to the base config directory, this facilitates testing specific configurations and is better aligned with core Detectron2.
@@ -8,18 +8,32 @@ from detectron2.engine import default_setup
from densepose import add_densepose_config
-_CONFIG_DIR = "configs"
+_BASE_CONFIG_DIR = "configs"
_QUICK_SCHEDULES_CONFIG_SUB_DIR = "quick_schedules"
_CONFIG_FILE_PREFIX = "densepose_"
_CONFIG_FILE_EXT = ".yaml"
-def _get_config_dir():
- return os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", _CONFIG_DIR)
+def _get_base_config_dir():
+ """
+ Return the base directory for configurations
+ """
+ return os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", _BASE_CONFIG_DIR)
+
+
+def _get_quick_schedules_config_dir():
+ """
+ Return the base directory for quick schedules configurations
+ """
+ return os.path.join(_get_base_config_dir(), _QUICK_SCHEDULES_CONFIG_SUB_DIR)
def _collect_config_files(config_dir):
- paths = []
+ """
+ Collect all configuration files (i.e. densepose_*.yaml) directly in the specified directory
+ """
+ start = _get_base_config_dir()
+ results = []
for entry in os.listdir(config_dir):
_, ext = os.path.splitext(entry)
if ext != _CONFIG_FILE_EXT:
@@ -27,31 +41,43 @@ def _collect_config_files(config_dir):
if not entry.startswith(_CONFIG_FILE_PREFIX):
continue
path = os.path.join(config_dir, entry)
- paths.append(path)
- return paths
+ config_file = os.path.relpath(path, start)
+ results.append(config_file)
+ return results
def get_config_files():
- config_dir = _get_config_dir()
- return _collect_config_files(config_dir)
+ """
+ Get all the configuration files (relative to the base configuration directory)
+ """
+ return _collect_config_files(_get_base_config_dir())
def get_quick_schedules_config_files():
- config_dir = _get_config_dir()
- config_dir = os.path.join(config_dir, _QUICK_SCHEDULES_CONFIG_SUB_DIR)
- return _collect_config_files(config_dir)
+ """
+ Get all the quick schedules configuration files (relative to the base configuration directory)
+ """
+ return _collect_config_files(_get_quick_schedules_config_dir())
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)
- cfg.merge_from_file(config_file)
+ 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_file):
+ """
+ Setup the configuration from the specified file (relative to the base configuration directory)
+ """
cfg = _get_model_config(config_file)
cfg.freeze()
default_setup(cfg, {})
