I'm trying to use a CoreMl model I created, but I'm getting an error on it (which I don't get with other models). The error is thrown by the following line: let compiled = try MLModel.compileModel(at: URL(fileURLWithPath: "/Users/myname/Desktop/ItemSimilarityRecommender.mlmodel"))
. (Note: I've tried using paths in my bundle and get the same error)
The error is Error Domain=com.apple.CoreML Code=3 "Error reading protobuf spec. validator error: unable to open file for read" UserInfo={NSLocalizedDescription=Error reading protobuf spec. validator error: unable to open file for read}
The only thing I can find online about this error is that it can happen if you omit ".mlmodel", which is clearly not my issue. When I compile the model manually on my computer, the program also fails. I've made multiple versions of this model to try to fix this problem, and every time I get the same error.
Edit:
I can compile the file manually, and it creates a seemingly valid .mlmodelc file. However, when I use try MLModel(contentsOf:)
, it throws the following:
2021-11-07 15:56:43.131400-0500 Movie Thing[52871:2279366] [coreml] Failed to open file: /Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/coremldata.bin. It is not a valid .mlmodelc file. 2021-11-07 15:56:43.132186-0500 Movie Thing[52871:2279366] [coreml] MLModelAsset: load failed with error Error Domain=com.apple.CoreML Code=0 "Unable to load model: file:///Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/. Compile the model with Xcode or
MLModel.compileModel(at:)
. " UserInfo={NSLocalizedDescription=Unable to load model: file:///Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/. Compile the model with Xcode orMLModel.compileModel(at:)
. , NSUnderlyingError=0x6000036e3090 {Error Domain=com.apple.CoreML Code=3 "Failed to open file: /Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/coremldata.bin. It is not a valid .mlmodelc file. : unspecified iostream_category error" UserInfo={NSLocalizedDescription=Failed to open file: /Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/coremldata.bin. It is not a valid .mlmodelc file. : unspecified iostream_category error}}} 2021-11-07 15:56:43.132312-0500 Movie Thing[52871:2279366] [coreml] MLModelAsset: modelWithError: load failed with error Error Domain=com.apple.CoreML Code=0 "Unable to load model: file:///Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/. Compile the model with Xcode orMLModel.compileModel(at:)
. " UserInfo={NSLocalizedDescription=Unable to load model: file:///Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/. Compile the model with Xcode orMLModel.compileModel(at:)
. , NSUnderlyingError=0x6000036e3090 {Error Domain=com.apple.CoreML Code=3 "Failed to open file: /Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/coremldata.bin. It is not a valid .mlmodelc file. : unspecified iostream_category error" UserInfo={NSLocalizedDescription=Failed to open file: /Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/coremldata.bin. It is not a valid .mlmodelc file. : unspecified iostream_category error}}} Error Domain=com.apple.CoreML Code=0 "Unable to load model: file:///Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/. Compile the model with Xcode orMLModel.compileModel(at:)
. " UserInfo={NSLocalizedDescription=Unable to load model: file:///Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/. Compile the model with Xcode orMLModel.compileModel(at:)
. , NSUnderlyingError=0x6000036e3090 {Error Domain=com.apple.CoreML Code=3 "Failed to open file: /Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/coremldata.bin. It is not a valid .mlmodelc file. : unspecified iostream_category error" UserInfo={NSLocalizedDescription=Failed to open file: /Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/coremldata.bin. It is not a valid .mlmodelc file. : unspecified iostream_category error}}}
Edit 2: To clarify, the model works as intended when tested and evaluated in CreateML.
xcrun coremlcompiler
(presumably that's what you are using when you say "compile the model manually on my computer")? – Kollwitz