以下是我完成的事情:
(1)从源(与bazel)建立张量流
(2)从源构建本征
(3)从源中构建protobuf
(4)将bazel-genfiles,tensorflow,third_party复制到workdir / include / tf
(5)将eigen3复制到workdir / include
(6)在workdir中编译我的cpp文件:g ++ -std = c ++ 11 -o -I./include/tf -I./include/eigen3 -I./include/tf/bazel-genfiles DeepLearningModel .cpp
以下是我得到的:
In file included from ./include/tf/tensorflow/core/framework/allocator.h:25:0,
from ./include/tf/tensorflow/core/framework/tensor.h:20,
from ./include/tf/tensorflow/core/public/session.h:24,
from DeepLearningModel.h:5,
from DeepLearningModel.cpp:1:
./include/tf/tensorflow/core/framework/type_traits.h:69:52: error: ‘half’ is not a member of ‘Eigen’
std::is_trivial<T>::value || std::is_same<T, Eigen::half>::value ||
^
./include/tf/tensorflow/core/framework/type_traits.h:69:52: error: ‘half’ is not a member of ‘Eigen’
./include/tf/tensorflow/core/framework/type_traits.h:69:63: error: template argument 2 is invalid
std::is_trivial<T>::value || std::is_same<T, Eigen::half>::value ||
^
DeepLearningModel.cpp: In member function ‘int DNNModel::decode_from_hex(char*, InputFeature&)’:
DeepLearningModel.cpp:58:34: error: ‘Tensorhape’ is not a member of ‘tensorflow’
Tensor x(tensorflow::DT_DOUBLE, tensorflow::Tensorhape({input.batch_size, input.timestep, input.feature_len}));
^
DeepLearningModel.cpp:61:22: error: ‘InputFeature {aka struct sInputFeature}’ has no member named ‘batch’
for(int i=0;i<input.batch;i++){
^
DeepLearningModel.cpp: In member function ‘int DNNModel::predict(const char*, int&)’:
DeepLearningModel.cpp:101:55: error: no matching function for call to ‘DNNModel::decode_from_hex(const char*&, InputFeature*)’
int status_decode = decode_from_hex(input_hex, &input);
^
DeepLearningModel.cpp:42:5: note: candidate: int DNNModel::decode_from_hex(char*, InputFeature&)
int DNNModel::decode_from_hex(char *input_hex, InputFeature &input){
^
DeepLearningModel.cpp:42:5: note: no known conversion for argument 2 from ‘InputFeature* {aka sInputFeature*}’ to ‘InputFeature& {aka sInputFeature&}’
DeepLearningModel.cpp:106:7: error: expected unqualified-id before ‘<’ token
std::<vector<std::pair<std::string, tensorflow:Tensor> > input_vec;
^
DeepLearningModel.cpp:106:8: error: ‘vector’ was not declared in this scope
std::<vector<std::pair<std::string, tensorflow:Tensor> > input_vec;
^
DeepLearningModel.cpp:106:8: note: suggested alternatives:
In file included from /usr/include/c++/5/vector:64:0,
from ./include/tf/tensorflow/core/public/session.h:20,
from DeepLearningModel.h:5,
from DeepLearningModel.cpp:1:
/usr/include/c++/5/bits/stl_vector.h:214:11: note: ‘std::vector’
class vector : protected _Vector_base<_Tp, _Alloc>
^
/usr/include/c++/5/bits/stl_vector.h:214:11: note: ‘std::vector’
DeepLearningModel.cpp:106:55: error: template argument 2 is invalid
std::<vector<std::pair<std::string, tensorflow:Tensor> > input_vec;
^
DeepLearningModel.cpp:106:59: error: ‘input_vec’ was not declared in this scope
std::<vector<std::pair<std::string, tensorflow:Tensor> > input_vec;
^
DeepLearningModel.cpp:107:31: error: missing template arguments before ‘,’ token
input_vec.push_back(std::pair,std::string, tensorflow::Tensor> >(&input_node, input.data));
^
DeepLearningModel.cpp:107:43: error: expected primary-expression before ‘,’ token
input_vec.push_back(std::pair,std::string, tensorflow::Tensor> >(&input_node, input.data));
^
DeepLearningModel.cpp:107:63: error: expected primary-expression before ‘>’ token
input_vec.push_back(std::pair,std::string, tensorflow::Tensor> >(&input_node, input.data));
^
DeepLearningModel.cpp:107:65: error: expected primary-expression before ‘>’ token
input_vec.push_back(std::pair,std::string, tensorflow::Tensor> >(&input_node, input.data));
^
In file included from ./include/eigen3/unsupported/Eigen/CXX11/Tensor:113:0,
from ./include/tf/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from ./include/tf/tensorflow/core/framework/tensor.h:19,
from ./include/tf/tensorflow/core/public/session.h:24,
from DeepLearningModel.h:5,
from DeepLearningModel.cpp:1:
./include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMap.h: In instantiation of ‘Eigen::TensorMap<PlainObjectType, Options_>::Scalar& Eigen::TensorMap<PlainObjectType, Options_>::operator()(Eigen::TensorMap<PlainObjectType, Options_>::Index, IndexTypes ...) [with IndexTypes = {int}; PlainObjectType = Eigen::Tensor<double, 1, 1, long int>; int Options_ = 16; Eigen::TensorMap<PlainObjectType, Options_>::Scalar = double; Eigen::TensorMap<PlainObjectType, Options_>::Index = long int]’:
DeepLearningModel.cpp:120:15: required from here
./include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMap.h:227:7: error: static assertion failed: Number of indices used to access a tensor coefficient must be equal to the rank of the tensor.
static_assert(sizeof...(otherIndices) + 1 == NumIndices || NumIndices == Dynamic, "Number of indices used to access a tensor coefficient must be equal to the rank of the tensor.");
^
./include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMap.h:230:110: error: no matching function for call to ‘Eigen::DSizes<long int, 1>::IndexOfRowMajor(Eigen::array<long int, 2ul>)’
const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumDims>{{firstIndex, otherIndices...}});
^
In file included from ./include/eigen3/unsupported/Eigen/CXX11/Tensor:68:0,
from ./include/tf/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from ./include/tf/tensorflow/core/framework/tensor.h:19,
from ./include/tf/tensorflow/core/public/session.h:24,
from DeepLearningModel.h:5,
from DeepLearningModel.cpp:1:
./include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h:336:52: note: candidate: DenseIndex Eigen::DSizes<DenseIndex, NumDims>::IndexOfRowMajor(Eigen::array<DenseIndex, NumDims>&) const [with DenseIndex = long int; int NumDims = 1; Eigen::array<DenseIndex, NumDims> = std::array<long int, 1ul>]
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex IndexOfRowMajor(const array<DenseIndex, NumDims>& indices) const {
^
./include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h:336:52: note: no known conversion for argument 1 from ‘Eigen::array<long int, 2ul> {aka std::array<long int, 2ul>}’ to ‘Eigen::array<long int, 1ul>& {aka const std::array<long int, 1ul>&}’
In file included from ./include/eigen3/unsupported/Eigen/CXX11/Tensor:113:0,
from ./include/tf/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from ./include/tf/tensorflow/core/framework/tensor.h:19,
from ./include/tf/tensorflow/core/public/session.h:24,
from DeepLearningModel.h:5,
from DeepLearningModel.cpp:1:
./include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMap.h:233:110: error: no matching function for call to ‘Eigen::DSizes<long int, 1>::IndexOfColMajor(Eigen::array<long int, 2ul>)’
const Index index = m_dimensions.IndexOfColMajor(array<Index, NumDims>{{firstIndex, otherIndices...}});
^
In file included from ./include/eigen3/unsupported/Eigen/CXX11/Tensor:68:0,
from ./include/tf/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from ./include/tf/tensorflow/core/framework/tensor.h:19,
from ./include/tf/tensorflow/core/public/session.h:24,
from DeepLearningModel.h:5,
from DeepLearningModel.cpp:1:
./include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h:333:52: note: candidate: DenseIndex Eigen::DSizes<DenseIndex, NumDims>::IndexOfColMajor(Eigen::array<DenseIndex, NumDims>&) const [with DenseIndex = long int; int NumDims = 1; Eigen::array<DenseIndex, NumDims> = std::array<long int, 1ul>]
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex IndexOfColMajor(const array<DenseIndex, NumDims>& indices) const {
^
./include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h:333:52: note: no known conversion for argument 1 from ‘Eigen::array<long int, 2ul> {aka std::array<long int, 2ul>}’ to ‘Eigen::array<long int, 1ul>& {aka const std::array<long int, 1ul>&}’
Eigen有什么问题,我该如何解决? 请帮忙......