深度学习网络不学习分段线性函数

2024-04-25 00:59:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我考虑一个分段线性的锯齿函数,它在区间[0,1]之间振荡8次,从0到1,也就是说它有8个“齿”。它最初是在this paper中审议的 众所周知,它可以通过深度为6DNN,交替宽度为2和1层来学习,因为这个函数可以写成g(g(g(x),其中g=s(2s(x)-4s(x-0.5)),s=max(0,x)然而,当我使用Keras实现这一想法时,我的DNN学习了一个常数函数。这是什么原因?在这种情况下,梯度下降不会收敛到“正确”参数的根本原因是什么,还是可以采取一些技术措施来训练这个网络? 注意:如果我显著增加层的宽度,我可以很好地训练网络,但这不是我想要的解决方案。我希望围绕这个主题进行讨论:)

我在下面附加了一段代码。不幸的是,不管我做了什么样的学习修改(使用我公认的非常有限的软件库),它都会学习常量函数

#...generate training data points- (x_train, y_train)...

model=Sequential()

num_layers=2*3

for _ in range(num_layers):
   model.add(Dense(2, activation='relu',input_dim=1))
   model.add(Dense(1, activation='relu'))

model.add(Dense(1))


model.compile(loss='mean_squared_error', 
optimizer=tf.keras.optimizers.Adam(learning_rate=0.001), metrics=['accuracy'])

# Train the model
model.fit(
x_train,
y_train,
epochs=15,
batch_size=50,
verbose=0
)
#..Sketch the resulting function ...(the model presented learns constant function no matter what I try)