diff --git a/pyproject.toml b/pyproject.toml index 13ddec87d5983a97e9a3e8da7970d9d8dfda0215..4132fd5c6691d30e016a25c72df17c0c1771472b 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 f567e736e4054da91ba5aac825e8e82aa911519d..cb3cf322a90543341cf0bdfe1554b8fffc53a679 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 bc1b1db75aca963396dc48a8e1fe28647f734f02..9143828147944b6cc6d26daa1d0e74407a094feb 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())