Code Monkey home page Code Monkey logo

go-tensorflow-image-recognition's Introduction

Image Recognition API in Go using TensorFlow

This is the underlying code for article Build an Image Recognition API with Go and TensorFlow.

Running the service

Build the image.

$ docker build -t localhost/recognition .

Run service in a container.

$ docker run -p 8080:8080 --rm localhost/recognition

Call the service.

$ curl localhost:8080/recognize -F 'image=@./cat.jpg'
{
  "filename": "cat.jpg",
  "labels": [
    { "label": "tabby", "probability": 0.45087516 },
    { "label": "Egyptian cat", "probability": 0.26096493 },
    { "label": "tiger cat", "probability": 0.23208225 },
    { "label": "lynx", "probability": 0.050698064 },
    { "label": "grey fox", "probability": 0.0019019963 }
  ]
}

go-tensorflow-image-recognition's People

Contributors

luisenmarroquin avatar mattn avatar tinrab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-tensorflow-image-recognition's Issues

docker-compose.yaml problem

$ docker-compose -f docker-compose.yaml up -d --build
ERROR: Version in "./docker-compose.yaml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version ("2.0", "2.1", "3.0", "3.1", "3.2") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/

MobileNet v2 support

Hi,

Hope you are all well !

I was wondering how complicated it would be to support Mobilenet v2 - ssd with your script.

What should be modified to do object detection ?

Cheers,
X

ERROR: reference to `TF_ImportGraphDefOptionsSetDefaultDevice'

Step 14/15 : RUN go get ./... && go build -o /usr/bin/app .
---> Running in 2b689073342c

github.com/tensorflow/tensorflow/tensorflow/go

/tmp/go-build057595270/b096/_x003.o: In function _cgo_691d94bb61b7_Cfunc_TF_ImportGraphDefOptionsSetDefaultDevice': /tmp/go-build/cgo-gcc-prolog:198: undefined reference to TF_ImportGraphDefOptionsSetDefaultDevice'
collect2: error: ld returned 1 exit status
ERROR: Service 'api' failed to build: The command '/bin/sh -c go get ./... && go build -o /usr/bin/app .' returned a non-zero code: 2

Support for own trained models?

First - I love this project and thanks for sharing it.

When using my own model trained by following the tutorial here for example, I get an empty response when attempting to recognize an image - curl: (52) Empty reply from server . Any support for custom trained models?

go: error loading module requirements

Hello, I git cloned this repo and try running the example based on the instructions in the readme, however there's issues with some dependencies

$ docker-compose -f docker-compose.yaml up -d --build
Building api
Step 1/16 : FROM tensorflow/tensorflow:1.9.0
 ---> caab7ec02690
Step 2/16 : RUN curl -L    "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.3.0.tar.gz" |    tar -C "/usr/local" -xz
 ---> Using cache
 ---> 159e42548844
Step 3/16 : RUN ldconfig
 ---> Using cache
 ---> acb818dd6e0d
Step 4/16 : ENV TF_CPP_MIN_LOG_LEVEL 2
 ---> Using cache
 ---> 5b5def0b688f
Step 5/16 : RUN apt-get update && apt-get install -y --no-install-recommends                g++             gcc             libc6-dev               make                pkg-config     wget     curl     git    && rm -rf /var/lib/apt/lists/*
 ---> Using cache
 ---> 40da5b287396
Step 6/16 : ENV GOLANG_VERSION 1.10.3
 ---> Using cache
 ---> 3f29629b0224
Step 7/16 : RUN set -eux;               dpkgArch="$(dpkg --print-architecture)";    case "${dpkgArch##*-}" in               amd64) goRelArch='linux-amd64'; goRelSha256='fa1b0e45d3b647c252f51f5e1204aba049cde4af177ef9f2181f43004f901035' ;;               armhf) goRelArch='linux-armv6l'; goRelSha256='d3df3fa3d153e81041af24f31a82f86a21cb7b92c1b5552fb621bad0320f06b6' ;;          arm64) goRelArch='linux-arm64'; goRelSha256='355128a05b456c9e68792143801ad18e0431510a53857f640f7b30ba92624ed2' ;;               i386) goRelArch='linux-386'; goRelSha256='3d5fe1932c904a01acb13dae07a5835bffafef38bef9e5a05450c52948ebdeb4' ;;          ppc64el) goRelArch='linux-ppc64le'; goRelSha256='f3640b2f0990a9617c937775f669ee18f10a82e424e5f87a8ce794a6407b8347' ;;               s390x) goRelArch='linux-s390x'; goRelSha256='34385f64651f82fbc11dc43bdc410c2abda237bdef87f3a430d35a508ec3ce0d' ;;               *) goRelArch='src'; goRelSha256='567b1cc66c9704d1c019c50bef946272e911ec6baf244310f87f4e678be155f2';    echo >&2; echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; echo >&2 ;;        esac;           url="https://golang.org/dl/go${GOLANG_VERSION}.${goRelArch}.tar.gz";        wget -O go.tgz "$url";  echo "${goRelSha256} *go.tgz" | sha256sum -c -;     tar -C /usr/local -xzf go.tgz;  rm go.tgz;         if [ "$goRelArch" = 'src' ]; then                echo >&2;               echo >&2 'error: UNIMPLEMENTED';            echo >&2 'TODO install golang-any from jessie-backports for GOROOT_BOOTSTRAP (and uninstall after build)';     echo >&2;                exit 1;         fi;             export PATH="/usr/local/go/bin:$PATH";   go version
 ---> Using cache
 ---> aab9b338a518
Step 8/16 : ENV GOPATH /go
 ---> Using cache
 ---> 62940c780fc2
Step 9/16 : ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
 ---> Using cache
 ---> 726bc5d09da8
Step 10/16 : RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
 ---> Using cache
 ---> 57668e3d0dba
Step 11/16 : RUN go get -u golang.org/x/vgo
 ---> Using cache
 ---> 773c58073d44
Step 12/16 : RUN mkdir -p /model &&   wget "https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip" -O /model/inception.zip &&   unzip /model/inception.zip -d /model &&   chmod -R 777 /model
 ---> Using cache
 ---> 3a5ea3b1f9e3
Step 13/16 : WORKDIR "/go/src/github.com/tinrab/go-tensorflow-image-recognition"
 ---> Using cache
 ---> 8d79f0a4c757
Step 14/16 : COPY . .
 ---> Using cache
 ---> e07ebda3bb84
Step 15/16 : RUN vgo build -o /usr/bin/app .
 ---> Running in 5168ace03ce3
go: finding github.com/julienschmidt/httprouter v0.0.0-20180411154501-adbc77eec0d9
go: finding github.com/tensorflow/tensorflow v1.9.0
go: github.com/julienschmidt/[email protected]: unknown revision adbc77eec0d9
go: github.com/tensorflow/[email protected]: unknown revision refs/tags/v1.9.0
go: error loading module requirements
ERROR: Service 'api' failed to build: The command '/bin/sh -c vgo build -o /usr/bin/app .' returned a non-zero code: 1

Any help is appreciated

nil-operation tensorflow problem

Hi Tin!

I am trying to run your code and when I send image via curl to the server getting following issue:

http: panic serving [::1]:57414: nil-Operation. If the Output was created with a Scope object, see Scope.Err() for details.

Please note that I did not work with TF before, so I am sorry if the answer to my issue is too obvious.

lp :)

similarity search

Is it possible to return the vector before the classify layer, so that it can also be used for image similarity?

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.