Giter VIP home page Giter VIP logo

caffe-ios-sample's Introduction

Caffe iOS sample

This is an example XCode project using iOS version of Caffe built by aleph7.

It also includes a class Classifier which is the cpp_classification imported from Caffe C++ example. It classifies example image as following screenshot:

sc

Dependencies

  • opencv2.framework
  • Xcode 6 (can't build with Xcode 7)

Get started

Clone it:

$ git clone --recursive [email protected]:noradaiko/caffe-ios-sample.git

Prepare model files

You need your caffemodel, deploy.prototxt, mean.binaryproto and labels.txt into model/ directory. This sample already includes files for testing except for caffemodel.

You can download BVLC CaffeNet Model from: http://dl.caffe.berkeleyvision.org/bvlc_reference_caffenet.caffemodel.

Of course, you can use your own network model if you have.

How to classify

NSString* model_file = [NSBundle.mainBundle pathForResource:@"deploy" ofType:@"prototxt" inDirectory:@"model"];
NSString* label_file = [NSBundle.mainBundle pathForResource:@"labels" ofType:@"txt" inDirectory:@"model"];
NSString* mean_file = [NSBundle.mainBundle pathForResource:@"mean" ofType:@"binaryproto" inDirectory:@"model"];
NSString* trained_file = [NSBundle.mainBundle pathForResource:@"bvlc_reference_caffenet" ofType:@"caffemodel" inDirectory:@"model"];
string model_file_str = std::string([model_file UTF8String]);
string label_file_str = std::string([label_file UTF8String]);
string trained_file_str = std::string([trained_file UTF8String]);
string mean_file_str = std::string([mean_file UTF8String]);

UIImage* example = [UIImage imageNamed:@"image_0002.jpg"];

cv::Mat src_img;
UIImageToMat(example, src_img);

Classifier classifier = Classifier(model_file_str, trained_file_str, mean_file_str, label_file_str);
std::vector<Prediction> result = classifier.Classify(src_img);

Output into console:

for (std::vector<Prediction>::iterator it = result.begin(); it != result.end(); ++it) {
  NSString* label = [NSString stringWithUTF8String:it->first.c_str()];
  NSNumber* probability = [NSNumber numberWithFloat:it->second];
  NSLog(@"label: %@, prob: %@", label, probability);
}

License and Citation

This example

BSD 2-Clause license

Caffe

Caffe is released under the BSD 2-Clause license. The BVLC reference models are released for unrestricted use.

Please cite Caffe in your publications if it helps your research:

@article{jia2014caffe,
  Author = {Jia, Yangqing and Shelhamer, Evan and Donahue, Jeff and Karayev, Sergey and Long, Jonathan and Girshick, Ross and Guadarrama, Sergio and Darrell, Trevor},
  Journal = {arXiv preprint arXiv:1408.5093},
  Title = {Caffe: Convolutional Architecture for Fast Feature Embedding},
  Year = {2014}
}

caffe-ios-sample's People

Contributors

craftzdog avatar

Watchers

James Cloos avatar Jeremy Vizzini 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.