Ian*_*uah 7 python machine-learning tensorflow
我有以下功能应该自动编码我的数据。
我的数据可以看成是一张长100宽2的图片,有2个通道(100, 2, 2)
def construct_ae(input_shape):
encoder_input = tf.placeholder(tf.float32, input_shape, name='x')
with tf.variable_scope("encoder"):
flattened = tf.layers.flatten(encoder_input)
e_fc_1 = tf.layers.dense(flattened, units=150, activation=tf.nn.relu)
encoded = tf.layers.dense(e_fc_1, units=75, activation=None)
with tf.variable_scope("decoder"):
d_fc_1 = tf.layers.dense(encoded, 150, activation=tf.nn.relu)
d_fc_2 = tf.layers.dense(d_fc_1, 400, activation=None)
decoded = tf.reshape(d_fc_2, input_shape)
with tf.variable_scope('training'):
loss = tf.losses.mean_squared_error(labels=encoder_input, predictions=decoded)
cost = tf.reduce_mean(loss)
optimizer = tf.train.AdamOptimizer(learning_rate=0.001).minimize(cost)
return optimizer
Run Code Online (Sandbox Code Playgroud)
我遇到了一个问题,我的成本大约是 1.1e9,而且它没有随着时间的推移而减少
我可视化了渐变(删除了代码,因为它只会使事情变得混乱),我认为那里有问题?但我不确定
问题
1) 网络构建中的任何内容看起来不正确吗?
2)数据是否需要在0-1之间归一化?
3)当我尝试将学习率提高到 1 时,有时会遇到 NaN。这是否表明了什么?
4) 我想我可能应该使用 CNN,但我遇到了同样的问题,所以我想我会转移到 FC,因为它可能更容易调试。
5)我想我使用了错误的损失函数,但我真的找不到任何关于正确使用损失的论文。如果有人可以指导我找到一个,我将不胜感激
小智 2
就高启动误差而言;这一切都取决于你的参数的初始化。良好的初始化技术可以让您开始的错误与所需的最小值相差不远。然而,默认的随机或基于零的初始化几乎总是会导致这种情况。