模型chinese_text_detection_db_mobile在C++下预测报错
Created by: ylj135cool
PaddlePaddle:1.8.4 PaddleHub:1.8.2 模型:chinese_text_detection_db_mobile=1.0.3 系统:win10 编译环境:VS2019
问题描述: 使用C++部署方式,按照文档提示,测试PaddleHub中的文字检测模型“chinese_text_detection_db_mobile”时,在预测时报错。
报错内容如下:
`--------------------------------------------
C++ Call Stacks (More useful to developers):
--------------------------------------------
Windows not support stack backtrace yet.
----------------------
Error Message Summary:
----------------------
InvalidArgumentError: Broadcast dimension mismatch. Operands could not be broadcast together with the shape of X = [1, 96, 12, 40] and the shape of Y = [1, 96, 11, 40]. Received [12] in X is not equal to [11] in Y at i:2.
[Hint: Expected x_dims_array[i] == y_dims_array[i] || x_dims_array[i] <= 1 || y_dims_array[i] <= 1 == true, but received x_dims_array[i] == y_dims_array[i] || x_dims_array[i] <= 1 || y_dims_array[i] <= 1:0 != true:1.] at (D:\1.8.2\paddle\paddle/fluid/operators/elementwise/elementwise_op_function.h:157)`
实际的调用代码如下:
void Pridict(cv::Mat& mat)
{
int batch_size = 1;
int channels = mat.channels();
int height = mat.rows;
int width = mat.cols;
int nums = batch_size * channels * height * width;
float* input = new float[nums] {0};
cv::Mat newMat;
mat.convertTo(newMat, CV_32FC3);
// data format NHWC to NCHW
int idx = 0;
for (int i = 0; i < batch_size; ++i)
{
int offsetBatch = i * width * height * channels;
for (int j = 0; j < height; ++j)
{
for (int k = 0; k < width; ++k)
{
auto data = newMat.at<cv::Vec3f>(j, k);
int offset = j * width + k;
input[offsetBatch + offset] = data[0];
input[offsetBatch + width * height + offset] = data[1];
input[offsetBatch + width * height * 2 + offset] = data[2];
}
}
}
//for (int i = 0; i < channels; ++i) {
// cv::extractChannel(newMat, cv::Mat(height, width, CV_32FC1, input + i * height * width), i);
//}
auto input_names = predictor->GetInputNames();
auto input_t = predictor->GetInputTensor(input_names[0]);
input_t->Reshape({ batch_size, channels, height, width });
input_t->copy_from_cpu(input);
//此处执行后报错
predictor->ZeroCopyRun();
std::vector<float> out_data;
auto output_names = predictor->GetOutputNames();
auto output_t = predictor->GetOutputTensor(output_names[0]);
std::vector<int> output_shape = output_t->shape();
int out_num = std::accumulate(output_shape.begin(), output_shape.end(), 1,
std::multiplies<int>());
out_data.resize(out_num);
output_t->copy_to_cpu(out_data.data());
delete[] input;
}
其中mat是直接从文件加载的一个jpg文件,又遇到类似情况的没有?还请各位大佬指导一下是什么原因,如何解决? 谢谢大家。