machine-learning - 如何保存经过训练的强化学习代理以避免每次都对其进行训练?

标签 machine-learning model artificial-intelligence reinforcement-learning agent

我尝试使用pickle来保存受污染的代理

   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 Format是一种网格格式,非常适合存储多维数字数组。例如:使用 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')

关于machine-learning - 如何保存经过训练的强化学习代理以避免每次都对其进行训练?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59125756/

相关文章:

javascript - 是否有像15个谜题一样无法解决的8个谜题

artificial-intelligence - 为什么要识别 XOR 算子的反向传播神经网络需要偏置神经元?

php - Zend Framework : Using Models and Views, 最佳实践

asp.net-mvc-3 - 如何在 MVC 中使用存储库模式创建动态的多个局部 View

artificial-intelligence - 适合爬山的启发式机制

algorithm - 最快的近似计数算法

java - 关于model-view-controller的一些疑惑

python - Xgboost DMatrix 初始化减少特征数量

python - Scikit-学习 TransformerMixin : 'numpy.ndarray' object has no attribute 'fit'

python - 如何将数据分为 N 类 + 1 "garbage"类(或省略一些数据)?