def test_update_config(): config = dict() updates = {"a/b": 1.0, "a": 2} update_config(config, updates) ref = {"a": {"b": 1.0}} assert config == ref config = {"a": {"x": 0}} updates = {"a/y": 1} update_config(config, updates) ref = {"a": {"x": 0, "y": 1}} assert config == ref config = {"a": {"x": 0}} updates = {"a/x": 1} update_config(config, updates) ref = {"a": {"x": 1}} assert config == ref config = {"a": {"x": 0}} updates = {"a/0": 1} update_config(config, updates) ref = {"a": {"x": 0, 0: 1}} assert config == ref config = {"a": {"x": 0}} updates = {"a/x/1": 1} update_config(config, updates) ref = {"a": {"x": [None, 1]}} assert config == ref
def test_config_format(): config = dict() updates = {"a/b": 1.0, "x": "{a/b}"} update_config(config, updates) print(config) ref = {"a": {"b": 1.0}, "x": 1.0} assert config == ref
def standalone_eval_csv_file(path_to_csv, callbacks, additional_kwargs={}): """Runs all given callbacks on the data in the :class:`EvalDataFolder` constructed from the given csv.abs Parameters ---------- path_to_csv : str Path to the csv file. callbacks : list(str or Callable) Import commands used to construct the functions applied to the Data extracted from :attr:`path_to_csv`. additional_kwargs : dict Keypath-value pairs added to the config, which is extracted from the ``model_outputs.csv``. Returns ------- The collected outputs of the callbacks. """ import importlib from edflow.main import get_implementations_from_config from edflow.config import update_config import sys sys.path.append(os.getcwd()) # convenience: load implementations from cwd out_data = EvalDataFolder(path_to_csv) config = read_meta_data(path_to_csv) update_config(config, additional_kwargs) dataset_str = config["dataset"] impl = get_implementations_from_config(config, ["dataset"]) in_data = impl["dataset"](config) if not isinstance(callbacks, list): callbacks = [callbacks] outputs = [] for cb in callbacks: if isinstance(cb, str): module = ".".join(cb.split(".")[:-1]) module = importlib.import_module(module) cb = getattr(module, cb.split(".")[-1]) outputs += [ cb(os.path.dirname(path_to_csv), in_data, out_data, config) ] return outputs
parser.add_argument( "-d", "--disable_cache", action="store_true", help="Disable caching dataset instantiation.", ) parser.add_argument( "-b", "--base", nargs="*", metavar="config.yaml", help="Paths to base configs.", default=list(), ) try: sys.path.append(os.getcwd()) opt, unknown = parser.parse_known_args() additional_kwargs = parse_unknown_args(unknown) config = dict() for base_config in opt.base: with open(base_config) as f: config.update(yaml.full_load(f)) update_config(config, additional_kwargs) except SystemExit as e: # This exception will be raised if --help or invalid command line arguments # are used. Currently streamlit prevents the program from exiting normally # so we have to do a hard exit. os._exit(e.code) explore(config, disable_cache=opt.disable_cache)
def standalone_eval_csv_file(path_to_csv, callbacks, additional_kwargs={}, other_config=None): """Runs all given callbacks on the data in the :class:`EvalDataFolder` constructed from the given csv.abs Parameters ---------- path_to_csv : str Path to the csv file. callbacks : dict(name: str or Callable) Import commands used to construct the functions applied to the Data extracted from :attr:`path_to_csv`. additional_kwargs : dict Keypath-value pairs added to the config, which is extracted from the ``model_outputs.csv``. These will overwrite parameters in the original config extracted from the csv. other_config : str Path to additional config used to update the existing one as taken from the ``model_outputs.csv`` . Cannot overwrite the dataset. Only used for callbacks. Parameters in this other config will overwrite the parameters in the original config and those of the commandline arguments. Returns ------- outputs: dict The collected outputs of the callbacks. """ from edflow.main import get_implementations_from_config from edflow.config import update_config import yaml if other_config is not None: with open(other_config, "r") as f: other_config = yaml.full_load(f) else: other_config = {} out_data = EvalDataFolder(path_to_csv) config = read_meta_data(path_to_csv) dataset_str = config["dataset"] impl = get_implementations_from_config(config, ["dataset"]) in_data = impl["dataset"](config) update_config(config, additional_kwargs) config.update(other_config) config_callbacks, callback_kwargs = config2cbdict(config) callbacks.update(config_callbacks) callbacks = load_callbacks(callbacks) root = os.path.dirname(path_to_csv) outputs = apply_callbacks(callbacks, root, in_data, out_data, config, callback_kwargs) return outputs
def standalone_eval_meta_dset(path_to_meta_dir, callbacks, additional_kwargs={}, other_config=None): """Runs all given callbacks on the data in the :class:`EvalDataFolder` constructed from the given csv.abs Parameters ---------- path_to_csv : str Path to the csv file. callbacks : dict(name: str or Callable) Import commands used to construct the functions applied to the Data extracted from :attr:`path_to_csv`. additional_kwargs : dict Keypath-value pairs added to the config, which is extracted from the ``model_outputs.csv``. These will overwrite parameters in the original config extracted from the csv. other_config : str Path to additional config used to update the existing one as taken from the ``model_outputs.csv`` . Cannot overwrite the dataset. Only used for callbacks. Parameters in this other config will overwrite the parameters in the original config and those of the commandline arguments. Returns ------- outputs: dict The collected outputs of the callbacks. """ from edflow.util import get_obj_from_str from edflow.config import update_config import yaml if other_config is not None: with open(other_config, "r") as f: other_config = yaml.full_load(f) else: other_config = {} out_data = MetaDataset(path_to_meta_dir) out_data.expand = True out_data.append_labels = True config = out_data.meta # backwards compatibility if not "datasets" in config: config["datasets"] = {"train": config["dataset"]} if "validation_dataset" in config: config["datasets"]["validation"] = config["validation_dataset"] datasets = dict((split, get_obj_from_str(config["datasets"][split])) for split in config["datasets"]) # TODO fix hardcoded dataset in_data = datasets["validation"](config=config) in_data.expand = True update_config(config, additional_kwargs) config.update(other_config) config_callbacks, callback_kwargs = config2cbdict(config) callbacks.update(config_callbacks) callbacks = load_callbacks(callbacks) root = os.path.dirname(path_to_meta_dir) # TODO handle logging of return values outputs = apply_callbacks(callbacks, root, in_data, out_data, config, callback_kwargs) return outputs