我有一个大类,如下所示:
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
从 这里,我看到,自从我的 load()
不需要自由于在 load
方法,我们不叫自我,然后我们应该使用 staticmethod
. 这是正确的?