KleinYuan / Caffe2-iOS

Caffe2 on iOS Real-time Demo. Test with Your Own Model and Photos.
MIT License
227 stars 45 forks source link
ai caffe caffe2 caffe2-ios classification deep-learning deep-learning-mobile deep-neural-networks demo ios object-detection objective-c opencv real-time swift swift3 tiny-yolo tutorial upload-images yolo

Slack Channel for Deep Learning Communication:

https://deep-learning-geeks-slack.herokuapp.com/

Caffe2-iOS

This is a project to demo how to use Caffe2/OpenCV 2 to build an iOS application doing real time object classification.

Demo

If you are too lazy to build this repo, I also put this in App Store:

Check it out

Wiki

Check our Wiki

Feel free to ask any questions from prepare environment to debug on Xcode and we are happy to help you.

For both Beginners and Experts

We provide two stable versions in here with:

Static Classifier Real Time Classifier Model Downloader
static realtime downloader
Static Classifier Real Time Classifier
static realtime

Dependencies

You have to use a Mac with Xcode >= 8.0 (macOS Sierra) to keep going

iOS 10

Caffe2

OpenCV 2

LFS Clone

brew install git-lfs
git lfs install
git lfs clone https://github.com/KleinYuan/Caffe2-iOS

Step by Step Tutorial

Validation and debug

There are some potential issues that you will have (I will keep adding if I sense some in issues):

Caffe2 iOS Build failed

1-a. Error Message 1: When build project in Xcode you see this error Cannot find caffe2/proto/caffe2.pb.h

1-b. Error Message 2: When running setup.sh you see this in terminal ${YOUR_PATH}/Caffe2-iOS/src/caffe2/third_party/protobuf/cmake: is a directory

  1. Description: Those two are related and all because that you failed to build the caffe2 ios and check this folder architecture to validate your build (you should be able to see the caffe2.pb.h)

  2. Debug and how to fix it: Mostly, the root cause is that your cmake is broken (not broken broken, more like configuration/path changed by other services/software) and you probably wanna run brew install cmake to reinstall it

Load model failed or thread killed in the mid

  1. Error Message: Reading dangerously large protocol message. If the message turns out to be larger than 67108864 bytes, parsing will be halted for security reasons. To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.

  2. Description: As you can see in the caffe2 repo, that they reduced the protobuf, which is the tool they use to hanlde the communication down to version 3.1.0 and only have 64MB limit. Therefore, when you load a model larger than that, boooooomb, memory exploed and thread got killed.

  3. Debug and how to fix it:

    • [X] After you download and build the caffe2, hold on and modify something to increase the limit first

    • [X] Find this file, which is the tool they use to hanlde the communication down to version 3.1.0 and only have 64MB and change the limit to whatever you want (also change the warning limit)

    • [X] Then build caffe2-ios and Tada

    • [X] Alternative method see here

Performance

The initial slope is for a static 4KB image, around 50 MB and Note that memory usage in live mode might not be the same as the one shown in Xcode (slightly different). And also, remember the memory data in the app is aggregated and therefore, if you are really interested in checking performance of a specific process, open Xcode :)

memorycomsuptionhighres

More Caffe2 Mobile Models

Check here

Future Work

We have a clear scope for this repo below:

Scope

OtherUseful resources links

Caffe2-on-iOS-install

Caffe2-repo

License

License