张量流概率的贝叶斯神经网络

时间:2019-02-23 11:27:07

标签: python tensorflow deep-learning tensorflow-probability

我是Tensorflow的新手,我正在尝试建立一个具有密集翻转层的贝叶斯神经网络。我的代码如下:

Traceback (most recent call last):
  File "./test_script.py", line 34, in <module>
    dataset[0:training,], labels[0:training], dataset[training:,], labels[training:], layers, epochs
  File "/home/e/bayesian_nn.py", line 34, in train_BNN
    bayesian_nn.compile(train_op, loss=loss, metrics=['accuracy'])
  File "/home/e/.pyenv/versions/kmer_profiling/lib/python3.6/site-packages/tensorflow/python/training/checkpointable/base.py", line 474, in _method_wrapper
    method(self, *args, **kwargs)
  File "/home/e/.pyenv/versions/kmer_profiling/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 405, in compile
    loss = loss or {}
  File "/home/e/.pyenv/versions/kmer_profiling/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 671, 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.

尝试编译网络时出现以下错误:

db.collectionName.find().sort({sortingParameter: 1}).collation({locale: "en_US", numericOrdering: true})

我不知道是什么原因导致此错误...请帮助:)

1 个答案:

答案 0 :(得分:0)

您似乎要传递给loss的{​​{1}}是model.compile,这是不允许的。看documentation,似乎您应该直接传递损失函数(或字符串表示形式),而不是首先实例化它,即tf.Tensor(或损失列表)而不是{{1 }}