Created
August 16, 2017 16:20
-
-
Save boaerosuke/5f655fa058d1cc1232768461162554c0 to your computer and use it in GitHub Desktop.
How to set up a VNCoreMLRequest with VNRequestCompletitionHandler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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