2016-09-20 2 views
0

입력 드롭 아웃을 사용할 때 LSTM의 성능이 극적으로 떨어지는 TensorFlow에 문제가 있습니다 (70 %에서 <까지 10 %).테스트 결과 손실로 인해 LSTM 성능 오류가 발생했습니다

필자는 교육 중에 input_keep_probability를 0.5로 설정하고 테스트 중에는 1로 설정해야한다고 생각합니다. 이것은 완벽하게 이해할 수 있지만 의도 한대로 작동하지는 않습니다. 교육 도중 테스트 중 드롭 아웃을 설정하면 성능이 향상됩니다 (아래 예제에서는 그렇지 않지만 코드가 적게 들고 요점은 동일합니다).

The accuracy and cost of 3 runs

'최고'라인은 더 드롭 아웃 없으며, 최악의 라인은 [keep_prob의 @ 열차 : 0.5, keep_prob의 @ 시험 : 1]이다 : 0.5, keep_prob의 @ 테스트 및 중심선은 [keep_prob의 @ 열차입니다 : 0.5]. 이것들은 테스트 세트의 비용과 정확성입니다. 그들은 모두 기차 세트에서 예상대로 행동합니다.

다음은 필수적인 코드입니다. 슬프게도 민감한 특성으로 인해 전체 코드 나 데이터 샘플을 게시 할 수는 없지만 자세한 정보가 필요하면 의견을 말하십시오.

lstm_size = 512 
numLayers = 4 
numSteps = 15 

lstm_cell = tf.nn.rnn_cell.LSTMCell(lstm_size, state_is_tuple=True, forget_bias=1) 
lstm_cell = tf.nn.rnn_cell.DropoutWrapper(lstm_cell, input_keep_prob=input_keep_prob) 
cell = tf.nn.rnn_cell.MultiRNNCell([lstm_cell] * numLayers, state_is_tuple=True) 

_inputs = [tf.squeeze(s, [1]) for s in tf.split(1, numSteps, input_data)] 
(outputs, state) = rnn.rnn(cell, _inputs, dtype=tf.float32) 
outputs = tf.pack(outputs) 

#transpose so I can put all timesteps through the softmax at once 
outputsTranspose = tf.reshape(outputs, [-1, lstm_size]) 

softmax_w = tf.get_variable("softmax_w", [lstm_size, nof_classes])       
softmax_b = tf.get_variable("softmax_b", [nof_classes]) 

logits = tf.matmul(outputsTranspose, softmax_w) + softmax_b 

loss = tf.nn.sparse_softmax_cross_entropy_with_logits(logits, targets) 
cost = tf.reduce_mean(loss) 

targetPrediction = tf.argmax(logits, 1) 
accuracy = tf.reduce_mean(tf.cast(tf.equal(targetPrediction, targets), "float")) 

"""Optimizer""" 
with tf.name_scope("Optimizer") as scope: 
    tvars = tf.trainable_variables() 

    #We clip the gradients to prevent explosion 
    grads, _ = tf.clip_by_global_norm(tf.gradients(cost, tvars),maxGradNorm) 
    optimizer = tf.train.AdamOptimizer(learning_rate) 
    gradients = zip(grads, tvars) 
    train_op = optimizer.apply_gradients(gradients) 


with tf.Session() as sess: 
    sess.run(init_op); 

    for i in range(nofBatches * nofEpochs): 
     example_batch, label_batch = sess.run(readTrainDataOp) 

     result = sess.run([train_op, accuracy, trainSummaries], feed_dict = {input_data: example_batch, targets: label_batch, input_keep_prob:trainInputKeepProbability, batch_size_ph:batch_size}) 
     #logging 

     if i % 50 == 0: 
      runTestSet() 
      #relevant part of runTestSet(): 
      #result = sess.run([cost, accuracy], feed_dict = {input_data: testData, targets: testLabels, input_keep_prob:testInputKeepProbability, batch_size_ph:testBatchSize}) 
      #logging 

이 예기치 않은 동작을 만드는 것은 무엇입니까?

편집 : 다음은 입력 샘플이 보이는 모습입니다. 다음 링크를 참조하십시오.

문제는 또한 단지 1 개의 층으로 만 존재합니다.

편집 : I made an example that reproduces the problem. test_samples.npy에 대한 경로를 첫 번째 인수로 사용하고 체크 포인트 경로를 두 번째 인수로 사용하여 Python 스크립트를 실행하면됩니다.

+0

당신이 소량으로 문제를 재현 할 수 있습니까 내 LSTM OM 잘 작동하지 않습니다

0.5 킵 확률값을 테스트하기위한 교육 1.0 킵 확률값에 대한 코드 및 일부 테스트 데이터를 공유 할 수 있습니까? 그러면 문제를보다 효과적으로 디버그하는 데 도움이됩니다. –

+0

이것은 매우 짧습니다 – Julius

+0

느린 응답으로 죄송합니다. 실수로 내 알림을 비활성화했습니다. 질문에 대한 입력 이미지를 추가했습니다. 또한 체크 포인트를 읽고 몇 가지 테스트 샘플에서 드롭 아웃을 사용하거나 사용하지 않고 테스트를 실행하는 약간의 코드를 작성합니다. –

답변

0

해보십시오 input_keep_prob = output_keep_prob = 0.7 중 하나

+1

자세한 내용을 편집하십시오. 코드 전용 및 "시도하십시오"답변은 검색 가능한 콘텐츠가 없으므로 권장하지 않으며 누군가가 "시도해"야하는 이유를 설명하지 않습니다. – abarisone

+0

이 코드 단편은 질문을 해결할 수 있지만 [설명 포함] (http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)은 게시물의 품질을 향상시키는 데 정말로 도움이됩니다. 앞으로 독자의 질문에 답하고 있으며 코드 제안의 이유를 알지 못할 수도 있습니다. –

+0

응답이 늦어서 실수로 알림을 사용 중지했습니다. 그것은 당신이 제안한 매개 변수로 지금 실행 중이고 동일한 일을 다시하고 있습니다. 지금까지의 내 결과는 첫 번째 레이어의 경우 input_keep_prob = 0.8이고 다음 세 레이어의 경우 0.5이고 테스트를 위해서는 [0.8, 1, 1, 1]입니다 (80 % 정확도). 모든 keep_probs가 1.0 인 (동일한 가중치로) 내 testset을 실행하면 결과가 10-15 % 정도 떨어집니다. –

관련 문제