我的部分代码如下,
IplImage *pImg = cvLoadImage("img.bmp", 1);
IplImage *pImgF = cvCreateImage(cvGetSize(pImg),IPL_DEPTH_32F , 3);
cvConvert(pImg, pImgF);
tensorflow::Tensor input_tensor(tensorflow::DT_FLOAT,
tensorflow::TensorShape({ 1, input_height, input_width, 3 }));
auto input_tensor_mapped = input_tensor.tensor<float, 4>();
float *pSourceRow = (float *)pImgF->imageData;
int x, y, c;
int depth = 3;
for (int y = 0; y < height; ++y) {
const float* source_row = pSourceRow + (y * width * depth);
for (int x = 0; x < width; ++x) {
const float *source_pixel = source_row + (x * depth);
const float* source_B = source_pixel + 0;
const float* source_G = source_pixel + 1;
const float* source_R = source_pixel + 2;
input_tensor_mapped(0, y, x, 0) = *source_R;
input_tensor_mapped(0, y, x, 1) = *source_G;
input_tensor_mapped(0, y, x, 2) = *source_B;
}
}
const Tensor& resized_tensor = input_tensor;
Status run_status = session->Run({ { input_layer, resized_tensor } },
{ output_layer }, {}, &outputs);
if (!run_status.ok()) {
LOG(ERROR) << "Running model failed: " << run_status;
return -1;
}
运行后,run_status显示错误“Expects arg [0]为uint8但提供了float”。任何人都知道如何解决它?