提交 b068788c 编写于 作者: X xiaohaichun 提交者: GitHub

Merge pull request #1001 from xiaohaichun/metal

add  gpu predict interface
......@@ -126,14 +126,23 @@
- (void)predict {
_texture = [self createTextureFromImage:[UIImage imageNamed:@"hand.jpg"] device:self.device];
[_runner predict:_texture withCompletion:^(BOOL success , NSArray<NSNumber *> *result) {
if (success) {
for (int i = 0; i < result.count; i ++) {
NSNumber *number = result[i];
NSLog(@"result %d = %f:",i, [number floatValue]);
NSTimeInterval startTime = [[NSDate date] timeIntervalSince1970];
NSInteger max = 428;
for (int i = 0;i < max; i ++) {
[_runner predict:_texture withCompletion:^(BOOL success , NSArray<NSNumber *> *result) {
if (success) {
if (i == max -1) {
double time = [[NSDate date] timeIntervalSince1970] - startTime;
time = (time/max)*1000;
NSLog(@"gap ==== %fms",time);
}
// for (int i = 0; i < result.count; i ++) {
// NSNumber *number = result[i];
// NSLog(@"result %d = %f:",i, [number floatValue]);
// }
}
}
}];
}];
}
}
- (void)didReceiveMemoryWarning {
......
......@@ -21,6 +21,16 @@ typedef enum : NSUInteger {
GenetType,
} NetType;
@interface PaddleMobileGPUResult: NSObject
@property (assign, nonatomic) float *output;
@property (assign, nonatomic) int outputSize;
-(void)releaseOutput;
@end
@interface ModelConfig: NSObject
/*
......@@ -81,6 +91,12 @@ typedef enum : NSUInteger {
*/
-(void)predict:(id<MTLTexture>)texture withCompletion:(void (^)(BOOL, NSArray<NSNumber *> *))completion;
/*
* texture: 需要进行预测的图像转换的 texture
* completion: 预测完成回调
*/
-(void)predict:(id<MTLTexture>)texture withResultCompletion:(void (^)(BOOL, PaddleMobileGPUResult *))completion;
/*
* 清理内存
*/
......
......@@ -14,6 +14,26 @@
@implementation ModelConfig
@end
@interface PaddleMobileGPUResult ()
@property (strong, nonatomic) ResultHolder *resultHolder;
- (void)setOutputResult:(ResultHolder *)resultHolder;
@end
@implementation PaddleMobileGPUResult
- (void)setOutputResult:(ResultHolder *)resultHolder {
self.resultHolder = resultHolder;
self.output = resultHolder.result;
self.outputSize = resultHolder.capacity;
}
-(void)releaseOutput {
[self.resultHolder releasePointer];
}
@end
@interface PaddleMobileGPU ()
{
Runner *runner;
......@@ -52,7 +72,14 @@
[result releasePointer];
}];
// [runner predictWithTexture:texture completion:completion];
}
-(void)predict:(id<MTLTexture>)texture withResultCompletion:(void (^)(BOOL, PaddleMobileGPUResult *))completion {
[runner predictWithTexture:texture completion:^(BOOL success, ResultHolder * _Nullable result) {
PaddleMobileGPUResult *gpuResult = [[PaddleMobileGPUResult alloc] init];
[gpuResult setOutputResult:result];
completion(success, gpuResult);
}];
}
-(void)clear {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册