unable to retrieve MLModel from CoreML Model Deployment

am very new to CoreMl and I want to retrieve a model from Coreml model deployment which was released this year at WWDC.
I made an app that just classifies special and rare things and I uploaded that model.archive to the CoreMl Model deployment dashboard.
I successfully deployed the model and its showing as active.
now the problem is I am unable to retrieve that model, I have tried a lot, I even saw all the WWDC sessions on that one and even copied that code from that session but all in vain.

Here is my whole model loading and retrieving code

my classification code which takes an image and does all the loading of CoreML and from CoreML model deployment.

Code Block
func updateClassifications(for image: UIImage) {
classificationLabel.text = "Classifying..."
var models = try? VNCoreMLModel(for: SqueezeNet().model)
if let modelsss = models {
extensionofhandler(ciimage: image, vnmodel: modelsss)
return
}
_ = MLModelCollection.beginAccessing(identifier: "TestingResnetModel") { [self] result in
var modelUrl: URL?
switch result {
case .success(let collection):
modelUrl = collection.entries["class"]?.modelURL
case .failure(let error):
fatalError("sorry \(error)")
}
let result = loadfishcallisier(from: modelUrl)
switch result {
case .success(let modelesss):
models = try? VNCoreMLModel(for: modelesss)
extensionofhandler(ciimage: image, vnmodel: models!)
case .failure(let error):
fatalError("plz \(error)")
}
}
}
func loadfishcallisier(from modelUrl: URL?) -> Result<MLModel,Error> {
if let modelUrl = modelUrl {
return Result { try MLModel(contentsOf: modelUrl)}
} else {
return Result { try MLModel(contentsOf: modelUrl!, configuration: .init())}
}
}
func extensionofhandler(ciimage: UIImage,vnmodel: VNCoreMLModel) {
let orientation = CGImagePropertyOrientation(ciimage.imageOrientation)
guard let ciImage = CIImage(image: ciimage) else { fatalError("Unable to create \(CIImage.self) from \(ciimage).")
}
DispatchQueue.global(qos: .userInitiated).async { [self] in
let handler = VNImageRequestHandler(ciImage: ciImage, orientation: orientation)
do {
try handler.perform([coremlmodel(using: vnmodel)])
} catch {
fatalError("Check the error")
}
}
}


my Vision request code
Code Block
func coremlmodel(using: VNCoreMLModel) -> VNCoreMLRequest {
let request = VNCoreMLRequest(model: using, completionHandler: { [weak self] request, error in
self?.processClassifications(for: request, error: error)
})
request.imageCropAndScaleOption = .centerCrop
return request
}


my classification code
Code Block
func processClassifications(for request: VNRequest, error: Error?) {
DispatchQueue.main.async {
guard let results = request.results else {
self.classificationLabel.text = "Unable to classify image.\n\(error!.localizedDescription)"
return
}
// The `results` will always be `VNClassificationObservation`s, as specified by the Core ML model in this project.
let classifications = results as! [VNClassificationObservation]
if classifications.isEmpty {
self.classificationLabel.text = "Nothing recognized."
} else {
// Display top classifications ranked by confidence in the UI.
let topClassifications = classifications.prefix(2)
let descriptions = topClassifications.map { classification in
// Formats the classification for display; e.g. "(0.37) cliff, drop, drop-off".
return String(format: " (%.2f) %@", classification.confidence, classification.identifier)
}
self.classificationLabel.text = "Classification:\n" + descriptions.joined(separator: "\n")
}
}
}


I am pretty sure something is wrong with my model loading code.

Xcode throws no error but it's not recognising anything.

if I have done anything wrong in my code I humbly ask you to show it to me and solve it

and is there any tutorial for retrieving the model from coreml model deployment.

Replies

I have the similar issue.
I did the success from MLModelCollection.beginAccessing, and got the MLModelCollection.
But there is no any entry in the MLModelCollection.
Is there any suggestion how to debug this ??
@htaiwan thanks for replying

can you please share the code with me on how you accessed the ml model

I highly respect your privacy and I don’t need any of your MLModelCollection identifier or anything i just need the code on how to retrieve the MLModel

it will be a great help if you provide me the code of retrieving MLModel from MLModelCollection .

and i am really sorry i don’t have any Suggestions on this one.

thanks in advance.
i have got the same question. when i use beginAccessingModelCollectionWithIdentifier, coreml show something wrong message :
Code Block language
[coreml] MLModelCollection: namespace (87HGLU5YX9.DeploymentModelCollection) download failed. Error Domain=com.apple.trial Code=0 "Unknown error." UserInfo={NSLocalizedDescription=Unknown error.}


Hi, I encountered exactly the same issue even though I went through and followed all the steps in:
iOS: 14.3 (18C66), iPhone 12 Pro Max

I even tried to create the test collection at different Teams. All without any luck to solve this issue... As I was going through the Developer Forum, I also noticed that many ML Developers have this kind of issue.

Code Block
CloudDeploymentTest[18290:11523393] [coreml] MLModelCollection: namespace (TEAM_ID.test_collection) download failed. Error Domain=com.apple.trial Code=0 "Unknown error." UserInfo={NSLocalizedDescription=Unknown error.}
Error accessing a model collection: Error Domain=com.apple.CoreML Code=10 "Failed to begin access for model collection with identifier 'test_collection': invalid identifier" UserInfo={NSLocalizedDescription=Failed to begin access for model collection with identifier 'test_collection': invalid identifier}


Any help would be highly appreciated!