From: Sergio Date: Thu, 15 May 2014 16:30:07 +0000 (-0700) Subject: Test for Threshold layer X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2fb868cbd32b542f4f77912e92bf105421fb9c0c;p=platform%2Fupstream%2Fcaffe.git Test for Threshold layer --- diff --git a/src/caffe/test/test_threshold_layer.cpp b/src/caffe/test/test_threshold_layer.cpp new file mode 100644 index 0000000..c475f66 --- /dev/null +++ b/src/caffe/test/test_threshold_layer.cpp @@ -0,0 +1,71 @@ +// Copyright 2014 BVLC and contributors. + +#include + +#include "cuda_runtime.h" +#include "gtest/gtest.h" +#include "caffe/blob.hpp" +#include "caffe/common.hpp" +#include "caffe/filler.hpp" +#include "caffe/vision_layers.hpp" +#include "caffe/test/test_gradient_check_util.hpp" + +#include "caffe/test/test_caffe_main.hpp" + +namespace caffe { + +extern cudaDeviceProp CAFFE_TEST_CUDA_PROP; + +template +class ThresholdLayerTest : public ::testing::Test { + protected: + ThresholdLayerTest() + : blob_bottom_(new Blob(2, 3, 6, 5)), + blob_top_(new Blob()) { + Caffe::set_random_seed(1701); + // fill the values + FillerParameter filler_param; + GaussianFiller filler(filler_param); + filler.Fill(this->blob_bottom_); + blob_bottom_vec_.push_back(blob_bottom_); + blob_top_vec_.push_back(blob_top_); + } + virtual ~ThresholdLayerTest() { delete blob_bottom_; delete blob_top_; } + Blob* const blob_bottom_; + Blob* const blob_top_; + vector*> blob_bottom_vec_; + vector*> blob_top_vec_; +}; + +typedef ::testing::Types Dtypes; +TYPED_TEST_CASE(ThresholdLayerTest, Dtypes); + + +TYPED_TEST(ThresholdLayerTest, TestSetup) { + LayerParameter layer_param; + ThresholdLayer layer(layer_param); + layer.SetUp(this->blob_bottom_vec_, &(this->blob_top_vec_)); + EXPECT_EQ(this->blob_top_->num(), this->bottom_top_->num()); + EXPECT_EQ(this->blob_top_->channels(), this->bottom_top_->channels()); + EXPECT_EQ(this->blob_top_->height(), this->bottom_top_->height()); + EXPECT_EQ(this->blob_top_->width(), this->bottom_top_->width()); +} +TYPED_TEST(ThresholdLayerTest, TestCPU) { + LayerParameter layer_param; + Caffe::set_mode(Caffe::CPU); + ThresholdLayer layer(layer_param); + layer.SetUp(this->blob_bottom_vec_, &(this->blob_top_vec_)); + layer.Forward(this->blob_bottom_vec_, &(this->blob_top_vec_)); + // Now, check values + const TypeParam* bottom_data = this->blob_bottom_->cpu_data(); + const TypeParam* top_data = this->blob_top_->cpu_data(); + const TypeParam threshold_ = layer.theshold_; + for (int i = 0; i < this->blob_bottom_->count(); ++i) { + EXPECT_GE(top_data[i], 0.); + EXPECT_LE(top_data[i], 1.); + EXPECT_TRUE(top_data[i] == 0 && bottom_data[i] <= threshold_); + EXPECT_TRUE(top_data[i] == 1 && bottom_data[i] > threshold_); + } +} + +} // namespace caffe