Weird compilation error if the mlmodel was downloaded from remote url

43 Views Asked by At

I want to download .mlmodel file from remote url and compile it directly on user's device. What I do is:

let request = URLRequest(url: modelURL)
        
let destinationURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("MNISTClassifier.mlmodel")
        
let task = URLSession.shared.dataTask(with: request) { data, response, error in
    guard let data = data else { return }
    do {
        try data.write(to: destinationURL)
    } catch let error {
        print(error)
    }
}
        
task.resume()

and then I compile it via:

MLModel.compileModel(at: destinationURL) { res in
    switch res {
        case .success(let url):
            print(url)
        case .failure(let error):
            print(error)
    }
}

but somehow I get this error:

Error Domain=com.apple.mlassetio Code=1 "Failed to parse the model specification. Error: Field number 7 has wireType 4, which is not supported." UserInfo={NSLocalizedDescription=Failed to parse the model specification. Error: Field number 7 has wireType 4, which is not supported.}

I always get that error. Even when I try to open the mlmodel via Xcode, I get error with:

validator error: Model specification version field missing or corrupt

The model what I use is MNISTClassification model from Apple Docs: https://ml-assets.apple.com/coreml/models/Image/DrawingClassification/MNISTClassifier/MNISTClassifier.mlmodel

Any idea why it happens and how can I fix that? I even tried to use Alamofire Downloader but getting the same error

0

There are 0 best solutions below