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);
}

 

 http://www.cocoachina.com/articles/19528

https://github.com/Onaeem26/ImageSegmentationML

posted @ 2020-07-15 14:20  lianhuaren  阅读(37)  评论(0编辑  收藏  举报