unittest_function.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Intel Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <string>
18 #include <vector>
19 
20 #include <gtest/gtest.h>
21 #include <opencv2/highgui.hpp>
22 #include <ros/package.h>
23 
25 
26 TEST(UnitTestFunction, testLibraryFunctions)
27 {
28  std::vector<std::string> caffe_dirs = { "AlexNet", "GoogLeNet", "SqueezeNet", "SSD_MobileNet", "TinyYolo" };
29  std::vector<std::string> tf_dirs = { "inception_v1", "inception_v2", "inception_v3", "inception_v4", "mobilenets" };
30  std::vector<std::string> caffe_nets = { "alexnet", "googlenet", "squeezenet", "mobilenetssd", "tinyyolo_v1" };
31  std::vector<std::string> tf_nets = { "inception_v1", "inception_v2", "inception_v3", "inception_v4", "mobilenet" };
32  std::vector<std::string> caffe_categories = { "imagenet1000.txt", "imagenet1000.txt", "imagenet1000.txt", "voc21.txt",
33  "voc20.txt" };
34  std::vector<std::vector<float>> caffe_means = { { 104.0069879317889, 116.66876761696767, 122.6789143406786 },
35  { 104.0069879317889, 116.66876761696767, 122.6789143406786 },
36  { 104.0069879317889, 116.66876761696767, 122.6789143406786 },
37  { 127.5, 127.5, 127.5 },
38  { 0, 0, 0 } };
39 
40  std::vector<std::vector<float>> tf_means = { { 128.0, 128.0, 128.0 },
41  { 128.0, 128.0, 128.0 },
42  { 128.0, 128.0, 128.0 },
43  { 128.0, 128.0, 128.0 },
44  { 127.5, 127.5, 127.5 } };
45  std::vector<float> caffe_scales = { 1.0, 1.0, 1.0, 0.007843, 0.00392156 };
46  std::vector<float> tf_scales = { 0.0078125, 0.0078125, 0.0078125, 0.0078125, 0.007843 };
47  std::vector<int> caffe_dimensions = { 227, 224, 227, 300, 448 };
48  std::vector<int> tf_dimensions = { 224, 224, 299, 299, 224 };
49 
50  for (unsigned int i = 0; i < caffe_nets.size(); i++)
51  {
52  ASSERT_NO_THROW({
53  std::shared_ptr<movidius_ncs_lib::NCSManager> handle = std::make_shared<movidius_ncs_lib::NCSManager>(
54  50, 0, static_cast<movidius_ncs_lib::Device::LogLevel>(0), caffe_nets[i],
55  "/opt/movidius/ncappzoo/caffe/" + caffe_dirs[i] + "/graph",
56  "/opt/movidius/ncappzoo/data/ilsvrc12/" + caffe_categories[i], caffe_dimensions[i], caffe_means[i],
57  caffe_scales[i], 3);
58  EXPECT_TRUE(handle != nullptr);
59  std::vector<std::string> images_path;
60  images_path.push_back(ros::package::getPath("movidius_ncs_lib") + "/../data/images/bicycle.jpg");
61  if (i < 3)
62  {
63  handle->classifyImage(images_path);
64  }
65  else
66  {
67  handle->detectImage(images_path);
68  }
69  });
70  }
71 
72  for (unsigned int i = 0; i < tf_nets.size(); i++)
73  {
74  ASSERT_NO_THROW({
75  std::shared_ptr<movidius_ncs_lib::NCSManager> handle = std::make_shared<movidius_ncs_lib::NCSManager>(
76  50, 0, static_cast<movidius_ncs_lib::Device::LogLevel>(0), tf_nets[i],
77  "/opt/movidius/ncappzoo/tensorflow/" + tf_dirs[i] + "/graph",
78  "/opt/movidius/ncappzoo/data/ilsvrc12/imagenet1001.txt", tf_dimensions[i], tf_means[i], tf_scales[i], 3);
79  EXPECT_TRUE(handle != nullptr);
80  std::vector<std::string> images_path;
81  images_path.push_back(ros::package::getPath("movidius_ncs_lib") + "/../data/images/bicycle.jpg");
82  handle->classifyImage(images_path);
83  sleep(10);
84  });
85  }
86 }
87 
88 TEST(UnitTestFunction, testLibraryIncorrectInputs)
89 {
90  try
91  {
92  std::vector<float> incorrect_mean = { 0, 0, 0 };
93  std::shared_ptr<movidius_ncs_lib::NCSManager> handle = std::make_shared<movidius_ncs_lib::NCSManager>(
94  0, 0, static_cast<movidius_ncs_lib::Device::LogLevel>(0), "Incorrect_type", "graph_not_exist",
95  "categories_not_exist", 0, incorrect_mean, 0, 3);
96  }
97  catch (...)
98  {
99  SUCCEED();
100  }
101 }
102 
103 int main(int argc, char** argv)
104 {
105  testing::InitGoogleTest(&argc, argv);
106  return RUN_ALL_TESTS();
107 }
TEST(UnitTestFunction, testLibraryFunctions)
ROSLIB_DECL std::string getPath(const std::string &package_name)
int main(int argc, char **argv)


movidius_ncs_lib
Author(s): Xiaojun Huang
autogenerated on Mon Jun 10 2019 14:11:23