저는 최근에 Tensorflow를 선택하여 환경에 적응하기 위해 최선을 다했습니다. 그것은 놀랍습니다. 그러나 tf.contrib.layers.batch_norm을 사용한 일괄 정규화는 약간 까다 롭습니다. 는 지금, 여기 내가 사용하는 기능입니다 :Tensorflow 일괄 정규화 : tf.contrib.layers.batch_norm
def batch_norm(x, phase):
return tf.contrib.layers.batch_norm(x,center = True, scale = True,
is_training = phase, updates_collections = None)
이를 사용하여, 나는 내가 온라인을 발견했습니다 대부분의 문서 (또한 Q & A)를 다음과 다음과 같은 결론에 나를 인도 :
1) is_training은 교육을 위해 True로 설정하고 테스트에는 false로 설정해야합니다. 이것은 의미가 있습니다! 훈련 할 때 나는 수렴했다 (오류 < 1 %, Cifar 10 Dataset).
그러나 테스트 중에 위의 일괄 함수에 대한 인수로 (update collection = None)을 추가하지 않는 한 내 결과가 끔찍합니다 (오류> 90 %). 논증으로 만 테스트하면 예상 한 오류가 발생합니다.
나는 또한 훈련을 위해 다음과 같은 사용 확신 :
update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
with tf.control_dependencies(update_ops): # Ensures, Updating ops will perform before training
with tf.name_scope('Cross_Entropy'):
cross_entropy = tf.reduce_mean( # Implement Cross_Entropy to compute the softmax activation
tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y_conv)) # Cross Entropy: True Output Labels (y_), Softmax output (y_conv)
tf.summary.scalar('cross_entropy', cross_entropy) # Graphical output Cross Entropy
with tf.name_scope('train'):
train_step = tf.train.AdamOptimizer(1e-2).minimize(cross_entropy) # Train Network, Tensorflow minimizes cross_entropy via ADAM Optimization
with tf.name_scope('Train_Results'):
with tf.name_scope('Correct_Prediction'):
correct_prediction = tf.equal(tf.argmax(y_conv, 1), tf.argmax(y_, 1)) # Check if prediction is wrong with tf.equal(CNN_result,True_result)
with tf.name_scope('Accuracy'):
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) # Find the percent accuracy, take mean of correct_prediction outputs
tf.summary.scalar('accuracy', accuracy) # Graphical output Classification Accuracy
이 배치 정규화 매개 변수는 훈련 기간 동안 업데이트되어 있는지 확인해야합니다.
그래서 이것은 update collection = None이 테스트 일 때 배치 정규화 매개 변수를 조정하지 않도록하는 일괄 정규화 함수의 멋진 기본값이라고 생각합니다.
마지막으로 : 테스트 단계에서 일괄 정규화가 켜지고 꺼져있을 때 좋은 결과 (예상 오류)가있는 것이 정상입니까? 위의 배치 표준 함수를 사용하여 잘 훈련 (is_training = True)하고 올바르게 테스트 (is_training = False) 할 수있었습니다. 그러나, 테스트 (is_training = True) 동안 나는 여전히 훌륭한 결과를 얻을 수있었습니다. 이것은 단지 나에게 나쁜 느낌을 준다. 누군가 이것이 왜 이런 일이 일어 났는지 설명 할 수 있습니까? 아니면 전혀 일어나지 않아야한다면?
감사합니다.
정보를 제공해 주셔서 감사합니다. 그러나 작은 배치 크기 (100)를 사용하고 있으며 몇 가지 다른 범위로 변경했습니다. GPU 메모리 제한으로 인해 특히 큰 배치를 사용하지 않았습니다. – Charles
나는 쇠퇴 속도를 바꾸고 당신이 권장하는 것처럼 안정성을 향상시키는 방법을 살펴 보겠습니다. – Charles