Skip to content
Snippets Groups Projects
Commit 143fd096 authored by François  LAURENT's avatar François LAURENT
Browse files

logging

parent 37aa8c6b
No related branches found
No related tags found
1 merge request!7debug-level log messages
...@@ -14,7 +14,7 @@ maggotuba-core = {git = "https://gitlab.pasteur.fr/nyx/MaggotUBA-core", tag = "v ...@@ -14,7 +14,7 @@ maggotuba-core = {git = "https://gitlab.pasteur.fr/nyx/MaggotUBA-core", tag = "v
torch = "^1.11.0" torch = "^1.11.0"
numpy = "^1.19.3" numpy = "^1.19.3"
protobuf = "3.9.2" protobuf = "3.9.2"
taggingbackends = {git = "https://gitlab.pasteur.fr/nyx/TaggingBackends", tag = "v0.15.2"} taggingbackends = {git = "https://gitlab.pasteur.fr/nyx/TaggingBackends", branch = "dev"}
[build-system] [build-system]
requires = ["poetry-core>=1.0.0"] requires = ["poetry-core>=1.0.0"]
......
...@@ -30,6 +30,7 @@ class MaggotModule(nn.Module): ...@@ -30,6 +30,7 @@ class MaggotModule(nn.Module):
@classmethod @classmethod
def load_config(cls, path): def load_config(cls, path):
with open(path, "r") as f: with open(path, "r") as f:
logging.debug(f"loading config file: {path}")
return json.load(f) return json.load(f)
@property @property
...@@ -74,6 +75,7 @@ class MaggotModule(nn.Module): ...@@ -74,6 +75,7 @@ class MaggotModule(nn.Module):
def save_config(self, cfgfile=None): def save_config(self, cfgfile=None):
if cfgfile is None: cfgfile = self.cfgfile if cfgfile is None: cfgfile = self.cfgfile
path = self.path / cfgfile path = self.path / cfgfile
logging.debug(f"saving config to file: {path}")
with open(path, "w") as f: with open(path, "w") as f:
json.dump(self.config, f, indent=2) json.dump(self.config, f, indent=2)
check_permissions(path) check_permissions(path)
...@@ -82,6 +84,7 @@ class MaggotModule(nn.Module): ...@@ -82,6 +84,7 @@ class MaggotModule(nn.Module):
def save_model(self, ptfile=None): def save_model(self, ptfile=None):
if ptfile is None: ptfile = self.ptfile if ptfile is None: ptfile = self.ptfile
path = self.path / ptfile path = self.path / ptfile
logging.debug(f"saving neural network state to file: {path}")
torch.save(self.model.state_dict(), path) torch.save(self.model.state_dict(), path)
check_permissions(path) check_permissions(path)
return path return path
...@@ -176,6 +179,7 @@ class MaggotEncoder(MaggotModule): ...@@ -176,6 +179,7 @@ class MaggotEncoder(MaggotModule):
_reason = None _reason = None
if config.get('load_state', True): if config.get('load_state', True):
try: try:
logging.debug(f"loading neural network state: {path}")
encoder.load_state_dict(torch.load(path)) encoder.load_state_dict(torch.load(path))
except Exception as e: except Exception as e:
_reason = e _reason = e
...@@ -331,9 +335,11 @@ class DeepLinear(nn.Module): ...@@ -331,9 +335,11 @@ class DeepLinear(nn.Module):
return self.layers(x) return self.layers(x)
def load(self, path): def load(self, path):
logging.debug(f"loading neural network state: {path}")
self.load_state_dict(torch.load(path)) self.load_state_dict(torch.load(path))
def save(self, path): def save(self, path):
logging.debug(f"saving neural network state to file: {path}")
torch.save(self.state_dict(), path) torch.save(self.state_dict(), path)
check_permissions(path) check_permissions(path)
......
...@@ -51,6 +51,8 @@ def train_model(backend, layers=1, pretrained_model_instance="default", ...@@ -51,6 +51,8 @@ def train_model(backend, layers=1, pretrained_model_instance="default",
print(f"saving model \"{backend.model_instance}\"") print(f"saving model \"{backend.model_instance}\"")
model.save() model.save()
return dataset, model # for debugging purposes
from taggingbackends.main import main from taggingbackends.main import main
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment