gpt4 book ai didi

swift - 不从 Remote Firebase Automl 自定义模型检索输出预测

转载 作者:行者123 更新时间:2023-11-30 10:37:06 24 4
gpt4 key购买 nike

我目前正在尝试构建一个使用谷歌 autoML 功能的应用程序。我已经训练了一个模型并将其发布在 google firebase 上,并按照文档将必要的代码集成到我的应用程序中:

https://firebase.google.com/docs/ml-kit/ios/label-images-with-automl

我正在使用远程模型,而不是将其设置为本地模型。但是,当我尝试运行代码,然后在模拟器中选择图像时,控制台中会输出一个空的预测列表。

我还打开了调试功能,但这并没有帮助我修复错误。这是我在 ViewController 中运行的代码:

import UIKit
import CoreML
import Vision
import Firebase
import FirebaseMLCommon


var serverImage: UIImage? = nil
var topResult = ""
class ViewController: UIViewController {

@IBOutlet var skinDiseaseImageView: UIImageView!
@IBOutlet var result1Label: UILabel!
@IBOutlet var result1Confidence: UILabel!
@IBOutlet var result2Label: UILabel!
@IBOutlet var result2Confidence: UILabel!
@IBOutlet var result3Label: UILabel!
@IBOutlet var result3Confidence: UILabel!

override func viewDidLoad() {

let initialConditions = ModelDownloadConditions(allowsCellularAccess: true,
allowsBackgroundDownloading: true)
let updateConditions = ModelDownloadConditions(allowsCellularAccess: false,
allowsBackgroundDownloading: true)
let remoteModel = RemoteModel(
name: "skinDiseaseModel", // The name you assigned in the console.
allowsModelUpdates: true,
initialConditions: initialConditions,
updateConditions: updateConditions
)
ModelManager.modelManager().register(remoteModel)

super.viewDidLoad()


}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

}


extension ViewController {

@IBAction func selectImage(_ sender: Any) {
let pickerController = UIImagePickerController()
pickerController.delegate = self
pickerController.sourceType = .savedPhotosAlbum
present(pickerController, animated: true)
}

}


extension ViewController: UIImagePickerControllerDelegate {

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
dismiss(animated: true)

guard let skinImage = info[UIImagePickerControllerOriginalImage] as? UIImage else {
fatalError("Error Retrieving Image Line 95")
}

var skinImageToDiagnose = VisionImage(image: skinImage)

serverImage = skinImage
skinDiseaseImageView.image = skinImage


let labelerOptions = VisionOnDeviceAutoMLImageLabelerOptions(
remoteModelName: "skinDiseaseModel", // Or nil to not use a remote model
localModelName: nil // Or nil to not use a bundled model
)
labelerOptions.confidenceThreshold = 0 // Evaluate your model in the Firebase console
// to determine an appropriate value.
let labeler = Vision.vision().onDeviceAutoMLImageLabeler(options: labelerOptions)

var topThreeResults = [String]()
var topThreeConfidences = [String]()
labeler.process(skinImageToDiagnose) { labels, error in
guard error == nil, let labels = labels
else {
print(error)
return
}
//task succeeded
print("1")
print(labels)
var counter = 0
for label in labels {
topThreeResults.append(String(describing: label))
topThreeConfidences.append(String(describing: label.confidence))
counter = counter + 1
print("counter")
if counter == 3 {
break
}
}

}

result1Label.text = topThreeResults[0]
result1Confidence.text = (topThreeConfidences[0] + "%")

result2Label.text = topThreeResults[1]
result2Confidence.text = (topThreeConfidences[1] + "%")

result3Label.text = topThreeResults[2]
result3Confidence.text = (topThreeConfidences[2] + "%")





}

}

这是我收到的错误:

 Fatal error: Index out of range
2019-08-31 19:50:19.763469-0700 medicalAppFinal[13776:2281569] Fatal error: Index out of range
(lldb)

我推断索引超出范围问题是由于标签列表(输出预测)在打印后为空。因此我明白为什么它的索引超出范围,但我不知道为什么在将图像传递到 labeler.process() 后收到一个空列表如何解决此错误?如果您需要更多信息,请告诉我

最佳答案

关于swift - 不从 Remote Firebase Automl 自定义模型检索输出预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57742917/

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