Mam wielką klasę, która wygląda w następujący sposób:
class Trainer:
def __init__(self, name, age, height, weight):
self.name = name
self.age = age
self.height = height
self.weight = weight
def fit(self, dataloader):
....DO MODEL TRAINING...
self.save(path=xxx)
self.load(path=xxx)
def save(self, path):
self.model.eval()
torch.save(self.model.state_dict(), path)
@staticmethod
def load(path: str):
"""Load a model checkpoint from the given path."""
checkpoint = torch.load(path, map_location=torch.device("cpu"))
return checkpoint
Stąd widzę, że od czasu, jak mój load()
nie potrzebuje w sobie, tak jak w load
metoda, która nie nazywamy siebie, wtedy musimy użyć staticmethod
. To jest poprawnie?