pypeline.Model: make deserialize to static

Change the `Model.deserialize` to a static function, which will return
a new instance of the Model.
This commit is contained in:
Giacomo Vercesi
2025-10-08 12:52:25 +02:00
parent c022c51b12
commit f165f99392
11 changed files with 34 additions and 20 deletions
@@ -131,9 +131,8 @@ def build_run_analysis_command(
name=analysis_name,
)
# Load the model
loaded_model: Model = model_ty()
with open(model, "rb") as model_file:
loaded_model.deserialize(model_file.read())
loaded_model = model_ty.deserialize(model_file.read())
logger.debug("Model loaded: `%s`", loaded_model)
@@ -154,9 +154,8 @@ def build_pipe_command(
static_configuration=static_configuration,
)
# Load the model
loaded_model: Model = model_ty()
with open(model, "rb") as model_file:
loaded_model.deserialize(model_file.read())
loaded_model = model_ty.deserialize(model_file.read())
# Load the containers with args form the command line
containers = []
for arg in pipe.arguments:
+1 -2
View File
@@ -117,8 +117,7 @@ def build_analysis_command(
# Load the model
storage_provider = storage_provider_factory(model_path=model)
loaded_model: Model = model_ty()
loaded_model.deserialize(storage_provider.get_model())
loaded_model = model_ty.deserialize(storage_provider.get_model())
logger.debug("Model loaded: `%s`", loaded_model)
@@ -128,8 +128,7 @@ def build_artifact_command(
# Load the model
storage_provider = storage_provider_factory(model_path=model)
loaded_model: Model = model_ty()
loaded_model.deserialize(storage_provider.get_model())
loaded_model = model_ty.deserialize(storage_provider.get_model())
logger.debug("Model loaded: `%s`", loaded_model)
+2 -1
View File
@@ -103,8 +103,9 @@ class Model(ABC):
def serialize(self) -> bytes:
pass
@classmethod
@abstractmethod
def deserialize(self, data: bytes):
def deserialize(cls, data: bytes) -> Model:
pass
@classmethod