This document discusses using TensorFlow with Golang for machine learning tasks like image recognition. It provides instructions for cloning a GitHub repository containing a sample project that uses a pre-trained TensorFlow model within a Golang application to classify images. The application is built as a Docker image to perform image recognition by taking URLs as arguments and returning potential labels and probabilities. The document also briefly mentions the possibility of training custom models from Golang in TensorFlow.
2. • Docker Community Leader , Bangalore
• Author :- lightweight Kubernetes with k3s
with packt Publication
• Gopherlabs – 500+ tutorials
• Dockerlabs – 500+ tutorials
• Kubelabs – 200+ tutorials
• Okteto – Kubernetes For Developer , Bangalore
Meetup Organizer
Who Am I?
@BiradarSangam
Sangam Biradar
EngineITops.com
3. ● Introduction to tenser flow
TensorFlow is an end-to-end open source platform for machine learning.
It has a comprehensive, flexible ecosystem of tools, libraries and community
resources that lets researchers push the state-of-the-art in ML and developers
easily build and deploy ML powered applications.
5. ● common use case
you can find some in the TensorFlow Models repo
https://github.com/tensorflow/models.
we'll use one of them, called Inception to recognize an
image. https://github.com/tensorflow/models/tre
e/master/research/inception/inception
6. ● tenser flow trained model
image with TensorFlow plus Go to reduce Dockerfile.
https://github.com/ctava/tensorflow-go
Download Inception
data: http://download.tensorflow.org/models/inception5h .zip
Let's start with simple main.go file to test if our Dockerfile works.
7. reduce my Dockerfile.
https://github.com/ctava/tensorflow-go
Download Inception data: http://download.tensorflow.org/models/inception5h.zip
Let's start with simple main.go file to test if our Dockerfile works.
package main func main()
{
if len(os.Args) < 2
{
log.Fatalf("usage: imgrecognition <image_url>")
}
fmt.Printf("url: %sn", os.Args[1]) }
8. docker build -t imgrecognition .
docker run imgrecognition https://www.iaspaper.net/wp-content/uploads/2017/10/Rabbit-Essay.jpg
our image from the provided URL:
// Get image from URL response, e := http.Get(os.Args[1]) if e
!= nil {
log.Fatalf("unable to get image from url: %v", e) }
defer response.Body.Close()
9. ● Run the session to normalize image using input/output
10. ● New Tensor converts from a Go value to a Tensor
13. ● In backend
- NewTensor converts from a Go value to a Tensor
- Build a graph of our image
- Init a session, because all Graph operations in Tensorflow are
done with sessions.
- Run the session to normalize image, using input and output.
normalized[0] contains normalized Tensor.
- In makeTransformImageGraph we define the rules of
normalization.
Golang https://github.com/sangam14/Tenserflow-golang-
docker-image- recongnition/blob/master/main.go
14. Also let's skip those warnings:
os.Setenv("TF_CPP_MIN_LOG_LEVEL", "2")
Here we worked with pre-trained model, let's try this program with
something unusual, like ... Gopher.
docker run imgrecognition
https://i.pinimg.com/736x/12/5c/e0/125ce0baff3271761ca61843ec
cf7985.jp g
Mouse?? no! But it's possible to train our models from Go in
TensorFlow.