Skip to content

Instantly share code, notes, and snippets.

@plutov
Created January 8, 2018 10:36
Show Gist options
  • Save plutov/7580d3fc5623cdc7efeb44269004fec7 to your computer and use it in GitHub Desktop.
Save plutov/7580d3fc5623cdc7efeb44269004fec7 to your computer and use it in GitHub Desktop.
tensorflow6.go
res := getTopFiveLabels(labels, output[0].Value().([][]float32)[0])
for _, l := range res {
fmt.Printf("label: %s, probability: %.2f%%\n", l.Label, l.Probability*100)
}
func getTopFiveLabels(labels []string, probabilities []float32) []Label {
var resultLabels []Label
for i, p := range probabilities {
if i >= len(labels) {
break
}
resultLabels = append(resultLabels, Label{Label: labels[i], Probability: p})
}
sort.Sort(Labels(resultLabels))
return resultLabels[:5]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment