5

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 or MLModel.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 or MLModel.compileModel(at:). " UserInfo={NSLocalizedDescription=Unable to load model: file:///Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/. Compile the model with Xcode or MLModel.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 or MLModel.compileModel(at:). " UserInfo={NSLocalizedDescription=Unable to load model: file:///Users/me/Desktop/ItemSimilarityRecommender.mlmodelc/. Compile the model with Xcode or MLModel.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.

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
Ben A.
  • 874
  • 7
  • 23
  • How did you make this model? – Sweeper Nov 07 '21 at 20:36
  • @Sweeper I tried doing it in both Playground and CreateML's interface. Both created .mlmodel files that threw this error. – Ben A. Nov 07 '21 at 20:43
  • Can you give the entire error message when you compile it with `xcrun coremlcompiler` (presumably that's what you are using when you say "compile the model manually on my computer")? – Sweeper Nov 07 '21 at 20:52
  • @Sweeper I edited my post with the full message. I tried compiling with xcrun and also the way described here: https://www.youtube.com/watch?v=qIX5vHhxjR8. Both created .mlmodelc files, and both of the files throw the same error when run in Swift. – Ben A. Nov 07 '21 at 21:03

0 Answers0