ValueError: Could not find matching function to call loaded from the SavedModel
ValueError: Could not find matching function to call loaded from the SavedModel
我正在尝试加载通过
保存的tf-agents
政策
try:
PolicySaver(collect_policy).save(model_dir + 'collect_policy')
except TypeError:
tf.saved_model.save(collect_policy, model_dir + 'collect_policy')
try/except块的快速解释:最初创建策略时,我可以通过PolicySaver
保存它,但是当我再次加载它进行另一次训练时运行,它是a SavedModel
因此不能被 PolicySaver
.
保存
这似乎工作正常,但现在我想使用这个策略进行自我播放,所以我在我的 AIPlayer class 中加载了 self.policy = tf.saved_model.load(policy_path)
的策略。但是,当我尝试使用它进行预测时,它不起作用。这是(测试)代码:
def decide(self, table):
state = table.getState()
timestep = ts.restart(np.array([table.getState()], dtype=np.float))
prediction = self.policy.action(timestep)
print(prediction)
传递到函数中的 table
包含游戏状态,并且 ts.restart()
函数是从我的自定义 pyEnvironment 中复制的,因此时间步的构造方式与在环境。但是,我收到 prediction=self.policy.action(timestep)
:
行的以下错误消息
ValueError: Could not find matching function to call loaded from the SavedModel. Got:
Positional arguments (2 total):
* TimeStep(step_type=<tf.Tensor 'time_step:0' shape=() dtype=int32>, reward=<tf.Tensor 'time_step_1:0' shape=() dtype=float32>, discount=<tf.Tensor 'time_step_2:0' shape=() dtype=float32>, observation=<tf.Tensor 'time_step_3:0' shape=(1, 79) dtype=float64>)
* ()
Keyword arguments: {}
Expected these arguments to match one of the following 2 option(s):
Option 1:
Positional arguments (2 total):
* TimeStep(step_type=TensorSpec(shape=(None,), dtype=tf.int32, name='time_step/step_type'), reward=TensorSpec(shape=(None,), dtype=tf.float32, name='time_step/reward'), discount=TensorSpec(shape=(None,), dtype=tf.float32, name='time_step/discount'), observation=TensorSpec(shape=(None,
79), dtype=tf.float64, name='time_step/observation'))
* ()
Keyword arguments: {}
Option 2:
Positional arguments (2 total):
* TimeStep(step_type=TensorSpec(shape=(None,), dtype=tf.int32, name='step_type'), reward=TensorSpec(shape=(None,), dtype=tf.float32, name='reward'), discount=TensorSpec(shape=(None,), dtype=tf.float32, name='discount'), observation=TensorSpec(shape=(None, 79), dtype=tf.float64, name='observation'))
* ()
Keyword arguments: {}
我做错了什么?它真的只是张量名称还是形状问题,我该如何改变它?
如有任何进一步调试的想法,我们将不胜感激。
我通过手动构建 TimeStep 让它工作:
step_type = tf.convert_to_tensor(
[0], dtype=tf.int32, name='step_type')
reward = tf.convert_to_tensor(
[0], dtype=tf.float32, name='reward')
discount = tf.convert_to_tensor(
[1], dtype=tf.float32, name='discount')
observations = tf.convert_to_tensor(
[state], dtype=tf.float64, name='observations')
timestep = ts.TimeStep(step_type, reward, discount, observations)
prediction = self.policy.action(timestep)
我正在尝试加载通过
保存的tf-agents
政策
try:
PolicySaver(collect_policy).save(model_dir + 'collect_policy')
except TypeError:
tf.saved_model.save(collect_policy, model_dir + 'collect_policy')
try/except块的快速解释:最初创建策略时,我可以通过PolicySaver
保存它,但是当我再次加载它进行另一次训练时运行,它是a SavedModel
因此不能被 PolicySaver
.
这似乎工作正常,但现在我想使用这个策略进行自我播放,所以我在我的 AIPlayer class 中加载了 self.policy = tf.saved_model.load(policy_path)
的策略。但是,当我尝试使用它进行预测时,它不起作用。这是(测试)代码:
def decide(self, table):
state = table.getState()
timestep = ts.restart(np.array([table.getState()], dtype=np.float))
prediction = self.policy.action(timestep)
print(prediction)
传递到函数中的 table
包含游戏状态,并且 ts.restart()
函数是从我的自定义 pyEnvironment 中复制的,因此时间步的构造方式与在环境。但是,我收到 prediction=self.policy.action(timestep)
:
ValueError: Could not find matching function to call loaded from the SavedModel. Got:
Positional arguments (2 total):
* TimeStep(step_type=<tf.Tensor 'time_step:0' shape=() dtype=int32>, reward=<tf.Tensor 'time_step_1:0' shape=() dtype=float32>, discount=<tf.Tensor 'time_step_2:0' shape=() dtype=float32>, observation=<tf.Tensor 'time_step_3:0' shape=(1, 79) dtype=float64>)
* ()
Keyword arguments: {}
Expected these arguments to match one of the following 2 option(s):
Option 1:
Positional arguments (2 total):
* TimeStep(step_type=TensorSpec(shape=(None,), dtype=tf.int32, name='time_step/step_type'), reward=TensorSpec(shape=(None,), dtype=tf.float32, name='time_step/reward'), discount=TensorSpec(shape=(None,), dtype=tf.float32, name='time_step/discount'), observation=TensorSpec(shape=(None,
79), dtype=tf.float64, name='time_step/observation'))
* ()
Keyword arguments: {}
Option 2:
Positional arguments (2 total):
* TimeStep(step_type=TensorSpec(shape=(None,), dtype=tf.int32, name='step_type'), reward=TensorSpec(shape=(None,), dtype=tf.float32, name='reward'), discount=TensorSpec(shape=(None,), dtype=tf.float32, name='discount'), observation=TensorSpec(shape=(None, 79), dtype=tf.float64, name='observation'))
* ()
Keyword arguments: {}
我做错了什么?它真的只是张量名称还是形状问题,我该如何改变它?
如有任何进一步调试的想法,我们将不胜感激。
我通过手动构建 TimeStep 让它工作:
step_type = tf.convert_to_tensor(
[0], dtype=tf.int32, name='step_type')
reward = tf.convert_to_tensor(
[0], dtype=tf.float32, name='reward')
discount = tf.convert_to_tensor(
[1], dtype=tf.float32, name='discount')
observations = tf.convert_to_tensor(
[state], dtype=tf.float64, name='observations')
timestep = ts.TimeStep(step_type, reward, discount, observations)
prediction = self.policy.action(timestep)