From cad434b5b449afbf20d644b7a84631408041d337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20=20LAURENT?= <francois.laurent@pasteur.fr> Date: Thu, 5 Oct 2023 13:55:34 +0200 Subject: [PATCH] debug-level log messages --- pyproject.toml | 4 ++-- src/maggotuba/models/modules.py | 8 ++++++++ src/maggotuba/models/trainers.py | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 13ddec8..4132fd5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "MaggotUBA-adapter" -version = "0.16.3" +version = "0.16.4" description = "Interface between MaggotUBA and the Nyx tagging UI" authors = ["François Laurent"] license = "MIT" @@ -14,7 +14,7 @@ maggotuba-core = {git = "https://gitlab.pasteur.fr/nyx/MaggotUBA-core", tag = "v torch = "^1.11.0" numpy = "^1.19.3" protobuf = "3.9.2" -taggingbackends = {git = "https://gitlab.pasteur.fr/nyx/TaggingBackends", tag = "v0.15.2"} +taggingbackends = {git = "https://gitlab.pasteur.fr/nyx/TaggingBackends", tag = "v0.15.3"} [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/src/maggotuba/models/modules.py b/src/maggotuba/models/modules.py index f567e73..cb3cf32 100644 --- a/src/maggotuba/models/modules.py +++ b/src/maggotuba/models/modules.py @@ -1,6 +1,7 @@ import logging import os from pathlib import Path +import numpy as np import torch from torch import nn import json @@ -29,6 +30,7 @@ class MaggotModule(nn.Module): @classmethod def load_config(cls, path): with open(path, "r") as f: + logging.debug(f"loading config file: {path}") return json.load(f) @property @@ -73,6 +75,7 @@ class MaggotModule(nn.Module): def save_config(self, cfgfile=None): if cfgfile is None: cfgfile = self.cfgfile path = self.path / cfgfile + logging.debug(f"saving config to file: {path}") with open(path, "w") as f: json.dump(self.config, f, indent=2) check_permissions(path) @@ -81,6 +84,7 @@ class MaggotModule(nn.Module): def save_model(self, ptfile=None): if ptfile is None: ptfile = self.ptfile path = self.path / ptfile + logging.debug(f"saving neural network state to file: {path}") torch.save(self.model.state_dict(), path) check_permissions(path) return path @@ -179,6 +183,8 @@ class MaggotEncoder(MaggotModule): except Exception as e: _reason = e config['load_state'] = False # for `was_pretrained` to properly work + else: + logging.debug(f"loading neural network state: {path}") else: _reason = '"load_state" is set to false' # if state file not found or config option "load_state" is False, @@ -330,9 +336,11 @@ class DeepLinear(nn.Module): return self.layers(x) def load(self, path): + logging.debug(f"loading neural network state: {path}") self.load_state_dict(torch.load(path)) def save(self, path): + logging.debug(f"saving neural network state to file: {path}") torch.save(self.state_dict(), path) check_permissions(path) diff --git a/src/maggotuba/models/trainers.py b/src/maggotuba/models/trainers.py index bc1b1db..9143828 100644 --- a/src/maggotuba/models/trainers.py +++ b/src/maggotuba/models/trainers.py @@ -386,17 +386,20 @@ def import_pretrained_model(backend, pretrained_model_instance): for file in pretrained_autoencoder_dir.iterdir(): if not file.is_file(): continue + logging.debug(f"copying file: {file}") dst = backend.model_dir() / file.name if file.name.endswith("config.json"): with open(file) as f: config = json.load(f) dir = backend.model_dir().relative_to(backend.project_dir) config["log_dir"] = str(dir) + logging.debug(f"log_dir: \"{config['log_dir']}\"") with open(dst, "w") as f: json.dump(config, f, indent=2) assert config_file is None config_file = dst else: + assert file.name != 'trained_classifier.pt' with open(file, "rb") as i: with open(dst, "wb") as o: o.write(i.read()) -- GitLab