Skip to Content
移动端AI与ML应用开发:基于iOS和Android
book

移动端AI与ML应用开发:基于iOS和Android

by Laurence Moroney
January 2023
Intermediate to advanced
288 pages
6h 6m
Chinese
China Machine Press
Content preview from 移动端AI与ML应用开发:基于iOS和Android
iOS
中使用自定义模型
|
211
我不会详细介绍这个函数的作用,但最终的想法是它会使用 Swift
init
功能来初始
化一个带有
Data
构造函数中的
unsafeBytes
的新数组。在 Swift 5.0+ 中,你可以使用
bindMemory
将底层内存复制到新数组中;否则,你将使用
unsafeData.withUnsafeBytes
从原始缓冲区的开头复制
unsafeData
的数量。
要使用之前创建的序列创建输入张量,你只需使用:
let tSequence = Array(sequence)
这将用于创建传递给解释器的
Data
类型。你会在下一步中看到这一点。
11.4.4
4
步:将数组复制到数据缓冲区
你现在有一个
Int32
的数组,使用了
Int32
的底层字节,它被称为
tSequence
。这需要
复制到 TensorFlow
Data
中才能解析它。执行此操作的最简单方法是扩展
Data
以处
理你将从中复制的缓冲区。这是扩展:
extension Data {
init<T>(copyingBufferOf array: [T]) {
self = array.withUnsafeBufferPointer(Data.init)
}
}
这将通过从输入数组(称为
array
)复制不安全的缓冲区数据来初始化
Data
。要使用它
来创建新
Data
,你可以使用如下代码:
let myData =
Data(copyingBufferOf: tSequence.map { Int32($0) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

人工智能驱动的商业智能

人工智能驱动的商业智能

Tobias Zwingmann
Lua游戏AI开发指南

Lua游戏AI开发指南

Posts & Telecom Press, David Young
人工智能技术与大数据

人工智能技术与大数据

Posts & Telecom Press, Anand Deshpande, Manish Kumar

Publisher Resources

ISBN: 9787111713081