设置模式捕获
SETTINGS['CAPTURE_MODE'] = "sys" # "sys" for windows else "fd"
如注释,Windows系统就采用sys,其他系统采用fd
Experiment实例添加save_git_info参数
ex = Experiment("pymarl", save_git_info=False)
# ValueError: Cannot import git (pip install GitPython).
# Either GitPython or the git executable is missing.
# You can disable git with:
# sacred.Experiment(..., save_git_info=False)
load添加Loader=yaml.FullLoader参数
config_dict = yaml.load(f, Loader=yaml.FullLoader)
collections.Mapping改为collections.abc
from collections.abc import Mapping
......
def recursive_dict_update(d, u):
for k, v in u.items():
if isinstance(v, Mapping):
d[k] = recursive_dict_update(d.get(k, {}), v)
else:
d[k] = v
return d
先变array再变tonser
v=np.array(v)
v = th.as_tensor(v, dtype=dtype, device=self.device)
os.EX_OK
# Making sure framework really exits
try:
OK = os.EX_OK # os.EX_OK旨在linux上面有,windows里面的os库里面没有这个函数
except AttributeError: # On a non-unix system
OK = 0
os._exit(OK) # os._exit(OK)是退出程序,不再执行之后的所有函数
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
if dtype is None:
return self.cpu().numpy()
else:
return self.cpu().numpy().astype(dtype, copy=False)
模型载入注意
checkpoint_path: "" # Load a checkpoint from this path,
# such as "results/models/qmix__2023-12-08_15-44-28",we must use '/' and we can't use Chinese
只能使用正斜杠来表示路径,反斜杠或者r只读都会报错
另外不能使用中文,使用中文会有load的报错。