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
494
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
857
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
618
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.8k
Jul ’21
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.
Replies
0
Boosts
0
Views
494
Activity
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.
Replies
0
Boosts
0
Views
857
Activity
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!
Replies
1
Boosts
0
Views
618
Activity
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
Replies
2
Boosts
0
Views
1.8k
Activity
Jul ’21