【问题标题】:Printing model summaries for rllib models打印 rllib 模型的模型摘要
【发布时间】:2022-01-04 03:15:55
【问题描述】:

我在rllib 文档中没有看到任何可以让我在 keras 中打印模型的快速摘要的内容,例如 print(model.summary())。我尝试使用 tf-slim 和

variables = tf.compat.v1.model_variables()
slim.model_analyzer.analyze_vars(variables, print_info=True)

大致了解 tensorflow 模型,但是在模型初始化后没有发现任何变量(插入到 ESTrainer 类 _init 的末尾)。具体来说,我一直在尝试获取进化策略 (ES) 策略的摘要,以验证模型配置的更改是否按预期更新,但我无法让摘要打印工作。

有没有现成的方法呢?苗条有望在这里工作吗?

【问题讨论】:

    标签: python tensorflow rllib


    【解决方案1】:

    训练代理可以返回允许您访问模型的策略:

    agent = ppo.PPOTrainer(config, env=select_env)
    
    policy = agent.get_policy()
    policy.model.base_model.summary() # Prints the model summary
    

    示例输出:

     Layer (type)                   Output Shape         Param #     Connected to                     
    ==================================================================================================
     observations (InputLayer)      [(None, 7)]          0           []                               
                                                                                                      
     fc_1 (Dense)                   (None, 256)          2048        ['observations[0][0]']           
                                                                                                      
     fc_value_1 (Dense)             (None, 256)          2048        ['observations[0][0]']           
                                                                                                      
     fc_2 (Dense)                   (None, 256)          65792       ['fc_1[0][0]']                   
                                                                                                      
     fc_value_2 (Dense)             (None, 256)          65792       ['fc_value_1[0][0]']             
                                                                                                      
     fc_out (Dense)                 (None, 5)            1285        ['fc_2[0][0]']                   
                                                                                                      
     value_out (Dense)              (None, 1)            257         ['fc_value_2[0][0]']             
                                                                                                      
    ==================================================================================================
    Total params: 137,222
    Trainable params: 137,222
    Non-trainable params: 0
    

    【讨论】:

    • 感谢您的回复。如果我使用调音,这可能吗?像这样:'analysis = tune.run(ESTrainer, config=ES_config, stop=stop, checkpoint_freq=5, **extra_kwargs)'。否则我会尝试将我的代码重构为您显示的格式。
    • 我自己没试过,但我注意到 tune.run 的第一个参数可以是一个函数,可以让你实例化一个训练器,从而访问策略:github.com/ray-project/ray/issues/8379#issuecomment-626239029
    • 我会试试的,谢谢。我接受了你的回答,因为这对我来说似乎有很多信息可以让它发挥作用。
    猜你喜欢
    • 2023-01-05
    • 2022-11-20
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    相关资源
    最近更新 更多