Skip to content

Commit ae290f1

Browse files
Improve: Support compiled CoreML models (#108)
* Check for precompiled model URL * Don't threat compiled model path as dir * Try different approach
1 parent 33d5df7 commit ae290f1

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

swift/Encoders.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ func readConfig(fromPath path: String) throws -> [String: Any] {
9999
/// - computeUnits: The hardware devices to use for model computation.
100100
/// - Returns: An instance of `MLModel`.
101101
func readModel(fromURL modelURL: URL, computeUnits: MLComputeUnits = .all) throws -> MLModel {
102-
let compiledModelURL = try MLModel.compileModel(at: modelURL)
102+
let compiledModelURL =
103+
modelURL.absoluteString.hasSuffix(".mlmodelc/") ? modelURL : try MLModel.compileModel(at: modelURL)
103104
let config = MLModelConfiguration()
104105
config.computeUnits = computeUnits
105106
return try MLModel(contentsOf: compiledModelURL, configuration: config)

0 commit comments

Comments
 (0)