【发布时间】:2021-08-18 20:35:30
【问题描述】:
我在安装 keras 时遇到问题。以下内容给我带来了太多麻烦(即使在终端上进行更新):
from keras.layers import Dense, Activation
from keras.models import Sequential
因此,我没有使用ann = Sequential() 初始化 ANN,而是使用ann = tf.keras.models.Sequential()。这通过导入:
import tensorflow as tf
from tensorflow import keras
我想使用 LeakyReLU 作为激活函数。然而,这个实现起来似乎有所不同,与其他人的做法相比,keras 文档对我的帮助并没有那么大。
我已经看到需要 ann.add(LeakyReLU(alpha=0.05))。但是,其他参数如 unit 或 input_dim 呢?如何使用我的代码实现这一点?
# Initialising the ANN
ann = tf.keras.models.Sequential()
# Adding the input layer and the first hidden layer
ann.add(tf.keras.layers.Dense(units=32, activation='relu'))
# Adding the second hidden layer
ann.add(tf.keras.layers.Dense(units=32, activation='relu'))
# Adding the output layer
ann.add(tf.keras.layers.Dense(units=1))
【问题讨论】:
标签: python tensorflow keras deep-learning relu