PaddleMobile.h 2.3 KB
Newer Older
1
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
L
liuruilong 已提交
2

3 4 5
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
L
liuruilong 已提交
6

7
 http://www.apache.org/licenses/LICENSE-2.0
L
liuruilong 已提交
8

9 10 11 12 13 14
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License. */

15 16
#pragma once

17 18 19
#import <CoreImage/CoreImage.h>
#import <Foundation/Foundation.h>

L
liuruilong 已提交
20 21 22 23 24 25 26 27 28 29 30
@interface PaddleMobileCPUResult: NSObject

@property (assign, nonatomic, readonly) float *output;

@property (assign, nonatomic, readonly) int outputSize;

-(void)releaseOutput;

@end

@interface PaddleMobileCPU : NSObject
31

L
liuruilong 已提交
32
/*
L
liuruilong 已提交
33
    创建对象
L
liuruilong 已提交
34
*/
35
- (instancetype)init;
L
liuruilong 已提交
36 37

/*
L
liuruilong 已提交
38
    load 模型, 开辟内存
L
liuruilong 已提交
39
*/
40
- (BOOL)load:(NSString *)modelPath andWeightsPath:(NSString *)weighsPath;
L
liuruilong 已提交
41

L
liuruilong 已提交
42 43 44 45 46
/*
  加载散开形式的模型, 需传入模型的目录
*/
- (BOOL)load:(NSString *)modelAndWeightPath;

L
liuruilong 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
/*
 * 从内存中加载模型
 * */
- (BOOL)LoadCombinedMemory:(size_t)modelLen
               andModelBuf:(const uint8_t *)modelBuf
         andModelParamsLen:(size_t)combinedParamsLen
      andCombinedParamsBuf:(const uint8_t *)combinedParamsBuf;

/*
 *  对图像进行预处理, 需要外部开辟 output 内存, 外部释放 output 内存
 * */
-(void)preprocess:(CGImageRef)image
           output:(float *)output
            means:(NSArray<NSNumber *> *)means
        scale:(float)scale
        dim:(NSArray<NSNumber *> *)dim;

/*
 * 预测预处理后的数据, 返回结果使用结束需要调用其 realseOutput 函数进行释放
 * */
- (PaddleMobileCPUResult *)predictInput:(float *)input
                                    dim:(NSArray<NSNumber *> *)dim;

L
liuruilong 已提交
70
/*
L
liuruilong 已提交
71
    进行预测, means 和 scale 为训练模型时的预处理参数, 如训练时没有做这些预处理则直接使用 predict
L
liuruilong 已提交
72
*/
73
- (NSArray *)predict:(CGImageRef)image dim:(NSArray<NSNumber *> *)dim means:(NSArray<NSNumber *> *)means scale:(float)scale;
L
liuruilong 已提交
74 75

/*
L
liuruilong 已提交
76
    进行预测, 默认 means 为 0, scale 为 1.0
L
liuruilong 已提交
77
*/
78
- (NSArray *)predict:(CGImageRef)image dim:(NSArray<NSNumber *> *)dim;
L
liuruilong 已提交
79 80

/*
L
liuruilong 已提交
81
    清理内存
L
liuruilong 已提交
82
*/
83 84 85
- (void)clear;

@end