Mask-RCNN-CoreML
Mask-RCNN-CoreML copied to clipboard
Error loading model
I get the following error when running the sample app after downloading the assets:
2019-01-17 21:51:37.564980-0800 Example[4051:695886] [espresso] [Espresso::handle_ex_plan] exception=Invalid dst shape1 x 1 x 2 x 0 x -1 2019-01-17 21:51:37.565377-0800 Example[4051:695886] [coreml] Error in adding network -1. 2019-01-17 21:51:37.565508-0800 Example[4051:695886] [coreml] MLModelAsset: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}
Got the same issue with xcode Version 10.1 (10B61), and the target is ios 12.0 and 12.1
019-02-18 13:43:22.192988-0800 Example[8416:2201273] [espresso] [Espresso::handle_ex_plan] exception=Invalid dst shape1 x 1 x 2 x 0 x -1
2019-02-18 13:43:22.193386-0800 Example[8416:2201273] [coreml] Error in adding network -1.
2019-02-18 13:43:22.193534-0800 Example[8416:2201273] [coreml] MLModelAsset: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}
2019-02-18 13:43:22.193562-0800 Example[8416:2201273] [coreml] MLModelAsset: modelWithError: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}
Got the same issue with xcode Version 10.1 (10B61), and the target is iOS 12.1.4:
2019-03-06 10:10:47.819631+0300 Example[1547:349765] [espresso] [Espresso::handle_ex_plan] exception=Invalid dst shape1 x 1 x 2 x 0 x -1 2019-03-06 10:10:47.820211+0300 Example[1547:349765] [coreml] Error in adding network -1. 2019-03-06 10:10:47.820472+0300 Example[1547:349765] [coreml] MLModelAsset: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.} 2019-03-06 10:10:47.820518+0300 Example[1547:349765] [coreml] MLModelAsset: modelWithError: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}
Me too ,I use xcode Version 10.1 (10B61), and the target is iOS 12.1 (16b94) iPhone x . when i was crash the first time to install app after that it normal.
espresso] [Espresso::handle_ex_plan] exception=mmap error: 12 2019-03-29 14:45:08.867218+0700 TrueHR[736:42507] [coreml] Error in adding network -1. 2019-03-29 14:45:08.867297+0700 TrueHR[736:42507] [coreml] MLModelAsset: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.} 2019-03-29 14:45:08.867315+0700 TrueHR[736:42507] [coreml] MLModelAsset: modelWithError: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}
And does anybody have a solution?)
Same issue here [espresso] [Espresso::handle_ex_plan] exception=Invalid dst shape1 x 1 x 2 x 0 x -1 [coreml] Error in adding network -1. [coreml] MLModelAsset: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.} [coreml] MLModelAsset: modelWithError: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}
Had the same issue and have found a work around.
Instead of including MaskRCNN.mlmodel in the project, I compiled it using MLModel.compileModel
Swift API on my PC beforehand and then include compiled mlmodelc file in the project.
Try the following step.
-
Compile MaskRCNN.mlmodel using
MLModel.compileModel
Swift API. You can do it yourself or you can use the attached MaskRCNN.mlmodelc which was compiled by me. https://drive.google.com/file/d/1NYD4BupvIs1Pza_F7jbg8oA5HXLV8FfC/view?usp=sharing -
Add reference to MaskRCNN.mlmodelc folder (check
Create folder references
) to your project. -
Make sure that in
Build Phases
, MaskRCNN.mlmodelc is added inCopy Bundle Resources
section. -
In Swift code, load mlmodelc file directly instead of mlmodel file.
// instaed of this
// let model = try VNCoreMLModel(for: MaskRCNN().model)
// use following
let compiledPath = Bundle.main.path(forResource: "MaskRCNN", ofType: "mlmodelc")
let compiledUrl = URL(fileURLWithPath: compiledPath!)
let mlmodel = try MLModel(contentsOf: compiledUrl)
guard let model = try? VNCoreMLModel(for: mlmodel) else {
fatalError("can't load Core ML model")
}
By the way, at first I tried run MLModel.compileModel
on my iPhone XS, but it exceeded device's memory limit (2000mb) and crashed. So I switched to run it on my Mac Book Pro.
Finally and more strangely, after this workaround worked, the original code started to work again. I don't know what the hell is going on :(