Tensorflow Lite示例无法替换模型(ArrayIndexOutOfBounds)

时间:2019-05-19 21:46:10

标签: java android-studio tensorflow tensorflow-lite yolo

我试图将tensorflow lite android示例(“ object_detection”)中的标准detect.tflite模型更改为我自己的模型,并使用tiny-YOLO进行了训练(但转换为.lite)。我收到以下错误:

Process: org.tensorflow.lite.examples.detection, PID: 21552
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1

我所做的是用自己的文件替换了。(tf)lite文件和labelmap文件。我还注释了加载标准模型的行:

// Download default models; if you wish to use your own models then
// place them in the "assets" directory and comment out this line.
//apply from: "download_model.gradle"

//apply from:'download_model.gradle'

这是我模型的元数据:

{"net": {"type": "[net]", "batch": 64, "subdivisions": 8, "width": 416, "height": 416, "channels": 3, "momentum": 0.9, "decay": 0.0005, "angle": 0, "saturation": 1.5, "exposure": 1.5, "hue": 0.1, "learning_rate": 0.001, "max_batches": 40200, "policy": "steps", "steps": "-1,100,20000,30000", "scales": ".1,10,.1,.1"}, "type": "[region]", "anchors": [1.08, 1.19, 3.42, 4.41, 6.63, 11.38, 9.42, 5.11, 16.62, 10.52], "bias_match": 1, "classes": 36, "coords": 4, "num": 5, "softmax": 1, "jitter": 0.2, "rescore": 1, "object_scale": 5, "noobject_scale": 1, "class_scale": 1, "coord_scale": 1, "absolute": 1, "thresh": 0.6, "random": 1, "model": "cfg/tiny-yolo-obj.cfg", "inp_size": [416, 416, 3], "out_size": [13, 13, 205], "name": "tiny-yolo-obj", "labels": ["Rosen 6", "Rosen 7", "Rosen 8", "Rosen 9", "Rosen 10", "Rosen Under", "Rosen Ober", "Rosen K\u00f6nig", "Rosen Ass", "Eichel 6", "Eichel 7", "Eichel 8", "Eichel 9", "Eichel 10", "Eichel Under", "Eichel Ober", "Eichel K\u00f6nig", "Eichel Ass", "Schellen 6", "Schellen 7", "Schellen 8", "Schellen 9", "Schellen 10", "Schellen Under", "Schellen Ober", "Schellen K\u00f6nig", "Schellen Ass", "Schilten 6", "Schilten 7", "Schilten 8", "Schilten 9", "Schilten 10", "Schilten Under", "Schilten Ober", "Schilten K\u00f6nig", "Schilten Ass"], "colors": [[254.0, 254.0, 254], [246.0625, 222.25, 127], [238.125, 190.5, 0], [230.1875, 158.75, -127], [222.25, 127.0, 254], [214.3125, 95.25, 127], [206.375, 63.5, 0], [198.4375, 31.75, -127], [190.5, 0.0, 254], [182.5625, -31.75, 127], [174.625, -63.5, 0], [166.6875, -95.25, -127], [158.75, -127.0, 254], [150.8125, -158.75, 127], [142.875, -190.5, 0], [134.9375, -222.25, -127], [127.0, 254.0, 254], [119.0625, 222.25, 127], [111.125, 190.5, 0], [103.1875, 158.75, -127], [95.25, 127.0, 254], [87.3125, 95.25, 127], [79.375, 63.5, 0], [71.4375, 31.75, -127], [63.5, 0.0, 254], [55.5625, -31.75, 127], [47.625, -63.5, 0], [39.6875, -95.25, -127], [31.75, -127.0, 254], [23.8125, -158.75, 127], [15.875, -190.5, 0], [7.9375, -222.25, -127], [0.0, 254.0, 254], [-7.9375, 222.25, 127], [-15.875, 190.5, 0], [-23.8125, 158.75, -127]]}

这是DetectorActivity中的代码:

  // Configuration values for the prepackaged SSD model.
  private static final int TF_OD_API_INPUT_SIZE = 416;
  private static final boolean TF_OD_API_IS_QUANTIZED = false;
  private static final String TF_OD_API_MODEL_FILE = "tiny-yolo-obj.lite";
  private static final String TF_OD_API_LABELS_FILE = "labelmap2.txt";
  private static final DetectorMode MODE = DetectorMode.TF_OD_API;
  // Minimum detection confidence to track a detection.
  private static final float MINIMUM_CONFIDENCE_TF_OD_API = 0.5f;
  private static final boolean MAINTAIN_ASPECT = false;
  private static final Size DESIRED_PREVIEW_SIZE = new Size(640, 480);
  private static final boolean SAVE_PREVIEW_BITMAP = false;
  private static final float TEXT_SIZE_DIP = 10;

在其他类似问题上,人们被告知将DetectorMode设置为DetectorMode.YOLO,但这样做时我的程序无法构建。

任何人都可以发现我必须更改的参数才能使模型工作吗?还是该解决方案需要更复杂的步骤?预先感谢您的帮助!

0 个答案:

没有答案