Added count==0 safeguard to CPU accuracy calculation
authorNoiredd <snowball91b@gmail.com>
Wed, 29 Nov 2017 10:48:29 +0000 (11:48 +0100)
committerNoiredd <snowball91b@gmail.com>
Wed, 29 Nov 2017 10:48:29 +0000 (11:48 +0100)
src/caffe/layers/accuracy_layer.cpp

index 392829e..b6d95b5 100644 (file)
@@ -86,7 +86,7 @@ void AccuracyLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
   }
 
   // LOG(INFO) << "Accuracy: " << accuracy;
-  top[0]->mutable_cpu_data()[0] = accuracy / count;
+  top[0]->mutable_cpu_data()[0] = (count == 0) ? 0 : (accuracy / count);
   if (top.size() > 1) {
     for (int i = 0; i < top[1]->count(); ++i) {
       top[1]->mutable_cpu_data()[i] =