image_through_model #49

Merged
brian merged 75 commits from image_through_model into main 2024-10-20 00:10:27 +02:00
2 changed files with 41 additions and 1 deletions
Showing only changes of commit 96d868a40c - Show all commits
+1 -1
View File
@@ -1 +1 @@
from .get_model_name import get_model_name
from .load_model import load_model
+40
View File
@@ -0,0 +1,40 @@
"""Definition of load_model function."""
import logging
from pathlib import Path
import torch
from minio import Minio
from models import VisualCommunicationModel
from shared.data_store import get_model
from .get_model_name import get_model_name
DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
def load_model(
client: Minio,
) -> VisualCommunicationModel:
"""Instantiate model with weights loaded from latest model saved in
MinIO."""
assert isinstance(client, Minio)
# instantiate model
model = VisualCommunicationModel()
# get model object name
model_name_path = Path('model_name.txt')
model_object_name = get_model_name(path=model_name_path)
logging.info('using model: %s', model_object_name)
# load model from minio
model_checkpoint = get_model(
client=client,
object_name=model_object_name,
)
model.load_state_dict(model_checkpoint)
# clean memory
model_checkpoint.clear()
# move model to selected device
model = model.to(DEVICE)
logging.debug('finished')
return model