【发布时间】:2019-11-30 19:31:25
【问题描述】:
我正在尝试在 iOS 上运行分段模型,但我有几个关于如何正确使用输出张量的问题。
这里是我正在使用的模型的链接: https://www.tensorflow.org/lite/models/segmentation/overview
当我运行这个模型时,我得到了具有维度的输出张量: 1 x 257 x 257 x 21。 为什么我得到 21 作为最后一个维度?看起来我们正在获得每个像素的类分数。我们是否需要在这里找到 argmax 才能得到正确的类值?
但为什么只有 21 个班级?我在想它应该包含更多。在哪里我可以找到哪个值对应于某个类的信息。 在 ImageClassification 示例中,我们有一个包含 1001 个类的 label.txt。
基于 ImageClassification 示例,我尝试解析张量:首先将其转换为大小为 1 387 029 (21 x 257 x 257) 的浮点数组,然后使用以下代码逐像素创建图像:
// size = 257
// depth = 21
// array - float array of size 1 387 029
for i in 0..<size {
for j in 0..<size {
var scores: [Float] = []
for k in 0..<depth {
let index = i * size * depth + j * depth + k
let score = array[index]
scores.append(score)
}
if let maxScore = scores.max(),
let maxClass = scores.firstIndex(of: maxScore) {
let index = i * size + j
if maxClass == 0 {
pixelBuffer[index] = .blue
} else if maxClass == 12 {
pixelBuffer[index] = .black
} else {
pixelBuffer[index] = .green
}
}
}
}
这是我得到的结果:
你可以看到质量不是很好。我错过了什么?
CoreML(https://developer.apple.com/machine-learning/models/) 的分割模型在同一个例子上效果更好:
【问题讨论】:
标签: ios tensorflow image-segmentation tensorflow-lite semantic-segmentation