class ConfigTest(BaseConfig):
int = 1
a: str = 'b'
b: float = 3.14
c:
= ConfigTest()
conf 'test.json')
conf.save(= ConfigTest.load_from_json('test.json')
conf2 assert conf == conf2
# remove test.json
'test.json')
os.remove(
= ConfigTest()
conf 'tmp/test.json')
conf.save(= ConfigTest.load_from_json('tmp/test.json')
conf2 assert conf == conf2
'tmp/test.json')
os.remove(
lambda: conf.save('test'), contains="Path must end with `.json`,")
test_fail(lambda: ConfigTest.load_from_json('test.json'), contains="File not found") test_fail(
Base APIs
relax.base.BaseConfig
class relax.base.BaseConfig ()
Base class for all config classes.
relax.base.BaseModule
class relax.base.BaseModule (config, name=None)
Base class for all modules.
class TestModule(BaseModule):
def save(self, path):
self.config.save(Path(path) / 'config.json')
def load_from_path(self, path):
self.config = ConfigTest.load_from_json(Path(path) / 'config.json')
= ConfigTest()
conf = TestModule(conf)
module assert module.name == 'TestModule'
'tmp/module/')
module.save('tmp/module/')
module.load_from_path(assert module.config == conf
'tmp/module/') shutil.rmtree(
relax.base.PredFnMixedin
class relax.base.PredFnMixedin ()
Mixin class for modules that have a pred_fn
method.
relax.base.TrainableMixedin
class relax.base.TrainableMixedin ()
Mixin class for trainable modules.