a bunch of updates.
[jacinto-ai/caffe-jacinto.git] / src / caffe / test / test_simple_conv.cpp
1 // Copyright 2013 Yangqing Jia
3 #include <gtest/gtest.h>
5 #include <cstring>
7 #include "caffe/common.hpp"
8 #include "caffe/blob.hpp"
9 #include "caffe/net.hpp"
10 #include "caffe/proto/caffe.pb.h"
11 #include "caffe/util/io.hpp"
13 #include "caffe/test/test_caffe_main.hpp"
15 namespace caffe {
17 template <typename Dtype>
18 class NetProtoTest : public ::testing::Test {};
20 typedef ::testing::Types<float> Dtypes;
21 TYPED_TEST_CASE(NetProtoTest, Dtypes);
23 TYPED_TEST(NetProtoTest, TestLoadFromText) {
24   NetParameter net_param;
25   ReadProtoFromTextFile("caffe/test/data/simple_conv.prototxt", &net_param);
26   Blob<TypeParam> lena_image;
27   ReadImageToBlob<TypeParam>(string("caffe/test/data/lena_256.jpg"), &lena_image);
28   vector<Blob<TypeParam>*> bottom_vec;
29   bottom_vec.push_back(&lena_image);
31   for (int i = 0; i < lena_image.count(); ++i) {
32     EXPECT_GE(lena_image.cpu_data()[i], 0);
33     EXPECT_LE(lena_image.cpu_data()[i], 1);
34   }
36   // Initialize the network, and then does smoothing
37   Net<TypeParam> caffe_net(net_param, bottom_vec);
38   const vector<Blob<TypeParam>*>& output = caffe_net.Forward(bottom_vec);
39   LOG(ERROR) << "Forward Done.";
40   EXPECT_EQ(output[0]->num(), 1);
41   EXPECT_EQ(output[0]->channels(), 1);
42   EXPECT_EQ(output[0]->height(), 252);
43   EXPECT_EQ(output[0]->width(), 252);
44   for (int i = 0; i < output[0]->count(); ++i) {
45     EXPECT_GE(output[0]->cpu_data()[i], 0);
46     EXPECT_LE(output[0]->cpu_data()[i], 1);
47   }
48   WriteBlobToImage<TypeParam>(string("lena_smoothed.png"), *output[0]);
49 }
52 }  // namespace caffe