update save and load
This commit is contained in:
+10
-10
@@ -3,10 +3,10 @@ import torch.nn as nn
|
||||
import torch.optim as optim
|
||||
from torch.distributions import Categorical
|
||||
|
||||
from dlgo import encoders
|
||||
from dlgo import goboard
|
||||
from dlgo.agent import Agent
|
||||
from dlgo.agent.helpers import is_point_an_eye
|
||||
from tugo import encoders
|
||||
from tugo import goboard
|
||||
from tugo.agents import Agent
|
||||
from tugo.agents.helpers import is_point_an_eye
|
||||
|
||||
|
||||
class ValueAgent(Agent):
|
||||
@@ -109,7 +109,7 @@ class ValueAgent(Agent):
|
||||
def diagnostics(self):
|
||||
return {'value': self.last_move_value}
|
||||
|
||||
def save(self, filename):
|
||||
def save(self, file_path):
|
||||
torch.save({
|
||||
'model': self.model.state_dict(),
|
||||
'encoder': {
|
||||
@@ -117,11 +117,11 @@ class ValueAgent(Agent):
|
||||
'board_width': self.encoder.board_width,
|
||||
'board_height': self.encoder.board_height,
|
||||
}
|
||||
}, filename)
|
||||
}, file_path)
|
||||
|
||||
@classmethod
|
||||
def load(cls, filename):
|
||||
checkpoint = torch.load(filename)
|
||||
def load(cls, file_path):
|
||||
checkpoint = torch.load(file_path)
|
||||
|
||||
model = Model() # The Model class should be defined appropriately
|
||||
model.load_state_dict(checkpoint['model'])
|
||||
@@ -134,9 +134,9 @@ class ValueAgent(Agent):
|
||||
return cls(model, encoder)
|
||||
|
||||
|
||||
def load_value_agent(filename):
|
||||
def load_value_agent(file_path):
|
||||
# 我假设 Model 类是预先定义好的 PyTorch 模型,你需要根据实际情况替换或实现这个模型。
|
||||
checkpoint = torch.load(filename)
|
||||
checkpoint = torch.load(file_path)
|
||||
|
||||
model = Model() # The Model class should be defined appropriately
|
||||
model.load_state_dict(checkpoint['model'])
|
||||
|
||||
Reference in New Issue
Block a user