我正在尝试使用Ubuntu 18.04中的Tensorflow(v1.10)和C ++中的Bazel(0.16)创建一个自定义OCR引擎。
当Tensorflow Session循环运行时,权重的预测值大于1
std :: vector输出;
for (size_t i=0; i<filenames.size(); i++)
{
cv::Mat image = cv::imread(filenames[i]);
Tensor image_tensor (tensorflow::DT_FLOAT, tensorflow::TensorShape{1,tf_height,tf_width,3});
image.convertTo(image, CV_32FC1);
tensorflow::StringPiece tmp_data = image_tensor.tensor_data();
memcpy(const_cast<char*>(tmp_data.data()), (image.data), tf_height * tf_width * sizeof(float));
// Creating a Session with the Graph
std::unique_ptr<tensorflow::Session> session(tensorflow::NewSession(tensorflow::SessionOptions()));
//session->tensorflow::reset(tensorflow::NewSession(tensorflow::SessionOptions()));
tensorflow::Status session_create_status = session->Create(graph_def);
std::vector<std::pair<string, tensorflow::Tensor>> inputs = {{inputLayer, image_tensor}};
outputs.clear();
Status runStatus = session->Run(inputs, {outputLayer}, {}, &outputs);
if (!runStatus.ok()) {
LOG(ERROR) << "Running model failed: " << runStatus;
return -1;
}
cv::imshow("Original Image",image);
cv::waitKey();
session->Close();
image.release();
}"Original Image",image);
cv::waitKey();
session->Close();
image.release();
}