如何对张量进行阈值处理

时间:2017-01-07 16:48:32

标签: python tensorflow

以下是我的代码:

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.

如果张量中的值小于0.5,那么它应该替换为0,否则为1.但它会一直返回错误。

.img-flux img {
    border: 0;
    max-height: 100%;
    max-width: 100%;
    height: auto;
    width: 100%;
    position: relative;
    transition: all 0.3s;
    margin: 0 auto;
    float: none;
    display: block;
    vertical-align: middle;
}

1 个答案:

答案 0 :(得分:4)

在这个简单的例子中,您可以使用

result = tf.cast(result + 0.5, tf.int32)

当if语句变得更复杂时,请考虑使用tf.cond