我正在使用 Keras 计算一个简单的序列分类神经网络。我玩了不同的模块,我发现有两种方法可以创建顺序神经网络。
第一种方法是使用 Sequential API。这是我在很多教程/文档中发现的最常见的方式。这是代码:
# Sequential Neural Network using Sequential()
model = Sequential()
model.add(Conv1D(filters=32, kernel_size=3, padding='same', activation='relu', input_shape=(27 , 300,)))
model.add(MaxPooling1D(pool_size=2))
model.add(LSTM(100))
model.add(Dense(len(7, activation='softmax'))
model.summary()
Run Code Online (Sandbox Code Playgroud)
第二种方法是使用模型 API 从“头”开始构建顺序神经网络。这是代码。
# Sequential neural network using Model()
inputs = Input(shape=(27 , 300))
x = Conv1D(filters=32, kernel_size=3, padding='same', activation='relu')(inputs)
x = MaxPooling1D(pool_size=2)(x)
x = LSTM(100)(x)
predictions = Dense(7, activation='softmax')(x)
model = Model(inputs=inputs, outputs=predictions)
model.summary()
Run Code Online (Sandbox Code Playgroud)
我用固定种子(np.random.seed(1337))训练它,训练数据相同,我的输出不同......知道总结中唯一的区别是模型API的第一层输入.
有没有人知道为什么这个神经网络不同?如果没有,为什么我得到不同的结果?
谢谢
python neural-network keras recurrent-neural-network keras-layer