Post

Replies

Boosts

Views

Activity

Crash Due to Optimization
I am getting the following crash only when building in release mode and only on iPhone 12 and up generations: pump-content was compiled with optimization - stepping may behave oddly; variables may not be available. I have encountered this bug before and it usually can be fixed by turning off all optimization in the release build. But for some reason, this has not worked. Here are my build settings: I have cleaned the build cmd+shift+k, but I still get the same error. Appreciate any help, thanks.
0
0
378
Nov ’21
EXC_BAD_ACCESS model.predict() CoreML
I am using a custom CoreML model which takes a MultiArray (Float32 1 × 85 × 60 × 1) as an input. The following is the entire app. As you can see I initialize the model, create some fake data and then run model.predict(data). import CoreML struct ContentView: View {       let model: A_4 = try! A_4(configuration: .init())       var body: some View {     VStack {       Text("Test")         .onAppear {           print(model.model)         }         .onTapGesture {           let data = [Float](repeating: 0.3, count: 5100)                       let reshapedData = try! MLMultiArray(data).reshaped(to: [1, 85, 60, 1])                       let input = A_4Input(conv2d_input: reshapedData)                       let prediction = try! model.prediction(input: input)                       print(prediction.Identity)         }     }   } } On any simulator device running iOS 14.5, model.predict works as expect yielding the following array: On any number tap: [0.0009301336,0.9990699] On my real device running iOS 15.0, the model produces a similar result: On any number tap: [0.0009710453,0.9990289] Lastly, I tested the app on the following devices, iPhone 11 Pro (iOS 14.7.1), iPhone 11 (iOS 14.6), iPhone SE 2 (iOS 14.6): On first tap: [0, 1] On Second tap: Thread 1: EXC_BAD_ACCESS (code=1, address=0x1470b4000) As you can see the first prediction is someone nonsense, and the second prediction crashes the app. I have attempted debugging this for quite some time and cannot determine the cause of this memory error. I have provided the ContentView and the model here: https://drive.google.com/drive/folders/11hw70kCfyeuRUepEf6cxhmuTb8oLW3jm?usp=sharing Thanks for any insight you can provide.
0
0
685
Aug ’21
Calling similar Functions from different classes without protocols
Well my use case is a bit challenging and has to do with the way CoreML autogenerates a class for every model and a respective series of predict methods. I have done my best to boil down the problem to its simplest form. I have the following two classes, each contains a predict method with ALWAYS has the same input type. class one {   func predict(input: Int) -> Double {      // Code   } } class two {   func predict(cool: Int) -> Int {      // Code   } } The following class is responsible for calling the .predict method in the above classes and a generic apply function which allows me to invoke the function without knowing the parameter name. class Consumer<Consumed> { let model: Consumed init(model: Consumed) { self.model = model } func anyFunction() { apply(fn: self.model.predict, arg: 4) } } // Generic Apply Method func apply<T, V>(fn: (T) throws -> V, arg: T) -> V? {   do {     return try? fn(arg)   } } Obviously the code above does not compile because I am attempting to call .predict on a generic type which is not guaranteed to have such a method. I believe the only way to fix this is to write a protocol which ensures the predict method exists in the generic paramter Consumed, but I am not sure how to do that. Below is my best attempt at the protocol that I believe <Consumed: ...> should conform to. protocol ModelProtocol {   func prediction<Input, Output>(input: Input) throws -> Output } Any help it appreciated, thanks!
1
0
464
Jul ’21
CoreML Model in Swift Package Tests
I am trying to create some tests inside a swift package that require the a coreML model. I am trying to copy the compiled model into the working bundle, but when I run the tests, the resource is not found using the Bundle.main.url() method. The project also compiles and runs successfully when running command+b. My file structure: My Package.swift: // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package(   name: "AudioPreprocessingSPM",   products: [     // Products define the executables and libraries a package produces, and make them visible to other packages.     .library(       name: "AudioPreprocessingSPM",       targets: ["AudioPreprocessingSPM"]),   ],   dependencies: [     // Dependencies declare other packages that this package depends on.     // .package(url: /* package url */, from: "1.0.0"),   ],   targets: [     // Targets are the basic building blocks of a package. A target can define a module or a test suite.     // Targets can depend on other targets in this package, and on products in packages this package depends on.     .target(       name: "AudioPreprocessingSPM",       dependencies: [],       resources: [.copy("A-6.swift"), .copy("A-6.mlmodelc")]),     .testTarget(       name: "AudioPreprocessingSPMTests",       dependencies: ["AudioPreprocessingSPM"],       resources: [.copy("A-6.swift"), .copy("A-6.mlmodelc")]),   ] ) My Package Test: @testable import AudioPreprocessingSPM final class AudioEngineTests: XCTestCase {       func testCreateAudioEngineInstance() {     var model = try! A_6(configuration: .init())   } } My modified A-6.swift file: class A_6 {   let model: MLModel   /// URL of model assuming it was installed in the same bundle as this class   class var urlOfModelInThisBundle : URL {     var bundles = Bundle.allBundles.map{ return $0.bundlePath }           return Bundle.main.url(forResource: "A-6", withExtension: "mlmodelc")!   } // Removed unmodified portions of auto generated file below } I am not very familiar with how bundling works for a swift package, but I believe that is where the issue lies. Error Received when running test: Fatal error: Unexpectedly found nil while unwrapping an Optional value: file AudioPreprocessingSPMTests/A-6.swift, line 100 2021-07-04 11:37:21.785589-0400 xctest[79167:2602315] Fatal error: Unexpectedly found nil while unwrapping an Optional value: file AudioPreprocessingSPMTests/A-6.swift, line 100 The default generation of file A-6.swift also fails: class var urlOfModelInThisBundle : URL {           let bundle = Bundle(for: A_6.self)           return bundle.url(forResource: "A-6", withExtension: "mlmodelc")! } Thanks for your help
2
0
1.4k
Jul ’21
AVAudioEngine sample rate mismatch on newer devices
I am currently using the AVAudioEngine to grab raw int16Channel data from the inputNode. The default sample rate for the AVAudioEngine online claim it is 44 kHz with bit depth of 32. I forcefully tap the inputNode with an AVAudioFormat which is initialized with a sample rate of 44100 rather than using inputNode.sampleRate since my program will only run with a sampleRate of 44100. The odd thing about the crash I am experiencing, is that it only seems to occur on newer devices. swift struct BaseView: View {       let audioEngine = AVAudioEngine()   let inputFormat = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 44100, channels: 1, interleaved: false)   let analysisQueue = DispatchQueue(label: "com.dev.pump.analysisQueue", qos: .background)   var body: some View {     VStack {       Text("Audio Engine Test")         .onTapGesture {           Log.info("Tapped")           audioEngine.inputNode           do {             try audioEngine.start()           } catch {             Log.error("Error in audio engine start", error)             fatalError()           }                       analysisQueue.async {             audioEngine.inputNode.installTap(onBus: 0, bufferSize: 11025, format: inputFormat) {_,_ in               Log.info("I am running")             }           }                     }     }   } } Devices I tested this on: iPhone 6s: No Crash iPhone 7: No Crash iPhone 8: No Crash iPhone SE 2: No Crash iPhone 11 Pro: Crash iPhone 11: Crash iPhone 12: Crash I do not have any other devices so I was not able to pinpoint what generation this occurred at. I am pretty sure the AVAudioEngine switched its default format when connected to bluetooth devices (from 44.1 kHz to 16 kHz), but I am not sure what is causing this. Below is the specific crash log: 2021-05-25 13:04:31.908675-0400 Pump Beta[57851:6521568] [avae]      AVAEInternal.h:76  required condition is false: [AVAudioEngineGraph.mm:2027:InstallTapOnNode: (format.sampleRate == inputHWFormat.sampleRate)] 2021-05-25 13:04:31.912024-0400 Pump Beta[57851:6521568] * Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: format.sampleRate == inputHWFormat.sampleRate' First throw call stack: (0x1829ad86c 0x1979c6c50 0x1828b3000 0x193393e18 0x1933d8fa8 0x1934557fc 0x1934360b8 0x104a13eb8 0x104921e40 0x10d367bcc 0x10d3696c0 0x10d371354 0x10d3720c0 0x10d37e644 0x1ce459814 0x1ce46076c) libc++abi.dylib: terminating with uncaught exception of type NSException** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: format.sampleRate == inputHWFormat.sampleRate' terminating with uncaught exception of type NSException
1
0
2.9k
May ’21