machine-learning - 如何保存训练有素的强化学习代理以避免每次都对其进行训练?
问题描述
我尝试使用 pickle 来保存 tained 代理
try:
agent1 = pickle.load(open(model_file_path, 'rb'))
except:
print("An exception occurred")
train_agent(True)
if agent1 == None:
train_agent(True)
human = Human()
human.set_sym(env1.o)
agent1.set_verbose(True)
start_session(agent1, human, Environment(), draw=2)
pickle.dump(agent1, open(model_file_path, 'wb'))
return agent1.prediction
但是保存代理的文件变得非常重,大约 1gb,因此我无法恢复代理
解决方案
HDF5 格式是一种网格格式,非常适合存储多维数字数组。例如:使用 Keras/Tensorflow,您可以非常轻松地保存/加载模型和权重:
# Save the model
model.save('path_to_my_model.h5')
# Recreate the exact same model purely from the file
new_model = keras.models.load_model('path_to_my_model.h5')
# Save weights
model.save_weights('path_to_my_weights.h5')
# Load weights
new_model.load_weights('path_to_my_weights.h5')
推荐阅读
- java - 对 DELETE 语句使用 Room Persistence 注释“RawQuery”
- php - 用 substr_replace 创建一个数组
- java - java中的值类型
- symfony - 2 个字段之间的 Symfony 验证
- kubernetes - 从本地机器访问 Kubernetes API
- node.js - 考虑所有可能性,在猫鼬中的两个值之间进行查询
- java - Java 日历奇怪的行为
- git - git push 和 commit 在 Vscode 中不起作用
- javascript - 当我将某些内容从一个模块返回到另一个模块时,使用 node.js 时出现问题,它显示未定义
- amazon-web-services - 如何使用 aws php sdk 将事件放入自定义总线?