[关闭]
@superpigy 2019-05-10T23:19:22.000000Z 字数 1424 阅读 36

简单文档

未分类


MLProcessPipeline

Pipeline中可以添加多个子步骤, 图片可以通过多个模型. 每个步骤完成后都有回调

用法:

  1. MLProcessPipeline CreatePipeline(Bitmap bm){
  2. MLProcessPipeline pipeline = new MLProcessPipeline(getActivity(), "cow_pipeline", 192, true, bm);
  3. int nTops = 10;
  4. /*
  5. BatchSize, number of items, dimension 4
  6. BatchSize, number of items, dimension 1
  7. BatchSize, number of items, dimension 1
  8. BatchSize, number of items, dimension 1
  9. */
  10. Map<Integer, Object> map = new ArrayMap<>();
  11. float[][][] outputLocations = new float[1][nTops][4];
  12. float[][] outputClassifyResult = new float[1][nTops];
  13. float[][] outputScores = new float[1][nTops];
  14. float[] outputDetectNum = new float[1];
  15. map.put(0, outputLocations);
  16. map.put(1, outputClassifyResult);
  17. map.put(2, outputScores);
  18. map.put(3, outputDetectNum);
  19. Pipeline中添加子步骤
  20. pipeline.addPipelineProcess("cow_detect", "cow_detect.tflite", map, 3, 1, nTops, 0.5f);
  21. /*
  22. Pipeline中子步骤执行完回调
  23. */
  24. pipeline.setOnRequestDoneHandler((MLProcessRequest p)->{
  25. try
  26. {
  27. if(p.requestModelIdentifier == "cow_detect"){
  28. drawCowRect(p);
  29. }
  30. Log.e("aaa", "Process request with id : " + p.requestModelIdentifier + " is done");
  31. return true;
  32. }
  33. catch (Exception e){
  34. Log.e("aaa", "Process request with id : " + p.requestModelIdentifier + " is failed");
  35. return false;
  36. }
  37. });
  38. /*
  39. Pipeline执行完回调
  40. */
  41. pipeline.setOnPipelineDoneHandler((MLProcessPipeline p)->{
  42. Log.e("aaa", "Process pipeline with id : " + p.Id + " is done");
  43. endProcess();
  44. return true;
  45. });
  46. return pipeline;
  47. }
  48. MLProcessPipeline pipeline = CreatePipeline(bitmap);
  49. try {
  50. MLProcessor.defaultProcessor.processMLRequestPipeline(pipeline);
  51. } catch (Exception e) {
  52. e.printStackTrace();
  53. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注