为什么还是报错:
ValueError Traceback (most recent call last)
Cell In [3], line 1
----> 1 returns = train(train_env, eval_env, model_name=model_name, epoch=1000)
File /tf/notebooks/reinforcement/train.py:75, in train(train_env, eval_env, model_name, epoch, num_iterations, collect_steps_per_iteration, log_interval, eval_interval)
66 def train(train_env, eval_env, model_name, epoch=100, num_iterations=6000, collect_steps_per_iteration=1,
67 log_interval=100, eval_interval=100):
68 # 主训练循环
(...)
71 # log_interval 每隔1000步打印日志
72 # eval_interval 每隔1000步评估模型的性能
74 print("构建网络")
---> 75 agent, iterator, replay_buffer = get_net(train_env)
76 save_train_checkpointer, save_train_policy_saver = get_checkpointer(model_name, agent)
78 print("初始评估")
File /tf/notebooks/reinforcement/learn.py:169, in get_net(train_env)
167 init_collect_steps = 100 # 根据需求调整
168 for _ in range(init_collect_steps):
--> 169 collect_step(train_env, collect_policy, replay_buffer)
171 # 准备数据集和迭代器,用于训练
172 dataset = replay_buffer.as_dataset(num_parallel_calls=3, sample_batch_size=64, num_steps=2).prefetch(3)
File /tf/notebooks/reinforcement/learn.py:106, in collect_step(environment, policy, replay_buffer)
105 def collect_step(environment, policy, replay_buffer):
--> 106 time_step = environment.current_time_step()
107 action_step = policy.action(time_step)
108 next_time_step = environment.step(action_step.action)
File /usr/local/lib/python3.8/dist-packages/tf_agents/environments/tf_environment.py:196, in TFEnvironment.current_time_step(self)
185 def current_time_step(self):
186 """Returns the current TimeStep.
187
188 Returns:
(...)
194 corresponding to observation_spec().
195 """
--> 196 return self._current_time_step()
File /usr/local/lib/python3.8/dist-packages/tf_agents/environments/tf_py_environment.py:237, in TFPyEnvironment._current_time_step(self)
234 return self._execute(_current_time_step_py)
236 with tf.name_scope('current_time_step'):
--> 237 outputs = tf.numpy_function(
238 _isolated_current_time_step_py,
239 [], # No inputs.
240 self._time_step_dtypes,
241 name='current_time_step_py_func')
242 return self._time_step_from_numpy_function_outputs(outputs)
File /usr/local/lib/python3.8/dist-packages/tensorflow/python/util/traceback_utils.py:153, in filter_traceback..error_handler(*args, **kwargs)
151 except Exception as e:
152 filtered_tb = _process_traceback_frames(e.traceback)
--> 153 raise e.with_traceback(filtered_tb) from None
154 finally:
155 del filtered_tb
File /usr/local/lib/python3.8/dist-packages/tf_agents/environments/tf_py_environment.py:234, in TFPyEnvironment._current_time_step.._isolated_current_time_step_py()
233 def _isolated_current_time_step_py():
--> 234 return self._execute(_current_time_step_py)
File /usr/local/lib/python3.8/dist-packages/tf_agents/environments/tf_py_environment.py:211, in TFPyEnvironment._execute(self, fn, *args, **kwargs)
209 def _execute(self, fn, *args, **kwargs):
210 if not self._pool:
--> 211 return fn(*args, **kwargs)
212 return self._pool.apply(fn, args=args, kwds=kwargs)