问题标签 [tensorflow-agents]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1700 浏览

tensorflow-agents - py_environment 'time_step' 与 'time_step_spec' 不匹配

我通过 tf 代理创建了一个自定义 pyenvironment。但是我无法使用 py_policy.action 验证环境或在其中采取步骤我对 time_step_specs 的例外情况感到困惑

我尝试通过 tf_py_environment.TFPyEnvironment 转换为 tf_py_environment 并成功地使用 tf_policy 采取行动,但我仍然对差异感到困惑。


这是我得到的错误:

----> 1 utils.validate_py_environment(env, episodes=5) 中的 ValueError Traceback (最近一次调用最后一次)

C:\Users\bzhang\AppData\Local\Continuum\anaconda3\lib\site-packages\tf_agents\environments\utils.py 在 validate_py_environment(environment, episodes) 58 raise ValueError( 59 'Given time_step: %r does not match expected time_step_spec: %r' % ---> 60 (time_step, time_step_spec)) 61 62 action = random_policy.action(time_step).action

ValueError: Given time_step: TimeStep(step_type=array(0), reward=array(0., dtype=float32), discount=array(1., dtype=float32), observation=array([[0., 0., 0 .], [0., 0., 0.], [0., 0., 0.]])) 与预期不匹配time_step_spec:TimeStep(step_type=ArraySpec(shape=(), dtype=dtype('int32' ), name='step_type'), reward=ArraySpec(shape=(), dtype=dtype('float32'), name='reward'), discount=BoundedArraySpec(shape=(), dtype=dtype('float32' ), name='discount', minimum=0.0, maximum=1.0),observation=BoundedArraySpec(shape=(3, 3), dtype=dtype('int32'), name='TicTacToe board state spec', minimum=- 1,最大值=1))

0 投票
2 回答
1718 浏览

python - AttributeError:模块“tensorflow.python.ops.linalg.linear_operator_util”没有属性“matmul_with_broadcast”

我正在尝试为 TF-Agents 创建我自己的 PyEnvironment。但是,此错误不断出现:

AttributeError:模块“tensorflow.python.ops.linalg.linear_operator_util”没有属性“matmul_with_broadcast”

我发现这似乎是一个问题tensorflow-probability,但我已经安装了https://github.com/tensorflow/agents/issues/91tensorflow-probability=0.7.0推荐 的版本

我试过重新安装和更新

tensorflow-gpu=2.0.0-beta1 tf-agents-nightly tensorflow-probability=0.7.0

这是一个最小的代码示例:

这是运行此最小示例时的完整错误消息:

0 投票
1 回答
3545 浏览

python - ValueError:找不到匹配的函数来调用从 SavedModel 加载

我正在尝试加载tf-agents我保存的策略

try/except 块的快速解释:最初创建策略时,我可以通过 保存它PolicySaver,但是当我再次加载它以进行另一次训练运行时,它是 a SavedModel,因此不能通过 保存PolicySaver

这似乎工作正常,但现在我想使用这个策略进行自我游戏,所以我self.policy = tf.saved_model.load(policy_path)在我的 AIPlayer 类中加载了这个策略。但是,当我尝试将其用于预测时,它不起作用。这是(测试)代码:

table传递到函数中的包含游戏的状态,并且该函数ts.restart()是从我的自定义 pyEnvironment 中复制的,因此时间步的构造方式与在环境中的方式完全相同。但是,我收到以下错误消息prediction=self.policy.action(timestep)

我究竟做错了什么?真的只是张量名称还是形状问题,我该如何改变它?

任何如何进一步调试的想法都值得赞赏。

0 投票
1 回答
593 浏览

python - Tf-Agents ParallelPyEnvironment 静默失败

我编写了一个自定义环境,因此我可以使用强化学习 (PPO) 和 tf-agents。如果我将我的 env (继承自 py_environment.PyEnvironment)包装在 a 中,这可以正常工作TfPyEnvironment,但如果我尝试将它包装成ParallelPyEnvironment. 我尝试过使用所有关键字参数,ParallelPyEnvironment但代码只是运行到该行,然后什么也没有发生 - 没有异常,程序不会终止等。

这是我初始化环境并展示工作变体的代码eval_env

如果我通过 终止脚本CTRL+C,这就是输出:

由此我得出结论,线程ParallelPyEnvironment试图启动并没有这样做,但由于我对 Python 中的线程不是很有经验,所以我不知道从哪里开始,尤其是如何解决这个问题。当前的训练需要很长时间并且根本没有使用我的 PC 的功能(使用了 3GB 的 32GB RAM,处理器为 3%,GPU 几乎不工作,但 VRAM 已满),因此这应该会显着加快训练时间。

0 投票
1 回答
60 浏览

python - IndexError in random.shuffle when class is executed concurrently

I have created a custom environment for reinforcement learning with tf-agents (not needed to answer this question), which works fine if I instantiate one thread by setting num_parallel_environments to 1, but throws infrequent and seemingly random errors like an IndexError inside random.shuffle(), when I increase num_parallel_environments to 50. Here's the code:

inside train.py

inside my environment, this is run in threads

this is a normal function, imported in every thread class

And here's one of the possible errors:

I suspect this error occurs because the threads are changing the array simultaneously, but I do not see why this would be the case:
Everything happens inside a class instance and the array getFullDeck() is returning is recreated every time the function is called, so there should be no way multiple threads have access to the same reference, right?

0 投票
1 回答
354 浏览

python - tf_Agent 没有正确训练?

此代码应使用 TF-Agents 库在 Cartpole 环境中训练 DQN(Deep Q Networks)代理,但似乎代理没有正确训练。我正在尝试使用 Driver 模块编写一个最小的示例。

我还能够运行 TF-Agents 库中的示例。

代码正在运行,但代理在训练后无法玩游戏。此外,我预计平均回报会随着时间的推移而增加,但会保持不变。

0 投票
1 回答
445 浏览

tensorflow2.0 - 具有输入参数的环境的 Tf 代理并行 Py 环境

假设您有一个具有输入参数的环境:例如,要创建一个您将使用的实例

env_instance = MyEnv(var_1=3, var_2=5, ...)

现在假设您想使用环境“MyEnv”创建一个 parallel_py_environment?由于需要输入参数,所以不能使用

tf_py_environment.TFPyEnvironment(parallel_py_environment.ParallelPyEnvironment([MyEnv]*int(n_envs)))

0 投票
0 回答
102 浏览

python - 如何合并两帧?openai 健身房复古中闪烁的观察问题

我正在使用带有 Atari2600 Asteroids rom 的 openai gym retro 作为我的强化学习项目的基础,但在观察和渲染方面遇到了问题。更准确地说,观察要么只是带有子弹陨石的特工/宇宙飞船。所以每一秒帧都只是宇宙飞船。

我的目标是使用 cv2 将这两个图像组合为一个图像。我有一个基本的观察包装器,它适用于观察,但对于渲染(调用 env.render())它仍然在做最初的问题。

我需要使用另一个包装器来使帧通过记忆真正合并还是有其他解决方案?

0 投票
1 回答
517 浏览

python - tf.agent 策略可以返回所有动作的概率向量吗?

我正在尝试使用 TF-Agent TF-Agent DQN Tutorial训练强化学习代理。在我的应用程序中,我有 1 个操作,其中包含 9 个可能的离散值(标记为 0 到 8)。下面是输出env.action_spec()

我想得到包含训练策略计算的所有动作的概率向量,并在其他应用程序环境中做进一步的处理。但是,该策略仅返回log_probability单个值,而不是所有操作的向量。反正有没有得到概率向量?

dqn_agent.DqnAgent() DQNAgent中,我设置emit_log_probability=True了应该定义的Whether policies emit log probabilities or not.

但是,当我运行时action_step = my_agent.policy.action(time_step),它会返回

我也尝试运行action_distribution = saved_policy.distribution(time_step),它返回

如果 TF.Agent 中没有这样的 API,有没有办法获得这样的概率向量?谢谢。


后续问题:

如果我理解正确,深度 Q 网络应该state从状态中获取每个动作的输入并输出 Q 值。我可以将这个 Q 值向量传递给 softmax 函数并计算相应的概率向量。实际上我已经用我自己定制的 DQN 脚本(没有 TF-Agent)做了这样的计算。那么问题就变成了:如何从TF-Agent返回Q值向量?

0 投票
0 回答
48 浏览

tensorflow - TF keras 层不再可保存?

最近升级到 Tensorflow 2.3 后,我无法保存 TF-agents 层,我得到了这个:

既然ActorDistributionNetwork是 的子类tf.keras.layers.Layer,那么个别 keras 层的自救能力是否被删除了?tensorflow我在 for和 for的发布更改中都找不到任何关于此的内容tf-agents。使用model.save_weights不是很方便tf-agents,因为我必须为自定义代理使用不同的层组合。