tensor.h
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 #ifndef MOVIDIUS_NCS_LIB_TENSOR_H
18 #define MOVIDIUS_NCS_LIB_TENSOR_H
19 
20 #include <memory>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 #include <opencv2/opencv.hpp>
26 
27 namespace movidius_ncs_lib
28 {
29 class Tensor
30 {
31 public:
32  using Ptr = std::shared_ptr<Tensor>;
33  using ConstPtr = std::shared_ptr<Tensor const>;
34 
35  Tensor(const std::pair<int, int>& net_dim,
36  const std::vector<float>& mean,
37  const float& scale);
38 
39  void loadImageData(const cv::Mat& image);
40  void clearTensor();
41 
42  inline const uint16_t* raw() const
43  {
44  return &tensor_[0];
45  }
46  inline const size_t size() const
47  {
48  return 3 * net_height_ * net_width_ * sizeof(uint16_t);
49  }
50  inline int getImageWidth()
51  {
52  return image_width_;
53  }
54  inline int getImageHeight()
55  {
56  return image_height_;
57  }
58 #ifndef SUPPORT_F16C
59  static void fp32tofp16(uint16_t* __restrict out, float in);
60  static void fp16tofp32(float* __restrict out, uint16_t in);
61 #endif
62 
63 private:
64  std::vector<uint16_t> tensor_;
69  std::vector<float> mean_;
70  float scale_;
71 };
72 } // namespace movidius_ncs_lib
73 
74 #endif // MOVIDIUS_NCS_LIB_TENSOR_H
const size_t size() const
Definition: tensor.h:46
static void fp16tofp32(float *__restrict out, uint16_t in)
Definition: tensor.cpp:89
std::shared_ptr< Tensor > Ptr
Definition: tensor.h:32
const uint16_t * raw() const
Definition: tensor.h:42
Tensor(const std::pair< int, int > &net_dim, const std::vector< float > &mean, const float &scale)
Definition: tensor.cpp:28
std::shared_ptr< Tensor const > ConstPtr
Definition: tensor.h:33
static void fp32tofp16(uint16_t *__restrict out, float in)
Definition: tensor.cpp:105
void loadImageData(const cv::Mat &image)
Definition: tensor.cpp:41
std::vector< uint16_t > tensor_
Definition: tensor.h:64
std::vector< float > mean_
Definition: tensor.h:69


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