我对tf_agents
中的bug感到困惑。下面的代码即使通过tf_env.action_spec().is_compatible_with(action) is False
也可以正常工作。你知道吗
import tensorflow as tf
import tf_agents.environments.tf_py_environment as tf_py_environment
from tf_agents.environments.tf_py_environment_test import PYEnvironmentMock
py_env = PYEnvironmentMock()
tf_env = tf_py_environment.TFPyEnvironment(py_env)
assert tf_env.batch_size == 1
action = tf.constant(2, shape=(1,), dtype=tf.int32)
assert tf_env.action_spec().is_compatible_with(action) is False
obs = tf_env.step(action)
如果现在更改动作的形状,action
确实与规范兼容,但是调用tf_env.step(action)
action = tf.constant(2, shape=(), dtype=tf.int32)
assert tf_env.action_spec().is_compatible_with(action) # Now ok
obs = tf_env.step(action) # raises an IndexError: list index out of range
引发下面的IndexError
,因为它需要一维操作数组:
Traceback (most recent call last):
File "/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3291, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-42-f3211de6b571>", line 1, in <module>
tf_env.step(action)
File "/lib/python3.6/site-packages/tf_agents/environments/tf_environment.py", line 232, in step
return self._step(action)
File "/lib/python3.6/site-packages/tensorflow/python/autograph/impl/api.py", line 147, in graph_wrapper
return f(*args, **kwargs)
File "/lib/python3.6/site-packages/tf_agents/environments/tf_py_environment.py", line 209, in _step
dim_value = tensor_shape.dimension_value(action.shape[0])
File "/lib/python3.6/site-packages/tensorflow/python/framework/tensor_shape.py", line 837, in __getitem__
return self._dims[key]
IndexError: list index out of range
我的代码有什么问题吗?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐