Giter Club home page Giter Club logo

yolov2_tf_ios's Introduction

What

This repo contains a sample iOS app that runs with a 80-class COCO trained tiny-yolo model and the TensorFlow libraries to do object detection and show the detected results and the bounding boxes. An iOS app based on the repo has been published and available for free download here.

Please check out my blog for the latest info on this app and tutorials on other TensorFlow mobile apps.

How

  1. Download the TensorFlow 1.2 source here;

  2. Build the TensorFlow iOS libraries by following the instructions here. After that, you'll see libprotobuf.a and libprotobuf-lite.a in tensorflow/contrib/makefile/gen/protobuf_ios/lib/, and libtensorflow-core.a in tensorflow/contrib/makefile/gen/lib;

  3. Clone this repo and then move the whole folder yolov2_tf_ios to tensorflow/contrib/ios_examples/ (so the TF libraries built in step 2 will be available to the project) and open the project in Xcode;

  4. Download the OpenCV 3.2.0 iOS pack here and then drag and drop the opencv2.framework to the Xcode project - this is used for drawing bounding boxes but of course you can do so (easily) with the iOS API too. Still I included OpenCV in the project to be ready for other more advanced OpenCV based CV processing;

  5. Run the app in Xcode on simulator or device and tap the button to see results as the screenshot below.

Detected Result

Notes

  1. This repo includes two pre-trained and TF-quantized models (to reduce the model size significantly): quantized-tiny-yolo.pb and quantized-tiny-yolo-voc.pb. The first one was originally trained using the PASCAL VOC dataset for 20-class object detection, and the second one the COCO dataset for 80-class object detection. I created the pb files using Darkflow then ran bazel-bin/tensorflow/tools/quantization/quantize_graph --input=darkflow/built_graph/tiny-yolo.pb --output_node_names=output --output=quantized_tiny-yolo.pb --mode=weights and bazel-bin/tensorflow/tools/quantization/quantize_graph --input=darkflow/built_graph/tiny-yolo-voc.pb --output_node_names=output --output=quantized_tiny-yolo-voc.pb --mode=weights. Both tiny-yolo(-vos).pb and its quantized versions can run successfully on device;

  2. I also tested the yolo.pb and its quantized version - they can run OK on simulator but would crash on actual device.

Credits

The preprocessing and postprocessing of the input image tensor and output tensor in iOS with TensorFlow C++ API was finally made right after many hours of debugging, review of the original Yolo9000 paper, and the help of the following sources:

  1. Darkflow source and README;

  2. The Real-time object detection with YOLO blog;

  3. The Tensorflow Android source code of TF Detect.

yolov2_tf_ios's People

Contributors

jeffxtang 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yolov2_tf_ios's Issues

Quantization problem

Do you know the output of your .pb file from quantization is quantized or float?

Protocol buffers version mismatch

I followed the installation steps, but I get a runtime exception when running on the device:

[libprotobuf FATAL /Volumes/build-storage/build/master_iOS-mac/opencv/3rdparty/protobuf/src/google/protobuf/stubs/common.cc:67] This program requires version 3.2.0 of the Protocol Buffer runtime library, but the installed version is 3.1.0. Please update your library. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in "/Users/Peter/Downloads/tensorflow-1.2.0/tensorflow/contrib/makefile/gen/proto/tensorflow/core/util/test_log.pb.cc".) libc++abi.dylib: terminating with uncaught exception of type google::protobuf::FatalException: This program requires version 3.2.0 of the Protocol Buffer runtime library, but the installed version is 3.1.0. Please update your library. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in "/Users/Peter/Downloads/tensorflow-1.2.0/tensorflow/contrib/makefile/gen/proto/tensorflow/core/util/test_log.pb.cc".)

I tried building libprotobuf 3.2 from source but then I have a similar issue that says the library was build against 3.1.
Help would be appreciated, could you perhaps share your project?

I can't find the file of quantize_graph

I have no quantization folder inside bazel-bin/tensorflow/tools. However, I have it inside tensorflow-master/tensorflow/tools/quantization. I just removed the bazel-bin and simply put tensorflow/tools/quantization/quantize_graph and it tells me can not find the directory or file.
Do you know why it happen.
How am I able to get a quantization folder inside bazel-bin?

Remove the imagenet_comp_graph_label_strings reference

The xcodeproject references a file that does not exist and is not used within the project.
But this fie is missing which causes a compile error. The reference should probably be removed therefore:

imagenet_comp_graph_label_strings

Speed and Accuracy

Is it possible for you to share speed and accuracy measurements of the yolo on ios? I am trying to find a optimal solution for tracking, detecting on mobile phone. It seems very hard to make a real time solution.

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.