Coder Social home page Coder Social logo

ecode-ethiopia / tensorflow-hotornot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from makorowy/tensorflow-hotornot

0.0 2.0 0.0 27.54 MB

This is an example of how to use TensorFlow library to classify images.

License: Other

Kotlin 100.00%

tensorflow-hotornot's Introduction

TensorFlow - Hot or Not?

This is an example of how to use TensorFlow library on Android to classify images. You can find the code explanation in details on my blog post. If you're interested how the model was created, you can read about it on my other blog post.


Presentation

The example was created for the presentation purpose which you can find here.

Usage

Flow of the app is pretty simple:

  1. Take a photo.
  2. Classify if it's hot or not.
  3. Show the results.

Code structure

The app consists of two main components:

  1. MainActivity which is responsible for taking a photo.
  2. ImageClassifier which classifies the photo.

Classifier

ImageClassifier properties:

  • inputName - the name of the classifier's input (the photo pixels goes in there),
  • outputName - the name of the classifier's output (the results can be found there),
  • imageSize - the size of the photo,
  • labels - the list of the labels (in our case "hot" and "not"),
  • imageBitmapPixels - the array with bitmap pixels (int values before normalization),
  • imageNormalizedPixels - the array with normalized pixels,
  • results - the list with the results,
  • tensorFlowInference - the TensorFlow API object (which is used for inference).

Classification process

For classifying photos the app is using retrained MobileNet model. The model can be found inside the assets folder together with the labels file.

Before classification the photo needs to be prepared to fit the input of the classifier which is 224x224 pixels. Because of that the photo is resized and cropped which is happening inside the ImageUtils.

Prepared photo is passed to the ImageClassifier. The class responsibilities are as follows:

  1. Nomalizing pixels of the photo - preprocessImageToNormalizedFloats() method.
  2. Classifying - classifyImageToOutputs() method.
  3. Getting the results - getResults() method.

For the classification process the instance of the TensorFlowInferenceInterface is used. The classification looks as follows:

  1. Put the data to the classifier:
    tensorFlowInference.feed(inputName, imageNormalizedPixels, 1L, imageSize, imageSize, COLOR_CHANNELS.toLong())
  2. Run the classifier:
    tensorFlowInference.run(arrayOf(outputName), ENABLE_LOG_STATS)
  3. Get the results from the output:
    tensorFlowInference.fetch(outputName, results)

The results are then passed to the MainActivity and shown on the screen.

License

Apache 2.0

tensorflow-hotornot's People

Watchers

James Cloos avatar  avatar

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.