Skip to content

Instantly share code, notes, and snippets.

@plutov
Created January 8, 2018 10:33
Show Gist options
  • Save plutov/0de9dc194bc15857db0c689ce0da4a5b to your computer and use it in GitHub Desktop.
Save plutov/0de9dc194bc15857db0c689ce0da4a5b to your computer and use it in GitHub Desktop.
tensorflow3.go
const (
graphFile = "/model/imagenet_comp_graph_label_strings.txt"
labelsFile = "/model/imagenet_comp_graph_label_strings.txt"
)
graph, labels, err := loadModel()
if err != nil {
log.Fatalf("unable to load model: %v", err)
}
func loadModel() (*tf.Graph, []string, error) {
// Load inception model
model, err := ioutil.ReadFile(graphFile)
if err != nil {
return nil, nil, err
}
graph := tf.NewGraph()
if err := graph.Import(model, ""); err != nil {
return nil, nil, err
}
// Load labels
labelsFile, err := os.Open()
if err != nil {
return nil, nil, err
}
defer labelsFile.Close()
scanner := bufio.NewScanner(labelsFile)
var labels []string
for scanner.Scan() {
labels = append(labels, scanner.Text())
}
return graph, labels, scanner.Err()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment