资源算法CoreML_MobileNet

CoreML_MobileNet

2020-02-28 | |  68 |   0 |   0

CoreML_MobileNet

GoogLeNetPlaces.mlmodel 和 Resnet50都可以识别人物和静态物体。不过这个才24M,小多了,所以就简尔处理给张特定的image,然后输出结果

图片.png

图片.png

Download Core ML Model

GoogLeNetPlaces.mlmodel下载地址

导入头文件

 #import < CoreML/CoreML.h>
 #import < Vision/Vision.h>
 #import "GoogLeNetPlaces.h"

图片识别

  1. 创建Resnet对象,加载CoreMLModel

  GoogLeNetPlaces *googleModel = [[GoogLeNetPlaces alloc] init];
  VNCoreMLModel * vnCoreModel = [VNCoreMLModel modelForMLModel:googleModel.model error:nil];
  1. 创建Vision请求,带有completion handle

   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;
            }
        }        
   }];
  1. VNClassificationObservation对象两个属性

    • identifier:识别对象

    • confidence:识别率

  2. 发送图片识别请求

   dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
       VNImageRequestHandler * vnImageRequestHandler = [[VNImageRequestHandler alloc] initWithCGImage:image.CGImage options:nil];   
        NSError *error = nil;
        [vnImageRequestHandler performRequests:@[vnCoreMlRequest] error:&error]; 
        if (error) {
            NSLog(@"%@",error.localizedDescription);
        }
    });
  1. 回调在主线程更新UI

  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            self.resultLable.text = [NSString stringWithFormat:@"识别结果:%@",tempClassification.identifier];
            self.confidenceLabel.text = [NSString stringWithFormat:@"匹配率:%@",@(tempClassification.confidence)];
        });


上一篇:MobileNet-v2-pruning

下一篇:Pedestrian-Detection-MobileNet

用户评价
全部评价

热门资源

  • Keras-ResNeXt

    Keras ResNeXt Implementation of ResNeXt models...

  • seetafaceJNI

    项目介绍 基于中科院seetaface2进行封装的JAVA...

  • spark-corenlp

    This package wraps Stanford CoreNLP annotators ...

  • capsnet-with-caps...

    CapsNet with capsule-wise convolution Project ...

  • inferno-boilerplate

    This is a very basic boilerplate example for pe...