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

Function printBestLabel

tensorflow/go/example_inception_inference_test.go:123–146  ·  view source on GitHub ↗
(probabilities []float32, labelsFile string)

Source from the content-addressed store, hash-verified

121}
122
123func printBestLabel(probabilities []float32, labelsFile string) {
124 bestIdx := 0
125 for i, p := range probabilities {
126 if p > probabilities[bestIdx] {
127 bestIdx = i
128 }
129 }
130 // Found the best match. Read the string from labelsFile, which
131 // contains one line per label.
132 file, err := os.Open(labelsFile)
133 if err != nil {
134 log.Fatal(err)
135 }
136 defer file.Close()
137 scanner := bufio.NewScanner(file)
138 var labels []string
139 for scanner.Scan() {
140 labels = append(labels, scanner.Text())
141 }
142 if err := scanner.Err(); err != nil {
143 log.Printf("ERROR: failed to read %s: %v", labelsFile, err)
144 }
145 fmt.Printf("BEST MATCH: (%2.0f%% likely) %s\n", probabilities[bestIdx]*100.0, labels[bestIdx])
146}
147
148// Convert the image in filename to a Tensor suitable as input to the Inception model.
149func makeTensorFromImage(filename string) (*tf.Tensor, error) {

Callers 1

ExampleFunction · 0.85

Calls 4

appendFunction · 0.85
OpenMethod · 0.45
CloseMethod · 0.45
ErrMethod · 0.45

Tested by

no test coverage detected