Giter VIP home page Giter VIP logo

caffe2-ios's Introduction

☕️ Caffe2Kit

Caffe2 for iOS. A simple integration into existing projects.

Caffe2Kit - Simple integration of Caffe2 on iOS.

Twitter Caffe2 Req

🚨 Attention

Please note that this pod is in a very early stage and currently has multiple shortcomings:

  • Not officially on CocoaPods yet!
  • Only runs on iOS 10.3! -- should be fixed soon by udating the build_ios_pod.sh build script
  • Wrapper currently only supports classification tasks.

📲 Installation

Caffe2Kit is will soon be available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Caffe2Kit', :git => 'git://github.com/RobertBiehl/caffe2-ios'

and run pod install.

Disable Bitcode

Since caffe2 is not yet built with bitcode support you need to add this to your Podfile

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end

and disable bitcode for your Target by setting Build Settings -> Enable Bitcode to No.

Additional steps:

These steps will hopefully be removed in later versions.

  1. in Build Phases -> Your Target -> Link Binary with Libraries add libstdc++.tdb.
  2. in Build Settings -> Other Linker Flags remove $(inherited)and -force_load "$(PODS_ROOT)/Caffe2Kit/install/lib/libCaffe2_CPU.a"

🚀 Using Caffe2Kit

import Caffe2Kit

do {
  let caffe = try Caffe2(initNetNamed: "squeeze_init_net", predictNetNamed:"squeeze_predict_net")
  let 🌅 = #imageLiteral(resourceName: "lion.png")

  if let res = self.caffe?.prediction(regarding:🌅) {
  // find top 5 classes
  let sorted = res
    .map{$0.floatValue}
    .enumerated()
    .sorted(by: {$0.element > $1.element})[0...5]

  // generate output
  let text = sorted
    .map{"\($0.offset): \(classes[$0.offset]) \($0.element*100)%"}
    .joined(separator: "\n")

  print("Result\n \(text)")
} catch _ {
  // model could not be loaded
}

Result:

291: 🦁 lion, king of beasts, Panthera leo 100.0%
373: 🐒 macaque 3.59472e-08%
231: 🐕 collie 4.77662e-09%
374: 🐒 langur 1.63787e-09%
371: 🐒 patas, hussar monkey, Erythrocebus patas 5.34424e-10%
259: 🐶 Pomeranian 2.12385e-10%

⏱ Performance

Prediciting the class in the example app examples/Caffe2Test takes approx, 2ms on an iPhone 7 Plus and 6ms on an iPhone 6.

✅ Requirements

Deployment target of your App is >= iOS 10.3

🤖 Author(s)

Robert Biehl, [email protected]

📄 License

Caffe2Kit is available under the Apache License 2.0. See the LICENSE file for more info.

Caffe2 is released under the BSD 2-Clause license.

caffe2-ios's People

Contributors

abjurato avatar robertbiehl avatar

Stargazers

 avatar

Watchers

 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.