MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / GetTopDetections

Function GetTopDetections

tensorflow/examples/multibox_detector/main.cc:187–210  ·  view source on GitHub ↗

Analyzes the output of the MultiBox graph to retrieve the highest scores and their positions in the tensor, which correspond to individual box detections.

Source from the content-addressed store, hash-verified

185// Analyzes the output of the MultiBox graph to retrieve the highest scores and
186// their positions in the tensor, which correspond to individual box detections.
187Status GetTopDetections(const std::vector<Tensor>& outputs, int how_many_labels,
188 Tensor* indices, Tensor* scores) {
189 auto root = tensorflow::Scope::NewRootScope();
190 using namespace ::tensorflow::ops; // NOLINT(build/namespaces)
191
192 string output_name = "top_k";
193 TopK(root.WithOpName(output_name), outputs[0], how_many_labels);
194 // This runs the GraphDef network definition that we've just constructed, and
195 // returns the results in the output tensors.
196 tensorflow::GraphDef graph;
197 TF_RETURN_IF_ERROR(root.ToGraphDef(&graph));
198
199 std::unique_ptr<tensorflow::Session> session(
200 tensorflow::NewSession(tensorflow::SessionOptions()));
201 TF_RETURN_IF_ERROR(session->Create(graph));
202 // The TopK node returns two outputs, the scores and their original indices,
203 // so we have to append :0 and :1 to specify them both.
204 std::vector<Tensor> out_tensors;
205 TF_RETURN_IF_ERROR(session->Run({}, {output_name + ":0", output_name + ":1"},
206 {}, &out_tensors));
207 *scores = out_tensors[0];
208 *indices = out_tensors[1];
209 return Status::OK();
210}
211
212// Converts an encoded location to an actual box placement with the provided
213// box priors.

Callers 1

PrintTopDetectionsFunction · 0.85

Calls 7

WithOpNameMethod · 0.80
TopKFunction · 0.50
NewSessionFunction · 0.50
SessionOptionsStruct · 0.50
ToGraphDefMethod · 0.45
CreateMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected