softmax test
authorYangqing Jia <jiayq84@gmail.com>
Thu, 26 Sep 2013 17:04:25 +0000 (10:04 -0700)
committerYangqing Jia <jiayq84@gmail.com>
Thu, 26 Sep 2013 17:04:25 +0000 (10:04 -0700)
src/caffe/test/test_softmax_layer.cpp

index 253ea8a..fc1c1b7 100644 (file)
@@ -46,6 +46,16 @@ TYPED_TEST(SoftmaxLayerTest, TestForwardCPU) {
   SoftmaxLayer<TypeParam> layer(layer_param);
   layer.SetUp(this->blob_bottom_vec_, &(this->blob_top_vec_));
   layer.Forward(this->blob_bottom_vec_, &(this->blob_top_vec_));
+  // Test sum
+  for (int i = 0; i < this->blob_bottom_->num(); ++i) {
+    TypeParam sum = 0;
+    for (int j = 0; j < this->blob_top_->channels(); ++j) {
+      sum += this->blob_top_->data_at(i, j, 0, 0);
+    }
+    EXPECT_GE(sum, 0.999);
+    EXPECT_LE(sum, 1.001);
+  }
+  // Test exact values
   for (int i = 0; i < this->blob_bottom_->num(); ++i) {
     TypeParam scale = 0;
     for (int j = 0; j < this->blob_bottom_->channels(); ++j) {