Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
从 Swift 到机器学习
Search
Wei Wang
September 15, 2018
Programming
2
970
从 Swift 到机器学习
Wei Wang
September 15, 2018
Tweet
Share
More Decks by Wei Wang
See All by Wei Wang
網路之難,難於上青天 - iPlayground 2019
onevcat
11
5k
GMTC 2019 - 在分歧中发展,2019 我们能用 Swift 做什么
onevcat
0
990
iOS Dev - The Dark Side
onevcat
0
130
面向协议编程与 Cocoa 的邂逅
onevcat
14
4.8k
Swift 3 - From Expert to Beginner
onevcat
2
210
如何打造一个让人愉快的框架
onevcat
4
22k
JSPatch Introduction
onevcat
0
180
Objective-C Runtime Swizzle
onevcat
0
190
Unity Memory
onevcat
0
130
Other Decks in Programming
See All in Programming
Building Scalable Mobile Projects: Fast Builds, High Reusability and Clear Ownership
cyrilmottier
2
240
AI Agents with JavaScript
slobodan
0
210
小さく段階的リリースすることで深夜メンテを回避する
mkmk884
2
160
Django for Data Science (Boston Python Meetup, March 2025)
wsvincent
0
310
custom_lintで始めるチームルール管理
akaboshinit
0
200
State of Namespace
tagomoris
3
330
Going Structural with Named Tuples
bishabosha
0
200
新しいPHP拡張モジュールインストール方法「PHP Installer for Extensions (PIE)」を使ってみよう!
cocoeyes02
0
290
複数ドメインに散らばってしまった画像…! 運用中のPHPアプリに後からCDNを導入する…!
suguruooki
0
460
The Weight of Data: Rethinking Cloud-Native Systems for the Age of AI
hollycummins
0
260
Boost Your Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
1.1k
5年間継続して開発した自作OSSの記録
bebeji_nappa
0
140
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.4k
Product Roadmaps are Hard
iamctodd
PRO
52
11k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7.2k
Music & Morning Musume
bryan
47
6.5k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Why Our Code Smells
bkeepers
PRO
336
57k
Java REST API Framework Comparison - PWX 2021
mraible
29
8.5k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.3k
Unsuck your backbone
ammeep
670
57k
How STYLIGHT went responsive
nonsquared
99
5.5k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Navigating Team Friction
lara
184
15k
Transcript
从 Swift 到 机器器学习 CreateML - Swifter 通向 ML 的⾦金金钥匙
王 巍 (onevcat) 2018.09.15, @Swift Conf.
后移动开发时代 Google Trends: “iOS Develop”
WWDC 2013
转变⼀一般都会带来痛苦
如何评价 2017 年年初华为开始「清理理」34 岁以上的职员? 程序员能纯靠技术渡过中年年危机吗? 程序员30岁之前年年薪不不到40W,再不不转⾏行行都晚了了? iOS 末路路了了吗,我找⼯工作两个⽉月,没⼈人要 35 岁做不不到管理理就等于失业
我(们)的出路路在哪⾥里里
我(们)的出路路在哪⾥里里 ⼤大前端 React Native Weex ⼩小程序 Flutter 机器器学习 深度学习 计算机视觉
⾃自然语⾔言处理理 ⻛风格化图像处理理
其余的出路路 区块链 P2P信贷 做个快乐的肥宅
做个快乐的肥宅
I have an idea!
App: 普尔亚后援会 • 使⽤用相机或者照⽚片库 • 识别照⽚片中的普尔亚⼿手势 • 收集到三张照⽚片获得奖励
HOW?
我(们)的出路路在哪⾥里里 ⼤大前端 React Native Weex ⼩小程序 Flutter 机器器学习 深度学习 计算机视觉
⾃自然语⾔言处理理 ⻛风格化图像处理理
CreateML WWDC 2018 Session 703 https://developer.apple.com/videos/play/wwdc2018/703/
⼀一般流程 准备数据 训练模型 评估模型
⼀一般流程 准备数据 训练模型 评估模型 图⽚片 + 分类标签 准备训练数据 (train set)
和验证数据 (validation set) 调整参数 寻找使训练数据具有最⼩小误差值的⼀一组参数 使⽤用验证数据对模型准确率评估
None
⼀一般流程 准备数据 训练模型 评估模型
CreateML 到底做了了什什么
mlmodel https://apple.github.io/coremltools/coremlspecification/index.html Protocol Buffers 序列列化的模型描述 layer 类型,权重等
~KB 迁移学习 VisionFeaturePrint_Scene mlmodel VisionFeaturePrint_Scene 只存在于 iOS 12, macOS 10.14
Vision 框架背后的特征提取 17KB in Demo Transfer Learning
None
✅ VisionFeaturePrint_Scene VisionFeaturePrint_Screen
Core ML Community Tools
None
visionFeaturePrint glmClassifier
开始定义 pipeline 输⼊入 299x299 保留留特性的同时限制处理理时间 内置模型 (特征提取) 2048 个特征的数组 (1,
2048) ⼴广义线性模型 (GLM) (2048, 1),与特征点乘得到结果
发⽣生了了什什么
Turi
Turi • 2013, 成⽴立 • 2016, Apple 以 2 亿美元收购
• 2017, 开源, ⽀支持 Metal 和 macOS GPU 加速 • 2018, 部分集成⼊入 Apple Developer Toolkit (Xcode) • 未来, 更更多的学习任务… 基于学习任务的 “傻⽠瓜式” 机器器学习框架
⼏几个问题
VisionFeaturePrint 集成在 iOS 12 和 macOS 10.14 中 问题 No.1
Core ML - iOS 11 • CoreML 从 iOS 11
开始⽀支持 • ⽆无法读取 CreateML 创建的带有 VisionFeaturePrint 的模型
Core ML - iOS 11 使⽤用 TuriCreate 的其他模型进⾏行行特征提取 可以得到与 CreateML
相近的结果
https://github.com/apple/turicreate
Demo
None
~ 90+ MB
过拟合,准确率 问题 No.2
⼀一个⾼高度 的模型 Overfitting 过拟合
过拟合
过拟合 训练数据严重不不⾜足 只来源于单⼀一⼈人员和单⼀一场景 对于⾮非该⼈人员的识别相当低效 默认的训练⽅方式只对最后⼀一层进⾏行行训练 特征提取模型中不不包含对应特征
0 22.5 45 67.5 90 0 5 10 15 20
准确率
默认特征提取模型下 增加训练数据,可以达到 85% 左右
卷积神经⽹网络和特征提取
抽象特征 (边缘,线条,⻆角度) 具体特征 (眼睛,⿐鼻⼦子,⽿耳朵)
CreateML (Turi) 的迁移学习 只对最后⼀一层进⾏行行训练 抽象特征 泛⽤用性 具体特征 专⽤用性
调整若⼲干层卷积层参数 进⾏行行迁移学习
CreateML / Turi
更更加“可操控”的学习⽅方式
更更加“可操控”的学习⽅方式
92% 左右的正确率
⼀一些客户端 ML 的 实际应⽤用
Super-Resolution SRCNN
https://speakerdeck.com/kenmaz/super-resolution-with-coreml-at-try-swift-tokyo-2018 SRCNNKit from DeNA
https://github.com/DeNA/SRCNNKit
在漫画之外使⽤用 1. 专⻔门的训练数据 2. 通过预处理理提取场景特征 (⼈人物,⻛风景,UI) 3.更更多的层数
⾳音乐情绪识别
从⾳音乐的曲调和节奏识别⾳音乐情绪 Music Keyword 梁梁祝 温柔婉转 命运交响曲 激情雄壮 ⼩小苹果 轻松欢快
其他场景 • 本地垃圾短信识别 • 游戏 AI (GameplayKit) • 专⽤用的图像分类/识别 •
etc…
总结 • ⼩小模型,Client Side ML 的关键 • 对于既有特征表现⾮非常出⾊色 (ImageNet Category)
• 简单,⽆无脑,拖拽式得到可⽤用模型 • 对⼯工程师友好,可以在 client 本机编译 (下载更更新模型)
总结 • 只适⽤用于特定任务 (图⽚片分类/⾃自然语⾔言处理理/回归分析) • TuriCreate 只能有限扩展 (使⽤用第三⽅方模型, ⻛风格化图 ⽚片滤镜等)
• ⽆无法处理理⾃自定义模型,或者更更⼀一般化的任务
⼀一些资源 Awesome Core ML Models https://github.com/likedan/Awesome-CoreML-Models Machine Learning for iOS
https://github.com/alexsosn/iOS_ML Apple Machine Learning Journal https://machinelearning.apple.com Kraggle https://www.kaggle.com Machine Learning (Turi) - Coursera https://coursera.org/specializations/machine-learning Deep Learning with Python https://www.manning.com/books/deep-learning-with-python
谢谢!: ] @onevcat, me@onev.cat