Tensorflow C++ 占位符初始化
Tensorflow C++ Placeholder initialization
我试图在cpp上使用tensorflow执行图像字幕。我正在遵循如何使用 tf.estimator 导入保存的 Tensorflow 模型训练并预测输入数据并尝试的方向
int main(int argc, char**) {
....
auto x = tf::Tensor(tf::DT_UINT8, tf::TensorShape({height, width, channel}));
auto matrix = x.matrix<char>();
....
}
当我编译程序时,代码
> In file included from /usr/local/include/tensorflow/core/framework/tensor.h:26:0,
from /usr/local/include/tensorflow/core/public/session.h:23,
from /usr/local/include/tensorflow/cc/saved_model/loader.h:26,
from server.cpp:22:
/usr/local/include/tensorflow/core/framework/types.h: In instantiation of ‘struct tensorflow::DataTypeToEnum<char>’:
/usr/local/include/tensorflow/core/framework/tensor.h:530:46: required from ‘typename tensorflow::TTypes<T, NDIMS>::Tensor tensorflow::Tensor::tensor() [with T = char; long unsigned int NDIMS = 2ul; typename tensorflow::TTypes<T, NDIMS>::Tensor = Eigen::TensorMap<Eigen::Tensor<char, 2, 1, long int>, 16, Eigen::MakePointer>]’
/usr/local/include/tensorflow/core/framework/tensor.h:240:25: required from ‘typename tensorflow::TTypes<T>::Matrix tensorflow::Tensor::matrix() [with T = char; typename tensorflow::TTypes<T>::Matrix = Eigen::TensorMap<Eigen::Tensor<char, 2, 1, long int>, 16, Eigen::MakePointer>]’
server.cpp:121:34: required from here
/usr/local/include/tensorflow/core/framework/types.h:138:3: error: static assertion failed: Specified Data Type not supported
static_assert(IsValidDataType<T>::value, "Specified Data Type not supported");In file included from /usr/local/include/tensorflow/core/public/session.h:23:0,
from /usr/local/include/tensorflow/cc/saved_model/loader.h:26,
from server.cpp:22:
/usr/local/include/tensorflow/core/framework/tensor.h: In instantiation of ‘typename tensorflow::TTypes<T, NDIMS>::Tensor tensorflow::Tensor::tensor() [with T = char; long unsigned int NDIMS = 2ul; typename tensorflow::TTypes<T, NDIMS>::Tensor = Eigen::TensorMap<Eigen::Tensor<char, 2, 1, long int>, 16, Eigen::MakePointer>]’:
/usr/local/include/tensorflow/core/framework/tensor.h:240:25: required from ‘typename tensorflow::TTypes<T>::Matrix tensorflow::Tensor::matrix() [with T = char; typename tensorflow::TTypes<T>::Matrix = Eigen::TensorMap<Eigen::Tensor<char, 2, 1, long int>, 16, Eigen::MakePointer>]’
server.cpp:121:34: required from here
/usr/local/include/tensorflow/core/framework/tensor.h:530:46: error: ‘v’ is not a member of ‘tensorflow::DataTypeToEnum<char>’
CheckTypeAndIsAligned(DataTypeToEnum<T>::v());
有人遇到过同样的问题吗?
找到了一个解决方案。似乎存在两个问题。 (1( DT_UINT8 是 C++ 中的 uchar (2(使用张量代替矩阵
我将代码更改为
auto x = tf::Tensor(tf::DT_UINT8, tf::TensorShape(
{height, width,3}));
auto matrix = x.tensor<uchar, 3>();
并工作。从 https://github.com/tensorflow/tensorflow/issues/19909 那里得到了这个想法
即使使用初始化列表声明TensorShape
,仍应指定矩阵的维数,因为它无法在编译时推导出C++。
auto x = tf::Tensor(tf::DT_UINT8, tf::TensorShape({height, width, channel}));
auto matrix = x.matrix<char, 3>();
相关文章:
- 是否可以初始化不可复制类型的成员变量(或基类)
- C++使用整数的压缩数组初始化对象
- C++初始化基类
- 多成员Constexpr结构初始化
- 复制列表初始化的隐式转换的等级是多少
- 内联映射初始化的动态atexit析构函数崩溃
- 如何在C++中初始化嵌套类中的2个memeber
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- 没有用于初始化C++中的变量模板的匹配构造函数
- 在未初始化映射的情况下,将值插入到映射的映射中
- 以这种方式初始化的 char 数组是否会自动添加空终止符?
- 初始化声明符是 prvalue 表达式吗?
- C++初始化 std::function 时如何将占位符绑定到引用/引用参数?
- Tensorflow C++ 占位符初始化
- 错误:在类型 "blah blah" 的绑定引用中删除限定符以初始化"some other blah blah"
- 使用无效指针初始化指针声明符的行为是否未定义?
- 在构造函数的成员初始值设定项列表中使用带有指示符的初始值设定项列表以初始化匿名联合类型时出现编译错误
- C++ 非整型模板 Const 初始化 预期在类名之前使用初始化声明符
- 使用索引指示符初始化_C++_对象的数组
- 尾随返回类型中的占位符是否覆盖初始占位符