深入探索TensorFlow:从激活函数到计算图优化
1. 常用激活函数介绍
在构建神经网络(NN)模型时,激活函数起着至关重要的作用,它为网络引入非线性,使得网络能够学习复杂的函数。以下是几种常见的激活函数及其在TensorFlow中的应用:
- 双曲正切函数(tanh) :可以使用 tf.keras.activations.tanh() 来实现,示例代码如下:
import numpy as np
import tensorflow as tf
z = np.array([...]) # 假设这里有具体的输入值
print(np.tanh(z))
print(tf.keras.activations.tanh(z))
- 逻辑函数(sigmoid) :在SciPy的
special模块中有expit函数可实现逻辑函数,在TensorFlow中可以使用tf.keras.activations.sigmoid(),示例代码如下:
from scipy.special import expit
print(expit(z))
print(tf.keras.activations.sigmoid(z))
- 修正线性单
TensorFlow核心机制与模型构建
超级会员免费看
订阅专栏 解锁全文
868

被折叠的 条评论
为什么被折叠?



