我已经在TensorFlow中编写了下面的多层感知器模型,但它不是训练。准确率保持在9%左右,相当于随机猜测,交叉熵保持在2.56左右,变化不大。你知道吗
架构如下:
def create_model(fingerprint_input, model_settings, is_training):
if is_training:
dropout_prob = tf.placeholder(tf.float32, name='dropout_prob')
fingerprint_size = model_settings['fingerprint_size']
label_count = model_settings['label_count']
weights_1 = tf.Variable(tf.truncated_normal([fingerprint_size, 128], stddev=0.001))
weights_2 = tf.Variable(tf.truncated_normal([128, 128], stddev=0.001))
weights_3 = tf.Variable(tf.truncated_normal([128, 128], stddev=0.001))
weights_out = tf.Variable(tf.truncated_normal([128, label_count], stddev=0.001))
bias_1 = tf.Variable(tf.zeros([128]))
bias_2 = tf.Variable(tf.zeros([128]))
bias_3 = tf.Variable(tf.zeros([128]))
bias_out = tf.Variable(tf.zeros([label_count]))
layer_1 = tf.matmul(fingerprint_input, weights_1) + bias_1
layer_1 = tf.nn.relu(layer_1)
layer_2 = tf.matmul(layer_1, weights_2) + bias_2
layer_2 = tf.nn.relu(layer_2)
layer_3 = tf.matmul(layer_2, weights_3) + bias_3
layer_3 = tf.nn.relu(layer_3)
logits = tf.matmul(layer_3, weights_out) + bias_out
if is_training:
return logits, dropout_prob
else:
return logits
它接受输入大小为fingerprint_size
,标签大小为label_count
。它有三个隐藏层,每个层有128个神经元。下面是一个语音数据集的TensorFlow示例,它为其他所有内容提供了一个框架。在文档中,我需要做的就是包含我自己的神经网络架构,我的方法应该定义这些参数并返回logits。你知道吗
当我用相同的输入和输出训练另一个预定义的架构时,神经网络训练。但这不是训练。以下是一个预定义的体系结构:
def create_single_fc_model(fingerprint_input, model_settings, is_training):
if is_training:
dropout_prob = tf.placeholder(tf.float32, name='dropout_prob')
fingerprint_size = model_settings['fingerprint_size']
label_count = model_settings['label_count']
weights = tf.Variable(
tf.truncated_normal([fingerprint_size, label_count], stddev=0.001))
bias = tf.Variable(tf.zeros([label_count]))
logits = tf.matmul(fingerprint_input, weights) + bias
if is_training:
return logits, dropout_prob
else:
return logits
前15000步的学习率为0.001,后3000步的学习率为0.0001。这些是默认值。我也尝试了0.01和0.001,但结果相同。我认为问题出在上面的实现中。你知道吗
你知道吗?你知道吗
提前谢谢!你知道吗
你可能遇到了一个vanishing gradient problem,你的变量被初始化为非常小的值(这是由
stddev
参数控制的),它在一个层上工作,但是在多个层的情况下,它会导致梯度在反向传播过程中消失。 尝试增加随机初始化权重变量的标准差,例如并用非零值初始化偏差,如
相关问题 更多 >
编程相关推荐