Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TensorFlow Neural Networks on iOS

TensorFlow Neural Networks on iOS

Slides from my 360iDev presentation on neural networks, CoreML and TensorFlow on iOS: https://360idev.com/sessions/tensorflow-neural-networks-ios/

Taylan Pince

August 15, 2017
Tweet

More Decks by Taylan Pince

Other Decks in Technology

Transcript

  1. Using TensorFlow, CoreML, Metal Performance Shaders, Accelerate BNNs, Keras and

    What the Heck is a Neural Network Anyway? Taylan Pince
  2. if x + y > b { return blue }

    else { return orange }
  3. if (xWeight * x) + (yWeight * y) > b

    { return blue } else { return orange }
  4. import tensorflow as tf matrix_size = 224 * 224 category_size

    = 150 with tf.name_scope("data"): d1 = tf.placeholder(tf.float32, [None, matrix_size], name="image_data") d2 = tf.placeholder(tf.float32, [None, category_size], name="category_data") with tf.name_scope("model"): weights = tf.Variable(tf.zeros([matrix_size, category_size]), name="weights") bias = tf.Variable(tf.zeros([category_size]), name="bias")
  5. pb

  6. tensorflow::GraphDef graph; tensorflow::Session *session; ReadBinaryProto(tensorflow::Env::Default(), path, &graph); tensorflow::NewSession(options, &session); session->Create(graph);

    tensorflow::Tensor x( tensorflow::DT_FLOAT, tensorflow::TensorShape({ 1, 224 * 224 }) ); std::vector<tensorflow::Tensor> outputs; session->Run(inputs, nodes, {}, &outputs);
  7. Limited support for training engines and layer types Custom models

    need conversion Picks CPU or GPU automatically
  8. let model = VNCoreMLModel(for: graph().model) let request = VNCoreMLRequest(model: model)

    { [unowned self] request, error in results.forEach({ (result) in print("\(result.identifier)") }) } } let handler = VNImageRequestHandler(ciImage: image) DispatchQueue.global(qos: .userInitiated).async { do { try handler.perform([request]) } catch { print(error) } }
  9. Convert pb file into a binary Metal can read: A

    list of floating point numbers
  10. Recap Train with TensorFlow + Keras Use CoreML if you

    can Use TF if you need multi-platform