提交 ad4730f9 编写于 作者: X xiaohaichun

update ssdar

上级 05316393
...@@ -31,8 +31,11 @@ ...@@ -31,8 +31,11 @@
self.queue = [self.device newCommandQueue]; self.queue = [self.device newCommandQueue];
// Do any additional setup after loading the view. // Do any additional setup after loading the view.
NSString *modelPath = [[NSBundle mainBundle] URLForResource:@"genet_model" withExtension:nil].path; // NSString *modelPath = [[NSBundle mainBundle] URLForResource:@"genet_model" withExtension:nil].path;
NSString *paramPath = [[NSBundle mainBundle] URLForResource:@"genet_params" withExtension:nil].path; // NSString *paramPath = [[NSBundle mainBundle] URLForResource:@"genet_params" withExtension:nil].path;
NSString *modelPath = [[NSBundle mainBundle] URLForResource:@"ar_model" withExtension:nil].path;
NSString *paramPath = [[NSBundle mainBundle] URLForResource:@"ar_params" withExtension:nil].path;
long fileSize; long fileSize;
FILE *fp; FILE *fp;
...@@ -55,16 +58,21 @@ ...@@ -55,16 +58,21 @@
fclose(parmaFilePointer); fclose(parmaFilePointer);
_modelConfig = [[ModelConfig alloc] init]; _modelConfig = [[ModelConfig alloc] init];
_modelConfig.means = @[[NSNumber numberWithFloat:128.0], [NSNumber numberWithFloat:128.0], [NSNumber numberWithFloat:128.0]]; // _modelConfig.means = @[[NSNumber numberWithFloat:128.0], [NSNumber numberWithFloat:128.0], [NSNumber numberWithFloat:128.0]];
_modelConfig.scale = 0.017; // _modelConfig.scale = 0.017;
_modelConfig.dims = @[[NSNumber numberWithFloat:1], [NSNumber numberWithFloat:128.], [NSNumber numberWithFloat:128.0],[NSNumber numberWithFloat:3.0]]; // _modelConfig.dims = @[[NSNumber numberWithFloat:1], [NSNumber numberWithFloat:128.], [NSNumber numberWithFloat:128.0],[NSNumber numberWithFloat:3.0]];
_modelConfig.means = @[[NSNumber numberWithFloat:103.94], [NSNumber numberWithFloat:116.78], [NSNumber numberWithFloat:123.68]];
_modelConfig.scale = 1;
_modelConfig.dims = @[[NSNumber numberWithFloat:1], [NSNumber numberWithFloat:160.], [NSNumber numberWithFloat:160.0],[NSNumber numberWithFloat:3.0]];
_modelConfig.modelPointer = buffer; _modelConfig.modelPointer = buffer;
_modelConfig.modelSize = (int)fileSize; _modelConfig.modelSize = (int)fileSize;
_modelConfig.paramPointer = parmaBuffer; _modelConfig.paramPointer = parmaBuffer;
_modelConfig.paramSize = (int)paramfileSize; _modelConfig.paramSize = (int)paramfileSize;
} }
- (IBAction)loaderButtonPressed:(id)sender { - (IBAction)loaderButtonPressed:(id)sender {
_runner = [[PaddleMobileGPU alloc] initWithCommandQueue:self.queue net:GenetType modelConfig:_modelConfig]; // _runner = [[PaddleMobileGPU alloc] initWithCommandQueue:self.queue net:GenetType modelConfig:_modelConfig];
_runner = [[PaddleMobileGPU alloc] initWithCommandQueue:self.queue net:MobileNetSSDType modelConfig:_modelConfig];
[_runner load]; [_runner load];
} }
- (IBAction)predictButtonPressed:(id)sender { - (IBAction)predictButtonPressed:(id)sender {
......
...@@ -27,6 +27,18 @@ public class MobileNet_ssd_AR: Net{ ...@@ -27,6 +27,18 @@ public class MobileNet_ssd_AR: Net{
dim = (n: 1, h: 160, w: 160, c: 3) dim = (n: 1, h: 160, w: 160, c: 3)
} }
@objc override public init(device: MTLDevice,paramPointer: UnsafeMutableRawPointer, paramSize:Int, modePointer: UnsafeMutableRawPointer, modelSize: Int) {
super.init(device:device,paramPointer:paramPointer,paramSize:paramSize,modePointer:modePointer,modelSize:modelSize)
means = [103.94, 116.78, 123.68]
scale = 1
except = 2
modelPath = ""
paramPath = ""
modelDir = ""
preprocessKernel = MobilenetssdPreProccess.init(device: device)
dim = (n: 1, h: 160, w: 160, c: 3)
}
class MobilenetssdPreProccess: CusomKernel { class MobilenetssdPreProccess: CusomKernel {
init(device: MTLDevice) { init(device: MTLDevice) {
let s = CusomKernel.Shape.init(inWidth: 160, inHeight: 160, inChannel: 3) let s = CusomKernel.Shape.init(inWidth: 160, inHeight: 160, inChannel: 3)
...@@ -90,32 +102,32 @@ public class MobileNet_ssd_AR: Net{ ...@@ -90,32 +102,32 @@ public class MobileNet_ssd_AR: Net{
let v = program.scope[output]! let v = program.scope[output]!
let originTexture = v as! Texture<Float32> let originTexture = v as! Texture<Float32>
originTexture.tensorDim = Dim.init(inDim: [originTexture.tensorDim[1] / 7, originTexture.tensorDim[0] * 7]) originTexture.tensorDim = Dim.init(inDim: [originTexture.tensorDim[1] / 7, originTexture.tensorDim[0] * 7])
originTexture.dim = Dim.init(inDim: [1, 1, originTexture.dim[3] / 7, originTexture.dim[2] * 7]) originTexture.dim = Dim.init(inDim: [1, 1, originTexture.dim[3] / 7, originTexture.dim[2] * 7])
originTexture.padToFourDim = Dim.init(inDim: [1, 1, originTexture.padToFourDim[3] / 7, originTexture.padToFourDim[2] * 7]) originTexture.padToFourDim = Dim.init(inDim: [1, 1, originTexture.padToFourDim[3] / 7, originTexture.padToFourDim[2] * 7])
program.scope[output] = originTexture program.scope[output] = originTexture
if i == 99 { if i == 99 {
opDesc.attrs["axis"] = 0 opDesc.attrs["axis"] = 0
} else { } else {
opDesc.attrs["shape"] = originTexture.tensorDim.dims.map { Int32($0) } opDesc.attrs["shape"] = originTexture.tensorDim.dims.map { Int32($0) }
} }
} }
for i in [58, 59, 88, 89, 95, 96, 68, 69, 78, 79] { for i in [58, 59, 88, 89, 95, 96, 68, 69, 78, 79] {
let opDesc = program.programDesc.blocks[0].ops[i] let opDesc = program.programDesc.blocks[0].ops[i]
let output = opDesc.outputs["Out"]!.first! let output = opDesc.outputs["Out"]!.first!
let v = program.scope[output]! let v = program.scope[output]!
let originTexture = v as! Texture<Float32> let originTexture = v as! Texture<Float32>
originTexture.tensorDim = Dim.init(inDim: [originTexture.tensorDim[1], originTexture.tensorDim[2]]) originTexture.tensorDim = Dim.init(inDim: [originTexture.tensorDim[1], originTexture.tensorDim[2]])
opDesc.attrs["shape"] = originTexture.tensorDim.dims.map { Int32($0) } opDesc.attrs["shape"] = originTexture.tensorDim.dims.map { Int32($0) }
} }
for i in [60, 101, 90, 97, 70, 80] { for i in [60, 101, 90, 97, 70, 80] {
let opDesc = program.programDesc.blocks[0].ops[i] let opDesc = program.programDesc.blocks[0].ops[i]
let output = opDesc.outputs["Out"]!.first! let output = opDesc.outputs["Out"]!.first!
...@@ -124,7 +136,7 @@ public class MobileNet_ssd_AR: Net{ ...@@ -124,7 +136,7 @@ public class MobileNet_ssd_AR: Net{
originTexture.tensorDim = Dim.init(inDim: [originTexture.tensorDim[1], originTexture.tensorDim[2]]) originTexture.tensorDim = Dim.init(inDim: [originTexture.tensorDim[1], originTexture.tensorDim[2]])
opDesc.attrs["axis"] = (opDesc.attrs["axis"]! as! Int) - 1 opDesc.attrs["axis"] = (opDesc.attrs["axis"]! as! Int) - 1
} }
for i in [102] { for i in [102] {
let opDesc = program.programDesc.blocks[0].ops[i] let opDesc = program.programDesc.blocks[0].ops[i]
for output in opDesc.outputs["Out"]! { for output in opDesc.outputs["Out"]! {
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
if (netType == GenetType) { if (netType == GenetType) {
net = [[Genet alloc] initWithDevice:queue.device paramPointer:config.paramPointer paramSize:config.paramSize modePointer:config.modelPointer modelSize:config.modelSize]; net = [[Genet alloc] initWithDevice:queue.device paramPointer:config.paramPointer paramSize:config.paramSize modePointer:config.modelPointer modelSize:config.modelSize];
} else if (netType == MobileNetSSDType) { } else if (netType == MobileNetSSDType) {
net = [[MobileNet_ssd_hand alloc] initWithDevice:queue.device paramPointer:config.paramPointer paramSize:config.paramSize modePointer:config.modelPointer modelSize:config.modelSize]; net = [[MobileNet_ssd_AR alloc] initWithDevice:queue.device paramPointer:config.paramPointer paramSize:config.paramSize modePointer:config.modelPointer modelSize:config.modelSize];
} else if (netType == MobileNetType) { } else if (netType == MobileNetType) {
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册