Skip to content

Instantly share code, notes, and snippets.

@boaerosuke
Created August 16, 2017 16:20
Show Gist options
  • Save boaerosuke/5f655fa058d1cc1232768461162554c0 to your computer and use it in GitHub Desktop.
Save boaerosuke/5f655fa058d1cc1232768461162554c0 to your computer and use it in GitHub Desktop.
How to set up a VNCoreMLRequest with VNRequestCompletitionHandler
VNCoreMLRequest *request = [[VNCoreMLRequest alloc] initWithModel: vnc_core_ml_model completionHandler: (VNRequestCompletionHandler) ^(VNRequest *request, NSError *error){
NSArray *results = [request.results copy];
VNCoreMLFeatureValueObservation *res = ((VNCoreMLFeatureValueObservation *)(results[0]));
NSNumber *prediction = [NSNumber numberWithFloat:0];
NSNumber *compare= [NSNumber numberWithFloat:0];
int atIndex = 0;
for(int i = 0; i<[res.featureValue multiArrayValue].count; i++){
compare = [[res.featureValue multiArrayValue] objectAtIndexedSubscript:i];
if([compare floatValue] > [prediction floatValue]){
prediction = compare;
atIndex = i;
}
}
// double predictionPercentage = [[[res.featureValue multiArrayValue] objectAtIndexedSubscript:atIndex] doubleValue];
NSString *result = @"";
self.resultLabel.text = [result stringByAppendingFormat: @"Digit may be: %i", atIndex];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment