gpt4 book ai didi

arrays - 在 CoreML 应用程序的变量列表中使用未解析的标识符

转载 作者:行者123 更新时间:2023-11-30 10:53:45 25 4
gpt4 key购买 nike

我将对象检测模型 (latestObservation) 的结果附加到列表 (listofObservation),该列表工作正常,但我想添加一个条件,以便仅在最新观察结果与之前的观察结果不同时才添加最新观察结果3 观察结果。

将最新结果与之前的观察结果进行比较时,我在访问变量时遇到问题。

这是我的代码:

var latestObservation = (topIdentifier: String(), topConfidence: Float(), scndIdentifier: String(), scndConfidence: Float()) 
var listofObservation:[(topIdentifier: String, topConfidence: Float, scndIdentifier: String, scndConfidence: Float)] = []
var LastTopIdentifierCounter = 0

// ... and the part of the func drawVisionRequestResults that is relevant here follows:

for observation in results where observation is VNRecognizedObjectObservation {
guard let objectObservation = observation as? VNRecognizedObjectObservation else {
continue
}
// Select only the label with the highest confidence and the second highest confidence:
let topLabelObservation = objectObservation.labels[0]
let secondLabelObservation = objectObservation.labels[1]

latestObservation = (topIdentifier: topLabelObservation.identifier, topConfidence: topLabelObservation.confidence, scndIdentifier: secondLabelObservation.identifier, scndConfidence: secondLabelObservation.confidence)

let OFL = listofObservation.count
if (listofObservation.topIdentifier(OFL)) == latestObservation.topIdentifier
&& latestObservation.topidentifier == listofObservation.topIdentifier[OFL-1]
&& latestObservation.topidentifier == listofObservation.topIdentifier[OFL-2]
{
LastTopIdentifierCounter += (1)
}
else {
listofObservation.append(latestObservation)
LastTopIdentifierCounter = 0
print(latestObservation)
print(listofObservation)

打印显示变量的以下内容(如果我将附加设置为无条件):

  1. 最新观察:

(topIdentifier:“6.no_phase”,topConfidence:0.87878287,scndIdentifier:“4.Faden_abnehmen”,scndConfidence:0.06840562)

  • 观察列表:
  • [(topIdentifier:“6.no_phase”,topConfidence:0.87878287,scndIdentifier:“4.Faden_abnehmen”,scndConfidence:0.06840562),(topIdentifier:“6.no_phase”,topConfidence:0.7264241,scndIdentifier:“4.Faden_abnehmen” , scndConfidence: 0.22894023), (topIdentifier: "6.no_phase", topConfidence: 0.92339694, scndIdentifier: "4.Faden_abnehmen", scndConfidence: 0.058480877)]

    在代码行上:

    if (listofObservation.topIdentifier(OFL)) == latestObservation.topIdentifier

    我确实收到以下消息:类型“[(topIdentifier: String, topConfidence: Float, scndIdentifier: String, scndConfidence: Float)]”的值没有成员“topIdentifier”

    我对 swift 很陌生,因此必须道歉,因为这可能是一个非常天真的问题......我已经为此苦苦挣扎了 2 天,但在任何地方都找不到如何解决这个问题的正确提示。任何评论都将受到高度赞赏。非常感谢!

    最佳答案

    您的listofObservation是一个元组数组,因此您需要指定某个元组的索引来获取某个元组及其属性

    array[index] -> element
    ^ Int ^ certain tuple
    <小时/>
    if listofObservation[OFL].topIdentifier  == latestObservation.topIdentifier 
    && listofObservation[OFL-1].topIdentifier == latestObservation.topidentifier
    && listofObservation[OFL-2].topIdentifier == latestObservation.topidentifier {...}
    <小时/>

    或者在 Swift 4.2+ 中,您可以使用 allSatisfy

    if listofObservation[OFL-2...OFL].allSatisfy { $0.topIdentifier == latestObservation.topIdentifier } {...}

    关于arrays - 在 CoreML 应用程序的变量列表中使用未解析的标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54182954/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com