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
204
|
第
11
章
我们可以使用它的
.output
属性访问解释器的输出张量。与输入类似,在这种情况下,
我们一次处理一张图像,因此它的输出索引是 0。如果我们对图像进行批处理,则对图
像
n
的推理将在索引
n
处。
// Get the output tensor to process the inference results.
outputTensor = try interpreter.output(at: 0)
回想一下,这个模型是在 5 种不同类型的花上训练的,所以模型的输出将是 5 个值,每
个值都是图像包含特定花的概率。顺序是按字母顺序排列的,所以我们识别的花是雏
菊、蒲公英、玫瑰、向日葵和郁金香,这 5 个值将与它们对应。因此,例如,第一个输
出值是图像包含雏菊的可能性,以此类推。
这些值是概率,因此它们在 0 和 1 之间,表示为浮点数。你可以读取输出张量并像这样
将其转换为数组:
let resultsArray =
outputTensor.data.toArray(type: Float32.self)
现在,如果你想确定图像中最有可能包含的花,你可以回到纯 Swift 中,获取最大值,
找到该值的索引,并查找与该索引对应的标签!
// Pick the biggest value in the array
let maxVal = resultsArray.max()
// Get the index of the biggest value
let resultsIndex = ...
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

Lua游戏AI开发指南

Lua游戏AI开发指南

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

人工智能技术与大数据

Posts & Telecom Press, Anand Deshpande, Manish Kumar

Publisher Resources

ISBN: 9787111713081