Skip to content

Instantly share code, notes, and snippets.

@owulveryck
Last active August 9, 2017 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owulveryck/1f3fc2366e5a35ab119633d57ad074b6 to your computer and use it in GitHub Desktop.
Save owulveryck/1f3fc2366e5a35ab119633d57ad074b6 to your computer and use it in GitHub Desktop.
Inception v3 in GO
func constructGraphToNormalizeImage() (graph *tf.Graph, input, output tf.Output, err error) {
const (
H, W = 299, 299
Mean = float32(0)
Scale = float32(255)
)
s := op.NewScope()
input = op.Placeholder(s, tf.String)
output = op.Div(s,
op.Sub(s,
op.ResizeBilinear(s,
op.ExpandDims(s,
op.Cast(s,
op.DecodeJpeg(s, input, op.DecodeJpegChannels(3)), tf.Float),
op.Const(s.SubScope("make_batch"), int32(0))),
op.Const(s.SubScope("size"), []int32{H, W})),
op.Const(s.SubScope("mean"), Mean)),
op.Const(s.SubScope("scale"), Scale))
graph, err = s.Finalize()
return graph, input, output, err
}
tick := time.Tick(1000 * time.Millisecond)
for {
err = cam.WaitForFrame(timeout)
// ... process error
frame, err := cam.ReadFrame()
if len(frame) != 0 {
select {
case <-tick:
// ... process the image and display the result
default:
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment