def read_pickle(path, G, G_solver, D_, D_solver):
try:
files = os.listdir(path)
file_list = [int(file.split('_')[-1].split('.')[0]) for file in files]
file_list.sort()
recent_iter = str(file_list[-1])
print(recent_iter, path)
with open(path + "/G_" + recent_iter + ".pkl", "rb") as f:
G.load_state_dict(torch.load(f))
with open(path + "/G_optim_" + recent_iter + ".pkl", "rb") as f:
G_solver.load_state_dict(torch.load(f))
with open(path + "/D_" + recent_iter + ".pkl", "rb") as f:
D_.load_state_dict(torch.load(f))
with open(path + "/D_optim_" + recent_iter + ".pkl", "rb") as f:
D_solver.load_state_dict(torch.load(f))
except Exception as e:
print("fail try read_pickle", e)
评论列表
文章目录