'Trying to use TensorFlow C++ API with Cast operation (Movenet Model) results in error when inference
Hi I'm trying to use the new MoveNet Model with the tensorlow C++ API.
This is my part of the code trying to load the SavedModel and the image.
Load Model
// Load
SavedModelBundleLite model_bundle;
SessionOptions session_options = SessionOptions();
session_options.config.mutable_gpu_options()->set_allow_growth(true);
RunOptions run_options = RunOptions();
std::string export_dir = "/workspace/modelZoo";
Status status = LoadSavedModel(session_options, run_options, export_dir, {"serve"}, &model_bundle);
Load Image
//Load image
int32_t input_width = 256;
int32_t input_height = 256;
using namespace ::tensorflow::ops;
std::string filename = "image.jpg";
Scope root = Scope::NewRootScope();
auto output = tensorflow::ops::ReadFile(root.WithOpName("file_reader"), filename);
const int wanted_channels = 3;
tensorflow::Output image_reader = tensorflow::ops::DecodeJpeg(root.WithOpName("file_decoder"), output, tensorflow::ops::DecodeJpeg::Channels(wanted_channels));
auto image_int32 = tensorflow::ops::Cast(root.WithOpName("int32_caster"), image_reader, tensorflow::DT_INT32);
auto dims_expander = tensorflow::ops::ExpandDims(root.WithOpName("expand_dims"), image_int32, 0);
auto resized = tensorflow::ops::ResizeBilinear(root, dims_expander, tensorflow::ops::Const(root.WithOpName("size"), {input_height, input_width}));
std::vector<Tensor> out_tensors;
ClientSession session(root);
auto run_status = session.Run({resized}, &out_tensors);
And INFERENCE
const std::string input_name_1 = model_def.inputs().at("input").name();
std::vector<std::pair<string, Tensor>> inputs_data = {{input_name_1, out_tensors[0]}};
std::string outputLayer = model_def.outputs().at("output_0").name();
std::vector<Tensor> outputs;
Status runStatus = model_bundle.GetSession()->Run(inputs_data, {outputLayer}, {}, &outputs);
When the code runs the inference I get this error.
Expects arg[0] to be int32 but float is provided
Based on the tutorial from tensorflow hub (https://tfhub.dev/google/movenet/multipose/lightning/1) the model needs int32 format but I don't know what is wrong with my code referring to the casting part of the input tensor
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
