操作系统:Ubuntu 16.04
Python 3.5
我试图在增强策略梯度算法程序上实现自定义损失函数,但遇到以下错误:
2018-03-28 23:32:37.766405: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA Traceback (most recent call last): File "reinforce.py", line 199, in <module>
main(sys.argv) File "reinforce.py", line 191, in main
reinforce.train(env) File "reinforce.py", line 57, in train
self.model.compile(loss=custom_loss, optimizer='adam') File "/usr/local/lib/python3.5/dist-packages/keras/models.py", line 824, in compile
**kwargs) File "/usr/local/lib/python3.5/dist-packages/keras/engine/training.py", line 603, in compile
loss = loss or {} File "/home/yuyangw/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 614, in __bool__
raise TypeError("Using a `tf.Tensor` as a Python `bool` is not allowed. " TypeError: Using a `tf.Tensor` as a Python `bool` is not allowed. Use `if t is not None:` instead of `if t:` to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor. Exception ignored in: <bound method BaseSession.__del__ of <tensorflow.python.client.session.Session object at 0x7f2a3346d748>>
错误在于模拟类的训练功能。这里我想实现一个定制的日志函数来执行梯度策略。但我不能使用模型.编译优化定制损失函数。在
代码如下:
^{pr2}$谢谢!!在
Have a look how loss functions are defined in keras.丢失函数必须是具有第一个参数标签和第二个参数预测的函数。 另外,如果您使用Keras,您可能希望使用Keras后端函数构建这样一个自定义的丢失函数(但是使用tf函数应该可以)。在
相关问题 更多 >
编程相关推荐