Created
January 8, 2018 10:33
-
-
Save plutov/0de9dc194bc15857db0c689ce0da4a5b to your computer and use it in GitHub Desktop.
tensorflow3.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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