Skip to content

Commit

Permalink
Add functions to load and save configs.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 716167231
  • Loading branch information
jan-matthis authored and copybara-github committed Jan 16, 2025
1 parent c06a789 commit 5d65ceb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions connectomics/jax/models/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

import collections.abc
import inspect
import json
import re
from typing import Any, Type

from absl import logging
from connectomics.common import file
from connectomics.common import import_util
# pylint:disable=unused-import
from connectomics.jax.models import convstack
Expand Down Expand Up @@ -181,3 +183,15 @@ def model_from_dict_config(
default_packages,
**config[cfg_field],
)


def save_config(config: ml_collections.ConfigDict, path: file.PathLike):
"""Saves model config to a file."""
with file.Open(path, 'w') as f:
f.write(config.to_json_best_effort() + '\n')


def load_config(path: file.PathLike) -> ml_collections.ConfigDict:
"""Loads a model config from a file."""
with file.Open(path, 'r') as f:
return ml_collections.ConfigDict(json.loads(f.read()))

0 comments on commit 5d65ceb

Please sign in to comment.