@superpigy
2019-05-10T23:19:22.000000Z
字数 1424
阅读 36
未分类
Pipeline中可以添加多个子步骤, 图片可以通过多个模型. 每个步骤完成后都有回调
MLProcessPipeline CreatePipeline(Bitmap bm){
MLProcessPipeline pipeline = new MLProcessPipeline(getActivity(), "cow_pipeline", 192, true, bm);
int nTops = 10;
/*
BatchSize, number of items, dimension 4
BatchSize, number of items, dimension 1
BatchSize, number of items, dimension 1
BatchSize, number of items, dimension 1
*/
Map<Integer, Object> map = new ArrayMap<>();
float[][][] outputLocations = new float[1][nTops][4];
float[][] outputClassifyResult = new float[1][nTops];
float[][] outputScores = new float[1][nTops];
float[] outputDetectNum = new float[1];
map.put(0, outputLocations);
map.put(1, outputClassifyResult);
map.put(2, outputScores);
map.put(3, outputDetectNum);
Pipeline中添加子步骤
pipeline.addPipelineProcess("cow_detect", "cow_detect.tflite", map, 3, 1, nTops, 0.5f);
/*
Pipeline中子步骤执行完回调
*/
pipeline.setOnRequestDoneHandler((MLProcessRequest p)->{
try
{
if(p.requestModelIdentifier == "cow_detect"){
drawCowRect(p);
}
Log.e("aaa", "Process request with id : " + p.requestModelIdentifier + " is done");
return true;
}
catch (Exception e){
Log.e("aaa", "Process request with id : " + p.requestModelIdentifier + " is failed");
return false;
}
});
/*
Pipeline执行完回调
*/
pipeline.setOnPipelineDoneHandler((MLProcessPipeline p)->{
Log.e("aaa", "Process pipeline with id : " + p.Id + " is done");
endProcess();
return true;
});
return pipeline;
}
MLProcessPipeline pipeline = CreatePipeline(bitmap);
try {
MLProcessor.defaultProcessor.processMLRequestPipeline(pipeline);
} catch (Exception e) {
e.printStackTrace();
}