提问人:Ramesh Kumar 提问时间:4/27/2023 最后编辑:The Dreams WindRamesh Kumar 更新时间:5/1/2023 访问量:115
如何检查苹果设备在运行时是否支持 GPU / 神经引擎?
How to check if apple device support GPU / neural engine in runtime?
问:
我正在研究coreML。具有神经引擎的设备(iPhone 13)能够同时处理 5 张图像,但没有神经引擎的设备(iPad 第 6 代)无法一次处理多张图像,一次只能处理一张图像。如果我尝试在没有神经引擎支持的设备中一次处理多个图像,则应用程序会崩溃(由于内存问题而终止)。
有没有办法同时处理具有多个图像的 ML 而不会崩溃。
func execModelFromQueue(){
for imageQueueObj in ImageQueueObjToAdd {
imageQueueObj.status = .InProgress
imageQueueObj.newStatus = true
self.runPrediciton(imageURL: imageQueueObj.imageURL, imageName: imageQueueObj.fileName) { [weak self] fileName, imageHailResult, error in
guard let self = self else { return }
if let imageProccessed = self._imageQueue.filter({ $0.fileName == fileName }).first {
imageProccessed.status = .Done
imageProccessed.newStatus = false
imageProccessed.mlResult = imageHailResult
self.updateImageStatus(name: imageProccessed.fileName)
}
HailDamageHelper.storeHailDamage(jobId: self.jobId, fileName: fileName, imageMLHailResult: imageHailResult)
self.delegate?.didFinishFile(filename: fileName, imageMLHailResults: imageHailResult)
}
}
}
private func runPrediciton(imageURL:URL, imageName:String, completion: @escaping (String, hailMLImageResult?, Error?) -> ()){
for tile in imageTileSet!.tiles! {
self.analyzeImage(fileName: imageName, tile: tile, tileSet: imageTileSet!) {[weak self]imageName, myTile, myTileSet, error, result in
guard error == nil, let self = self else { return }
myTile.mlOutput = result
myTile.proccessed = true
}
}
private func analyzeImage(fileName: String, tile: hailMLImageTile, tileSet: hailMLImageTileSet, completion: @escaping (String, hailMLImageTile, hailMLImageTileSet, Error?, hail_v001Output?)->()){
if #available(iOS 13.0, *) {
DispatchQueue.global(qos: .background).async { [weak self] in
guard let self = self else { return }
do {
let startProcessDate = Date()
if let model = self.getHailModel() {
let input = try hail_v001Input(imageWith: tile.image!.cgImage!, iouThreshold: 0.6, confidenceThreshold: 0.4)
let output = try model.prediction(input: input)
let endProcessDate = Date()
}
}
答: 暂无答案
评论