我正在尝试使用tf 1.5.0 c api运行已保存的图像分割模型 . 我的模型得到一个大小为1 * 256 * 256 * 3的输入图像,并提供给这样的张量:
for (int x = 0; x < 256; x++) {
for (int y = 0; y <256; y++) {
data_(0, x, y, 0) =
(float) image_out.at<:vec3b>(x, y)[0];
data_(0, x, y, 1) =
(float) image_out.at<:vec3b>(x, y)[1];
data_(0, x, y, 2) =
(float) image_out.at<:vec3b>(x, y)[2];
}
}
然后我使用 sess->Run() 运行模型,并获得输出:
输入张量类型:浮点形状:[1,224,224,3]值:[[[254 254 254]]] ...输出张量类型:浮点形状:[1,224,224,1]值:[[[0.160249829] [0.0639446825] [ 0.0414313935]]] ...
我想使用cv :: imwrite()将输出保存到图像中 . 但是,张量不能直接保存 . 所以我试着像这样转换张量:tensorflow :: tensor-> eigen :: mat-> cv :: mat . 代码是:
auto m = Eigen::Map<:matrix>
float, /* scalar element type */
Eigen::Dynamic, /* num_rows is a run-time value */
Eigen::Dynamic, /* num_cols is a run-time value */
Eigen::RowMajor /* tensorflow::Tensor is always row-major */
>>(
outputs[0].flat().data(), /* ptr to data */
outputs[0].dim_size(1), /* num_rows */
outputs[0].dim_size(2) /* num_cols */);
//std::cout << "m " << m << std::endl;
cv::Mat rotMatrix;
cv::eigen2cv(m, rotMatrix);
这在编译时引发错误:
注意:模板void cv :: eigen2cv(const Eigen :: Matrix <_scalar>&,cv :: Mat&)void eigen2cv(const Eigen :: Matrix <_tp _options>&src,Mat&dst)^ /usr/local/opencv3.1/include/opencv2/core/eigen.hpp:63:6:注意:模板参数扣除/替换失败:src / demo / demo .cpp:152:28:注意:\ u2018Eigen :: Map> \ u2019不是来自\ u2018const Eigen :: Matrix <_scalar> \ u2019 cv :: eigen2cv(m,rotMatrix ); ^在src / demo / demo.cpp中包含的文件中:11:0:/usr/local/opencv3.1/include/opencv2/core/eigen.hpp:81:6:注意:template void cv :: eigen2cv(const Eigen :: Matrix <_scalar>&,cv :: Matx <_tp>&)void eigen2cv(const Eigen :: Matrix <_tp>&src,^ /usr/local/opencv3.1/include/opencv2/core/eigen.hpp:81:6:注意:模板参数扣除/替换失败:src / demo / demo.cpp:152:28 :注意:\ u2018Eigen :: Map> \ u2019不是来自\ u2018const Eigen :: Matrix <_scalar> \ u2019 cv :: eigen2cv(m,rotMatrix); ^ make:* ** [obj / demo.o]错误1
怎么了?
那么,有没有一种方便的方法呢?