tf.nn.relu()函数是将大于0的数保持不变,小于0的数置为0:
f
(
x
)
=
m
a
x
(
0
,
x
)
f(x) = max(0, x)
f(x)=max(0,x)
relu
(
features,
name=None
)
参数说明:
features - tensor类型,类型为float32, float64, int32, int64, uint8, int16, int8, uint16, half
name - 可选,string类型,运算名称
示例代码:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf
a = tf.constant([1, -2, 0, 4, -5, 6])
b = tf.nn.relu(a)
print(b)
# tf.Tensor([1 0 0 4 0 6], shape=(6,), dtype=int32)