core ml人像分割
1.
Resnet50 *resnetModel = [[Resnet50 alloc] init]; UIImage *image = self.selectedImageView.image; VNCoreMLModel *vnCoreModel = [VNCoreMLModel modelForMLModel:resnetModel.model error:nil]; VNCoreMLRequest *vnCoreMlRequest = [[VNCoreMLRequest alloc] initWithModel:vnCoreModel completionHandler:^(VNRequest * _Nonnull request, NSError * _Nullable error) { CGFloat confidence = 0.0f; VNClassificationObservation *tempClassification = nil; for (VNClassificationObservation *classification in request.results) { if (classification.confidence > confidence) { confidence = classification.confidence; tempClassification = classification; } } self.recognitionResultLabel.text = [NSString stringWithFormat:@"识别结果:%@",tempClassification.identifier]; self.confidenceResult.text = [NSString stringWithFormat:@"匹配率:%@",@(tempClassification.confidence)]; }]; VNImageRequestHandler *vnImageRequestHandler = [[VNImageRequestHandler alloc] initWithCGImage:image.CGImage options:nil]; NSError *error = nil; [vnImageRequestHandler performRequests:@[vnCoreMlRequest] error:&error]; if (error) { NSLog(@"%@",error.localizedDescription); }