如何在C ++中将图像的类型二进制数据更改为tensorflw :: Tensor()?
`string image_path = tensorflow::io::JoinPath(root_dir, image);
Status read_tensor_status =
ReadTensorFromImageFile(image_path, input_height, input_width, input_mean,
input_std, &resized_tensors);
if (!read_tensor_status.ok()) {
LOG(ERROR) << read_tensor_status;
return -1;
}
const Tensor& resized_tensor = resized_tensors[0];
// Actually run the image through the model.
std::vector<Tensor> outputs;
Status run_status = session->Run({{input_layer, resized_tensor}},
{output_layer}, {}, &outputs);`
这是用于预测图像标签的c ++张量流示例代码。 因此输入的数据类型是图像(tensorflow api通过“ ReadTensorFromImageFile”将图像提供给tensorflow :: Tensor)。
Status read_tensor_status =
ReadTensorFromImageFile(image_path, input_height, input_width, input_mean,
input_std, &resized_tensors);
const Tensor& resized_tensor = resized_tensors[0];
Status run_status = session->Run({{input_layer, resized_tensor}},
{output_layer}, {}, &outputs);
我的tensorflow模型的输入数据类型是二进制。
with open('image.jpg', 'rb') as img_file:
img_file_data = img_file.read()
在python中,以上代码是我模型的输入数据类型。
所以我必须将二进制转换为tensorflow :: Tensor。 我找不到 如果可以的话,请告诉我。 谢谢您的阅读。