【发布时间】:2021-12-31 05:53:00
【问题描述】:
我有一个大类,如下所示:
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
从here,我看到由于我的load()不需要self,因为在load方法中,我们不调用self,那么我们应该使用staticmethod。这是正确的吗?
【问题讨论】:
标签: python deep-learning