Skip to content

Instantly share code, notes, and snippets.

@digitallysavvy
Created February 29, 2020 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitallysavvy/38b9e923b5edae7334212c85994a14de to your computer and use it in GitHub Desktop.
Save digitallysavvy/38b9e923b5edae7334212c85994a14de to your computer and use it in GitHub Desktop.
First snippet of CoreML within ARBroadcaster
let mlModel: MLModel = Hotdog().model
var visionRequests = [VNRequest]()
let dispatchQueueML = DispatchQueue(label: "io.agora.dispatchqueue.ml") // A Serial Queue
override func viewDidLoad() {
super.viewDidLoad()
// Set up Vision Model
guard let hotDogModel = try? VNCoreMLModel(for: mlModel) else {
fatalError("Could not load model. Ensure Coreml model is in your XCode Project and part of a target (see: https://stackoverflow.com/questions/45884085/model-is-not-part-of-any-target-add-the-model-to-a-target-to-enable-generation ")
}
// Set up Vision-CoreML Request
let classificationRequest = VNCoreMLRequest(model: hotDogModel, completionHandler: classificationCompleteHandler)
classificationRequest.imageCropAndScaleOption = VNImageCropAndScaleOption.centerCrop // Crop from centre of images and scale to appropriate size.
visionRequests = [classificationRequest]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment