Nim*_*avi 2 python machine-learning neural-network keras tensorflow
我想知道dropout是如何工作的,所以我进入了layers.core模块并将dropout调用从in_train_phase更改为in_test_phase.
我不确定我的更改是否对狡猾的辍学行为负责,所以请耐心等待.
现在将这些更改记在下面的代码片段中:
from keras.models import Model
from keras.layers import Dropout, Input
import numpy as np
import tensorflow as tf
from keras import initializers
x=np.ones((2,2,4))
# x[:,1,:] = 1
print(x)
from keras.layers import Dense
input = Input(name='atom_inputs', shape=(2, 4))
x1 = Dense(4, activation='linear',
kernel_initializer=initializers.Ones(),
bias_initializer='zeros')(input)
x1 = Dropout(0.5, noise_shape=(tf.shape(input)[0], 1, 4))(x1)
fmodel = Model(input, x1)
fmodel.compile(optimizer='sgd', loss='mse')
print(fmodel.predict(x))
Run Code Online (Sandbox Code Playgroud)
将根据辍学率产生不同的预测.
例如:
Dropout(0.2)
[[[5. 5. 5. 5.]
[5. 5. 5. 5.]]
[[5. 0. 5. 0.]
[5. 0. 5. 0.]]]
Dropout(0.5)
[[[0. 0. 8. 8.]
[0. 0. 8. 8.]]
[[8. 0. 8. 8.]
[8. 0. 8. 8.]]]
Run Code Online (Sandbox Code Playgroud)
我哪里错了?丢失是在密集输出层上定义的,因此它应该只影响关闭和打开的神经元,而不是它们各自的值.对?
| 归档时间: |
|
| 查看次数: |
379 次 |
| 最近记录: |