近来,有越来越多的深度学习框架开始面向移动端进行发展。近日,阿里也基于其 MNN 推理引擎开源了最新的 MNNKit 深度学习 SDK,安卓和 iOS 开发者都可以方便地进行调用。
MNN 引擎层,是 MNN (https://github.com/alibaba/MNN) 库在 Android/iOS 上编译好的包的二进制 Release 版本,提供端侧运行环境。
Core 基础层,这主要抽象和封装与 MNN c++接口调用粒度基本一致的上层 API,iOS 通过 OC 接口提供,Android 通过 Java 接口提供(TODO)。这一层同时也为上层 SDK 提供一些公共服务类或结构定义。
业务 Kit 层,包括了人脸检测、手势识别封装的 API。据项目介绍,之后的业务 Kit 层会不断扩展。
人脸检测 API
手势识别 API
人像分割 API
人脸基本信息
人脸位置的矩形坐标
106 个关键点坐标(区分被遮挡的和未被遮挡的)
置信度
欧拉角度
人脸动作(包含 5 个人脸的动作)
眨眼
张嘴
摇头
点头
扬眉
在 MNN 引擎执行推理之前,对原始的输入进行预处理,保证输入数据中的人脸为正向
使用 AI 模型进行推理;
推理后,产生基于输入图像(预处理之后的)坐标系的关键点结果;。
把关键点坐标变换到和屏幕渲染坐标系相同的方向,方便渲染。
public static void createInstanceAsync (Context context, FaceDetectorCreateConfig createConfig, InstanceCreatedListener<FaceDetector> listener)
public synchronized FaceDetectionReport[] inference(byte[] data, int width, int height, MNNCVImageFormat format, long detectConfig, int inAngle, int outAngle, MNNFlipType outputFlip)
public synchronized FaceDetectionReport[] inference(Bitmap bitmap, long detectConfig, int inAngle, int outAngle, MNNFlipType outputFlip)
public synchronized void release()
+ (void)createInstanceAsync:(MNNFaceDetectorCreateConfig*)config Callback:(void(^)(NSError *error, MNNFaceDetector *faceDetector))block CallbackQueue:(dispatch_queue_t)callbackQueue;
+ (void)createInstanceAsync:(MNNFaceDetectorCreateConfig*)config Callback:(void(^)(NSError *error, MNNFaceDetector *faceDetector))block;
- (NSArray<MNNFaceDetectionReport *> *)inference:(CVPixelBufferRef)pixelBuffer Config:(MNNFaceDetectConfig)detectConfig Angle:(float)inAngle OutAngle:(float)outAngle FlipType:(MNNFlipType)flipType error:(NSError *__autoreleasing *)error;
- (NSArray<MNNFaceDetectionReport *> *)inferenceImage:(UIImage*)image Config:(MNNFaceDetectConfig)detectConfig Angle:(float)inAngle OutAngle:(float)outAngle FlipType:(MNNFlipType)flipType error:(NSError *__autoreleasing *)error;
- (NSArray<MNNFaceDetectionReport *> *)inference:(unsigned char*)data Width:(float)w Height:(float)h Format:(MNNCVImageFormat)format Config:(MNNFaceDetectConfig)detectConfig Angle:(float)inAngle OutAngle:(float)outAngle FlipType:(MNNFlipType)flipType error:(NSError *__autoreleasing *)error;