SlideShare a Scribd company logo
1 of 31
Download to read offline
Swift for Tensorflow
Next-Generation Platform
Tensorflow Python Swift
•
•
• Tensorflow
•
• Tensorflow goal
• Why Swift for Tensorflow?
• Swift Python
• Tensorflow Python Swift
•
•
Swift for Tensorflow
Google I/O 2019 5. 8.TensorFlow Dev Summit 2019 3. 6.
• Python Tensorflow Swift "Next-generation platform" .
• Tensorflow Swift ?
-
.
- Swift Python (Expressive, Writability) ?
.
- Swift Python ?
Tensorflow Python Ecosystem( , , ) Swift ?
Tensorflow
Tensorflow
• Tensorflow 

Python Javascript Swift
• CPU/GPU . Google TPU(Tensor Processing Unit)
. .
• Tensorflow Data Flow Graph .
Data Flow Graph
• (Node) (Edge)
(Directed Graph) .
• , , / .
• .
• (=Tensor) ,
(Tensor Flow) .
Tensorflow goal
Tensorflow .
• High Performance
• Writability(Expressiveness)
• Performance Predictability
• Debuggability and Introspection
• High-End User Experience
• Best-of-class Automatic Differentiation (AD)
Swift vs Python
Python
• Community: .
• Open-source and cross-platform
• Shallow learning curve: , .
• High productivity
• Ecosystem: Numpy, Pandas, …
Python
• Performance: Python C++ Tensorflow .
• Concurrency: GIL(Global Interpreter Lock) . 

Mutex lock.
• Deployment: Python . . 

Tensorflow .(Caffe-C++, TF Lite-Android, CoreML-iOS)
• Custom Operations: C++, CUDA .
From WhySwiftForTensorFlow.md
Swift
• Swift iOS macOS , 2014 6 2 WWDC .
• OS Objective-C 

LLVM(Low-Level Virtual Machine) .
• Strong type language, Optional Type .
• 2019 4 18 Swift 5.0
Swift
• Type Safe
• Enable Automatic Differentiation in compile time
• Python Interoperability
In machine learning aspect
Type safe - Optional
• Compile-time .
• .
• Type '?'
• : , (nil)
• NullPointerException compile-time .
var optionalInt1: Int = nil // error
var optionalInt2: Int? = nil // correct
Automatic Differentiation ( )
• .
• Automatic Differentiation .
• (derivative) . (Runtime)
• gradient-based . ex) (Linear Regression)
Automatic Differentiation
• .
• Swift Compile-time
@differentiable
@differentiable
func square1(_ x: Float) -> Float {
return x * x
}
@differentiable
func square2(_ x: Float) -> Float {
return x * x * x * x
}
let x: Float = 3.0
print(gradient(at: x, in: square1)) // x^2, 6.0
print(gradient(at: x, in: square2)) // 4*x^3, 108.0
Python Interoperability
// NumPy example:
import Python
let np = Python.import("numpy") // import numpy as np
let a = np.arange(15).reshape(3, 5) // a = np.arange(15).reshape(3, 5)
let b = np.array([6, 7, 8]) // b = np.array([6, 7, 8])
// Pickle example:
let gzip = Python.import("gzip") // import gzip as gzip
let pickle = Python.import("pickle") // import pickle as pickle
let file = gzip.open("mnist.pkl.gz", "rb") // file = gzip.open("mnist.pkl.gz", "rb")
// (images, labels) = pickle.load(file)
let (images, labels) = pickle.load(file).tuple2
print(images.shape) // (50000, 784) print(images.shape)
Swift
• Performance
• Concurrency
Swift C-based low-level .
Swift compile , .
Tensorflow Swift Tensor compile-time .
Swift pthread API . Python .
Swift Dispatch() (async/await) .
Disadvantages of Swift
• New language: Swift , Python native .
• Windows support: BSD, Linux, UNIX .
• Small data-science community: Python data-science .
Swift vs Python in MNIST Example
MNIST
• Softmax-regression .
• Layer vector .
• bias .
• Softmax-regression .
Softmax Regression
• Multi-class Classification Model
• Probability = [0.1, 0.2, 0.8, … 0.6, 0.1, 0.0] 1 .
Softmax Regression
Gradient Descent
=
Swift
struct MNISTParameters : ParameterGroup {
var w1 = Tensor<Float>(randomNormal: [784, 30])
var w2 = Tensor<Float>(randomNormal: [30, 10])
var b1 = Tensor<Float>(zeros: [1, 30])
var b2 = Tensor<Float>(zeros: [1, 10])
}
let iterationCount = Int32(batchSize) / minibatchSize
for i in 0..<iterationCount {
let images = minibatch(images, index: i)
let numericLabels = minibatch(numericLabels, index: i)
let labels = minibatch(labels, index: i)
let z1 = images • parameters.w1 + parameters.b1
let h1 = sigmoid(z1)
let z2 = h1 • parameters.w2 + parameters.b2
let predictions = sigmoid(z2)
let dz2 = predictions - labels
let dw2 = h1.transposed() • dz2
let db2 = dz2.sum(squeezingAxes: 0)
let dz1 = matmul(dz2, parameters.w2.transposed()) * h1 * (1 - h1)
let dw1 = images.transposed() • dz1
let db1 = dz1.sum(squeezingAxes: 0)
let gradients = MNISTParameters(w1: dw1, w2: dw2, b1: db1, b2: db2)
parameters.update(withGradients: gradients) { param, grad in
param -= grad * learningRate
}
let correctPredictions = predictions.argmax(squeezingAxis: 1).elementsEqual(numericLabels)
correctGuesses += Int(Tensor<Int32>(correctPredictions).sum())
totalGuesses += Int(minibatchSize)
}
Python
X = tf.placeholder(tf.float32, [None, 784])
Y = tf.placeholder(tf.float32, [None, 10])
W1 = tf.Variable(tf.random_normal([784, 256], stddev=0.01))
L1 = tf.nn.relu(tf.matmul(X, W1))
W2 = tf.Variable(tf.random_normal([256, 256], stddev=0.01))
L2 = tf.nn.relu(tf.matmul(L1, W2))
W3 = tf.Variable(tf.random_normal([256, 10], stddev=0.01))
model = tf.matmul(L2, W3)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(logits=model, labels=Y))
total_batch = int(mnist.train.num_examples / batch_size)
for epoch in range(15):
total_cost = 0
for i in range(total_batch):
batch_xs, batch_ys = mnist.train.next_batch(batch_size)
_, cost_val = sess.run([optimizer, cost], feed_dict={X: batch_xs, Y: batch_ys})
total_cost += cost_val
https://youtu.be/5ttySH7CppA
Swift for TensorFlow MNIST Example
Which one is Next-generation platform?
Swift is Next-generation platform of TensorFlow

But, Python is still dominient.

Python and Swift are in a complement relationship
• Tensorflow github : https://github.com/tensorflow/
• Swift for Tensorflow github : https://github.com/tensorflow/swift
• Swift for Tensorflow : https://www.tensorflow.org/swift
• Swift for Tensorflow Design Overview : https://github.com/tensorflow/swift/blob/master/docs/
DesignOverview.md
• Why Swift for Tensorflow? : https://github.com/tensorflow/swift/blob/master/docs/
WhySwiftForTensorFlow.md
• Swift example : https://github.com/tensorflow/swift/blob/master/docs/site/tutorials/
model_training_walkthrough.ipynb
• https://github.com/bbvch13531/tf.swift

More Related Content

What's hot

Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlibPiyush rai
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpyFaraz Ahmed
 
Introduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersIntroduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersKimikazu Kato
 
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Edureka!
 
Beyond tf idf why, what & how
Beyond tf idf why, what & howBeyond tf idf why, what & how
Beyond tf idf why, what & howlucenerevolution
 
Introduction to PyTorch
Introduction to PyTorchIntroduction to PyTorch
Introduction to PyTorchJun Young Park
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101Ankur Gupta
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyKimikazu Kato
 
Queue implementation
Queue implementationQueue implementation
Queue implementationRajendran
 
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with MayaviScientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with MayaviEnthought, Inc.
 
미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정SeungChul Kang
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Platonov Sergey
 
Pythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPaulo Sergio Lemes Queiroz
 
Machine learning with scikit-learn
Machine learning with scikit-learnMachine learning with scikit-learn
Machine learning with scikit-learnQingkai Kong
 

What's hot (20)

NumPy/SciPy Statistics
NumPy/SciPy StatisticsNumPy/SciPy Statistics
NumPy/SciPy Statistics
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlib
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpy
 
Matplotlib
MatplotlibMatplotlib
Matplotlib
 
Introduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersIntroduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning Programmers
 
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
 
Beyond tf idf why, what & how
Beyond tf idf why, what & howBeyond tf idf why, what & how
Beyond tf idf why, what & how
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
Welcome to python
Welcome to pythonWelcome to python
Welcome to python
 
Introduction to PyTorch
Introduction to PyTorchIntroduction to PyTorch
Introduction to PyTorch
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPy
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with MayaviScientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
 
미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
 
Lec1
Lec1Lec1
Lec1
 
Pythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPU
 
Machine learning with scikit-learn
Machine learning with scikit-learnMachine learning with scikit-learn
Machine learning with scikit-learn
 

Similar to Swift for tensorflow

Numba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPyNumba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPyTravis Oliphant
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimizationg3_nittala
 
Python高级编程(二)
Python高级编程(二)Python高级编程(二)
Python高级编程(二)Qiangning Hong
 
190111 tf2 preview_jwkang_pub
190111 tf2 preview_jwkang_pub190111 tf2 preview_jwkang_pub
190111 tf2 preview_jwkang_pubJaewook. Kang
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and SparkOswald Campesato
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CSteffen Wenz
 
Scientific visualization with_gr
Scientific visualization with_grScientific visualization with_gr
Scientific visualization with_grJosef Heinen
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...GeeksLab Odessa
 
Scaling Python to CPUs and GPUs
Scaling Python to CPUs and GPUsScaling Python to CPUs and GPUs
Scaling Python to CPUs and GPUsTravis Oliphant
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Qiangning Hong
 
Seven waystouseturtle pycon2009
Seven waystouseturtle pycon2009Seven waystouseturtle pycon2009
Seven waystouseturtle pycon2009A Jorge Garcia
 
Apache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmapApache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmapKostas Tzoumas
 
Python-GTK
Python-GTKPython-GTK
Python-GTKYuren Ju
 
Kyo - Functional Scala 2023.pdf
Kyo - Functional Scala 2023.pdfKyo - Functional Scala 2023.pdf
Kyo - Functional Scala 2023.pdfFlavio W. Brasil
 
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
Business Dashboards using Bonobo ETL, Grafana and Apache AirflowBusiness Dashboards using Bonobo ETL, Grafana and Apache Airflow
Business Dashboards using Bonobo ETL, Grafana and Apache AirflowRomain Dorgueil
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Yuren Ju
 
TensorFlow for IITians
TensorFlow for IITiansTensorFlow for IITians
TensorFlow for IITiansAshish Bansal
 
Tensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi chaTensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi chaDonghwi Cha
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsMichael Pirnat
 
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward
 

Similar to Swift for tensorflow (20)

Numba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPyNumba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPy
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 
Python高级编程(二)
Python高级编程(二)Python高级编程(二)
Python高级编程(二)
 
190111 tf2 preview_jwkang_pub
190111 tf2 preview_jwkang_pub190111 tf2 preview_jwkang_pub
190111 tf2 preview_jwkang_pub
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and Spark
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
Scientific visualization with_gr
Scientific visualization with_grScientific visualization with_gr
Scientific visualization with_gr
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
 
Scaling Python to CPUs and GPUs
Scaling Python to CPUs and GPUsScaling Python to CPUs and GPUs
Scaling Python to CPUs and GPUs
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
 
Seven waystouseturtle pycon2009
Seven waystouseturtle pycon2009Seven waystouseturtle pycon2009
Seven waystouseturtle pycon2009
 
Apache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmapApache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmap
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
 
Kyo - Functional Scala 2023.pdf
Kyo - Functional Scala 2023.pdfKyo - Functional Scala 2023.pdf
Kyo - Functional Scala 2023.pdf
 
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
Business Dashboards using Bonobo ETL, Grafana and Apache AirflowBusiness Dashboards using Bonobo ETL, Grafana and Apache Airflow
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
 
TensorFlow for IITians
TensorFlow for IITiansTensorFlow for IITians
TensorFlow for IITians
 
Tensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi chaTensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi cha
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
 

More from 규영 허

スケーラブル SwiftUI プロジェクトにおける実用的な TCA モジュラー化
スケーラブル SwiftUI プロジェクトにおける実用的な TCA モジュラー化スケーラブル SwiftUI プロジェクトにおける実用的な TCA モジュラー化
スケーラブル SwiftUI プロジェクトにおける実用的な TCA モジュラー化규영 허
 
LLVM UB Optimization
LLVM UB OptimizationLLVM UB Optimization
LLVM UB Optimization규영 허
 
프로그래머의 뇌
프로그래머의 뇌프로그래머의 뇌
프로그래머의 뇌규영 허
 
SwiftUI와 TCA로 GitHub Search앱 만들기
SwiftUI와 TCA로 GitHub Search앱 만들기SwiftUI와 TCA로 GitHub Search앱 만들기
SwiftUI와 TCA로 GitHub Search앱 만들기규영 허
 
Chromium에 contribution하기
Chromium에 contribution하기Chromium에 contribution하기
Chromium에 contribution하기규영 허
 

More from 규영 허 (6)

スケーラブル SwiftUI プロジェクトにおける実用的な TCA モジュラー化
スケーラブル SwiftUI プロジェクトにおける実用的な TCA モジュラー化スケーラブル SwiftUI プロジェクトにおける実用的な TCA モジュラー化
スケーラブル SwiftUI プロジェクトにおける実用的な TCA モジュラー化
 
LLVM UB Optimization
LLVM UB OptimizationLLVM UB Optimization
LLVM UB Optimization
 
프로그래머의 뇌
프로그래머의 뇌프로그래머의 뇌
프로그래머의 뇌
 
SwiftUI와 TCA로 GitHub Search앱 만들기
SwiftUI와 TCA로 GitHub Search앱 만들기SwiftUI와 TCA로 GitHub Search앱 만들기
SwiftUI와 TCA로 GitHub Search앱 만들기
 
Influencer
InfluencerInfluencer
Influencer
 
Chromium에 contribution하기
Chromium에 contribution하기Chromium에 contribution하기
Chromium에 contribution하기
 

Recently uploaded

(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 

Recently uploaded (20)

(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 

Swift for tensorflow

  • 1. Swift for Tensorflow Next-Generation Platform Tensorflow Python Swift
  • 2. • • • Tensorflow • • Tensorflow goal • Why Swift for Tensorflow? • Swift Python • Tensorflow Python Swift • •
  • 3. Swift for Tensorflow Google I/O 2019 5. 8.TensorFlow Dev Summit 2019 3. 6.
  • 4. • Python Tensorflow Swift "Next-generation platform" . • Tensorflow Swift ?
  • 5. - . - Swift Python (Expressive, Writability) ? . - Swift Python ? Tensorflow Python Ecosystem( , , ) Swift ?
  • 7. Tensorflow • Tensorflow 
 Python Javascript Swift • CPU/GPU . Google TPU(Tensor Processing Unit) . . • Tensorflow Data Flow Graph .
  • 8. Data Flow Graph • (Node) (Edge) (Directed Graph) . • , , / . • . • (=Tensor) , (Tensor Flow) .
  • 9. Tensorflow goal Tensorflow . • High Performance • Writability(Expressiveness) • Performance Predictability • Debuggability and Introspection • High-End User Experience • Best-of-class Automatic Differentiation (AD)
  • 11. Python • Community: . • Open-source and cross-platform • Shallow learning curve: , . • High productivity • Ecosystem: Numpy, Pandas, …
  • 12. Python • Performance: Python C++ Tensorflow . • Concurrency: GIL(Global Interpreter Lock) . 
 Mutex lock. • Deployment: Python . . 
 Tensorflow .(Caffe-C++, TF Lite-Android, CoreML-iOS) • Custom Operations: C++, CUDA . From WhySwiftForTensorFlow.md
  • 13. Swift • Swift iOS macOS , 2014 6 2 WWDC . • OS Objective-C 
 LLVM(Low-Level Virtual Machine) . • Strong type language, Optional Type . • 2019 4 18 Swift 5.0
  • 14. Swift • Type Safe • Enable Automatic Differentiation in compile time • Python Interoperability In machine learning aspect
  • 15. Type safe - Optional • Compile-time . • . • Type '?' • : , (nil) • NullPointerException compile-time . var optionalInt1: Int = nil // error var optionalInt2: Int? = nil // correct
  • 16. Automatic Differentiation ( ) • . • Automatic Differentiation . • (derivative) . (Runtime) • gradient-based . ex) (Linear Regression)
  • 18. @differentiable @differentiable func square1(_ x: Float) -> Float { return x * x } @differentiable func square2(_ x: Float) -> Float { return x * x * x * x } let x: Float = 3.0 print(gradient(at: x, in: square1)) // x^2, 6.0 print(gradient(at: x, in: square2)) // 4*x^3, 108.0
  • 19. Python Interoperability // NumPy example: import Python let np = Python.import("numpy") // import numpy as np let a = np.arange(15).reshape(3, 5) // a = np.arange(15).reshape(3, 5) let b = np.array([6, 7, 8]) // b = np.array([6, 7, 8]) // Pickle example: let gzip = Python.import("gzip") // import gzip as gzip let pickle = Python.import("pickle") // import pickle as pickle let file = gzip.open("mnist.pkl.gz", "rb") // file = gzip.open("mnist.pkl.gz", "rb") // (images, labels) = pickle.load(file) let (images, labels) = pickle.load(file).tuple2 print(images.shape) // (50000, 784) print(images.shape)
  • 20. Swift • Performance • Concurrency Swift C-based low-level . Swift compile , . Tensorflow Swift Tensor compile-time . Swift pthread API . Python . Swift Dispatch() (async/await) .
  • 21. Disadvantages of Swift • New language: Swift , Python native . • Windows support: BSD, Linux, UNIX . • Small data-science community: Python data-science .
  • 22. Swift vs Python in MNIST Example
  • 23. MNIST • Softmax-regression . • Layer vector . • bias . • Softmax-regression .
  • 24. Softmax Regression • Multi-class Classification Model • Probability = [0.1, 0.2, 0.8, … 0.6, 0.1, 0.0] 1 .
  • 27. Swift struct MNISTParameters : ParameterGroup { var w1 = Tensor<Float>(randomNormal: [784, 30]) var w2 = Tensor<Float>(randomNormal: [30, 10]) var b1 = Tensor<Float>(zeros: [1, 30]) var b2 = Tensor<Float>(zeros: [1, 10]) } let iterationCount = Int32(batchSize) / minibatchSize for i in 0..<iterationCount { let images = minibatch(images, index: i) let numericLabels = minibatch(numericLabels, index: i) let labels = minibatch(labels, index: i) let z1 = images • parameters.w1 + parameters.b1 let h1 = sigmoid(z1) let z2 = h1 • parameters.w2 + parameters.b2 let predictions = sigmoid(z2) let dz2 = predictions - labels let dw2 = h1.transposed() • dz2 let db2 = dz2.sum(squeezingAxes: 0) let dz1 = matmul(dz2, parameters.w2.transposed()) * h1 * (1 - h1) let dw1 = images.transposed() • dz1 let db1 = dz1.sum(squeezingAxes: 0) let gradients = MNISTParameters(w1: dw1, w2: dw2, b1: db1, b2: db2) parameters.update(withGradients: gradients) { param, grad in param -= grad * learningRate } let correctPredictions = predictions.argmax(squeezingAxis: 1).elementsEqual(numericLabels) correctGuesses += Int(Tensor<Int32>(correctPredictions).sum()) totalGuesses += Int(minibatchSize) }
  • 28. Python X = tf.placeholder(tf.float32, [None, 784]) Y = tf.placeholder(tf.float32, [None, 10]) W1 = tf.Variable(tf.random_normal([784, 256], stddev=0.01)) L1 = tf.nn.relu(tf.matmul(X, W1)) W2 = tf.Variable(tf.random_normal([256, 256], stddev=0.01)) L2 = tf.nn.relu(tf.matmul(L1, W2)) W3 = tf.Variable(tf.random_normal([256, 10], stddev=0.01)) model = tf.matmul(L2, W3) cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(logits=model, labels=Y)) total_batch = int(mnist.train.num_examples / batch_size) for epoch in range(15): total_cost = 0 for i in range(total_batch): batch_xs, batch_ys = mnist.train.next_batch(batch_size) _, cost_val = sess.run([optimizer, cost], feed_dict={X: batch_xs, Y: batch_ys}) total_cost += cost_val
  • 30. Which one is Next-generation platform? Swift is Next-generation platform of TensorFlow But, Python is still dominient. Python and Swift are in a complement relationship
  • 31. • Tensorflow github : https://github.com/tensorflow/ • Swift for Tensorflow github : https://github.com/tensorflow/swift • Swift for Tensorflow : https://www.tensorflow.org/swift • Swift for Tensorflow Design Overview : https://github.com/tensorflow/swift/blob/master/docs/ DesignOverview.md • Why Swift for Tensorflow? : https://github.com/tensorflow/swift/blob/master/docs/ WhySwiftForTensorFlow.md • Swift example : https://github.com/tensorflow/swift/blob/master/docs/site/tutorials/ model_training_walkthrough.ipynb • https://github.com/bbvch13531/tf.swift