Skip to content

Instantly share code, notes, and snippets.

View plutov's full-sized avatar
🎥
https://www.youtube.com/packagemain

Alex Pliutau plutov

🎥
https://www.youtube.com/packagemain
View GitHub Profile
@plutov
plutov / tensorflow3.go
Created January 8, 2018 10:33
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)
}
@plutov
plutov / tensorflow4.go
Created January 8, 2018 10:34
tensorflow4.go
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()
@plutov
plutov / tensorflow5.go
Created January 8, 2018 10:35
tensorflow5.go
// 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,
@plutov
plutov / tensorflow6.go
Created January 8, 2018 10:36
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
@plutov
plutov / tensorflow.Dockerfile
Created January 8, 2018 10:44
tensorflow.Dockerfile
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" ]
@plutov
plutov / stack.go
Created August 21, 2018 02:36
stack
package main
import (
"fmt"
)
type Node struct {
Value int
}
@plutov
plutov / working-with-db-nulls2.go
Created August 21, 2018 04:59
working-with-db-nulls2
type Customer struct {
ID int
Email string
Phone sql.NullString
Age sql.NullInt64
}
@plutov
plutov / working-with-db-nulls3.go
Created August 21, 2018 04:59
working-with-db-nulls3
fmt.Println(customer.Phone.Value)
@plutov
plutov / working-with-db-nulls1.go
Last active August 21, 2018 05:03
working-with-db-nulls1
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 {
@plutov
plutov / working-with-db-time-in-go1.go
Created August 21, 2018 05:05
working-with-db-time-in-go1.go
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
}