This file contains 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) | |
} |
This file contains 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
func normalizeImage(body io.ReadCloser) (*tensorflow.Tensor, error) { | |
var buf bytes.Buffer | |
io.Copy(&buf, body) | |
tensor, err := tensorflow.NewTensor(buf.String()) | |
if err != nil { | |
return nil, err | |
} | |
graph, input, output, err := getNormalizedGraph() |
This file contains 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
// Create a session for inference over modelGraph. | |
session, err := tf.NewSession(modelGraph, nil) | |
if err != nil { | |
log.Fatalf("could not init session: %v", err) | |
} | |
defer session.Close() | |
output, err := session.Run( | |
map[tf.Output]*tf.Tensor{ | |
modelGraph.Operation("input").Output(0): tensor, |
This file contains 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
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 |
This file contains 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
FROM ctava/tensorflow-go | |
RUN mkdir -p /model && \ | |
curl -o /model/inception5h.zip -s "http://download.tensorflow.org/models/inception5h.zip" && \ | |
unzip /model/inception5h.zip -d /model | |
WORKDIR /go/src/imgrecognition | |
COPY . . | |
RUN go build | |
ENTRYPOINT [ "/go/src/imgrecognition/imgrecognition" ] |
This file contains 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
package main | |
import ( | |
"fmt" | |
) | |
type Node struct { | |
Value int | |
} |
This file contains 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
type Customer struct { | |
ID int | |
Email string | |
Phone sql.NullString | |
Age sql.NullInt64 | |
} |
This file contains 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
fmt.Println(customer.Phone.Value) |
This file contains 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
type Customer struct { | |
ID int | |
Email string | |
Phone string | |
Age int | |
} | |
func GetCustomerByEmail(db *sql.DB, email string) (*Customer, error) { | |
stmt, err := db.Prepare("SELECT id, email, phone, age FROM customer where email = ?") | |
if err != nil { |
This file contains 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
var nt mysql.NullTime | |
err := db.QueryRow("SELECT time FROM foo WHERE id = ?", id).Scan(&nt) | |
if nt.Valid { | |
// use nt.Time | |
} else { | |
// NULL value | |
} |