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

Function ExecuteTfLite

tensorflow/lite/models/smartreply/predictor.cc:45–68  ·  view source on GitHub ↗

Predict with TfLite model.

Source from the content-addressed store, hash-verified

43
44// Predict with TfLite model.
45void ExecuteTfLite(const std::string& sentence,
46 ::tflite::Interpreter* interpreter,
47 std::map<std::string, float>* response_map) {
48 {
49 TfLiteTensor* input = interpreter->tensor(interpreter->inputs()[0]);
50 tflite::DynamicBuffer buf;
51 buf.AddString(sentence.data(), sentence.length());
52 buf.WriteToTensorAsVector(input);
53 interpreter->AllocateTensors();
54
55 interpreter->Invoke();
56
57 TfLiteTensor* messages = interpreter->tensor(interpreter->outputs()[0]);
58 TfLiteTensor* confidence = interpreter->tensor(interpreter->outputs()[1]);
59
60 for (int i = 0; i < confidence->dims->data[0]; i++) {
61 float weight = confidence->data.f[i];
62 auto response_text = tflite::GetString(messages, i);
63 if (response_text.len > 0) {
64 (*response_map)[string(response_text.str, response_text.len)] += weight;
65 }
66 }
67 }
68}
69
70void GetSegmentPredictions(
71 const std::vector<std::string>& input,

Callers 1

GetSegmentPredictionsFunction · 0.85

Calls 10

GetStringFunction · 0.85
AddStringMethod · 0.80
WriteToTensorAsVectorMethod · 0.80
tensorMethod · 0.45
inputsMethod · 0.45
dataMethod · 0.45
lengthMethod · 0.45
AllocateTensorsMethod · 0.45
InvokeMethod · 0.45
outputsMethod · 0.45

Tested by

no test coverage detected