TensorFlow,使用`tf.tensor`作为python`BOOL了
raise errors.OperatorNotAllowedInGraphError(
tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: using a `tf.Tensor` as a Python `bool` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function
代码就是这样。
self.target = tf.compat.v1.placeholder(tf.float32, shape = [None], name='Qvals')
self.actions= tf.compat.v1.placeholder(tf.int32, shape = [None], name='Actions')
self.model = AlexNetDuel(self.X, cfg.num_actions, cfg.train_fc)
self.predict = self.model.output
ind = tf.one_hot(self.actions, cfg.num_actions)
pred_Q = tf.reduce_sum(tf.multiply(self.model.output, ind), axis=1)
self.loss = huber_loss(pred_Q, self.target)
self.train = tf.cond(tf.optimizers.Adam(lr=self.lr, beta1=0.9, beta2=0.99).minimize(self.loss, name="train"))
raise errors.OperatorNotAllowedInGraphError(
tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: using a `tf.Tensor` as a Python `bool` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function
Code is this.
self.target = tf.compat.v1.placeholder(tf.float32, shape = [None], name='Qvals')
self.actions= tf.compat.v1.placeholder(tf.int32, shape = [None], name='Actions')
self.model = AlexNetDuel(self.X, cfg.num_actions, cfg.train_fc)
self.predict = self.model.output
ind = tf.one_hot(self.actions, cfg.num_actions)
pred_Q = tf.reduce_sum(tf.multiply(self.model.output, ind), axis=1)
self.loss = huber_loss(pred_Q, self.target)
self.train = tf.cond(tf.optimizers.Adam(lr=self.lr, beta1=0.9, beta2=0.99).minimize(self.loss, name="train"))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论