forked from Pisush/tensorflow-and-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.go
76 lines (57 loc) · 1.81 KB
/
template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
tf "github.com/tensorflow/tensorflow/tensorflow/go"
)
const (
inputImage = "./captcha/3KC6YY.png"
)
func captchaToText(path string, savedModel *tf.SavedModel, printLogs bool) string {
// Read captcha
captchaImage, err := ioutil.ReadFile(inputImage)
if err != nil {
log.Fatal(err)
}
// This is where the action happens: run captcha through tensorflow model!
// Define the Output struct that will be fed in the model:
// the operation here is providing the input image as bytes of the prediction node, the index is 0
feedsOutput := tf.Output{
//...
}
// here just for the template to run - delete me
nilOutput := tf.Output{}
if feedsOutput != nilOutput {
lof.Fatal(err)
}
// Define the input Tensor: the string version of the CAPTCHA
//...
// Set a map from the operation we will apply to the input it will be applied on
// feeds := map[tf.Output]*tf.Tensor{feedsOutput: feedsTensor}
// Define the Output struct that will be fetched as the model's result:
// the operation here is the output of the prediction node, the index is 0
//...
// Run the data through the graph using the two Output structs
// and receive the output: the captcha prediction
//...
// We only need the first element of the tensor
var text string
//...
if printLogs {
log.Println("for file" + path + "the text is" + text)
}
return text
}
func main() {
printLogs := flag.Bool("printlog", false, "set to true for printing all log lines on the screen")
flag.Parse()
// Always make the log file run.log
//...
// Creates a new SavedModel by loading a model previously exported to a directory on disk
// the tag is "serve", no special options
var captchaText string
// captchaText = captchaToText(inputImage, savedModel, *printLogs)
fmt.Println(captchaText)
}