TensorFlow标签编号与轴上的形状不匹配

时间:2020-02-01 18:55:19

标签: java android tensorflow classification tensorflow-lite

尝试运行代码实验室: https://codelabs.developers.google.com/codelabs/recognize-flowers-with-tensorflow-on-android/#6

我已经开发了自己的文件和列表文件,尽管当我开始通过Android运行它时似乎出现此错误:

java.lang.IllegalArgumentException: Label number 6 mismatch the shape on axis 1

然后将我链接到代码的这一部分:

Map<String, Float> labeledProbability =
        new TensorLabel(labels, probabilityProcessor.process(outputProbabilityBuffer))
            .getMapWithFloatValue();
    Trace.endSection();

这是在“分类结果”部分

public List<Recognition> recognizeImage(final Bitmap bitmap, int sensorOrientation) {
    // Logs this method so that it can be analyzed with systrace.
    Trace.beginSection("recognizeImage");

    Trace.beginSection("loadImage");
    long startTimeForLoadImage = SystemClock.uptimeMillis();
    inputImageBuffer = loadImage(bitmap, sensorOrientation);
    long endTimeForLoadImage = SystemClock.uptimeMillis();
    Trace.endSection();
    LOGGER.v("Timecost to load the image: " + (endTimeForLoadImage - startTimeForLoadImage));

    // Runs the inference call.
    Trace.beginSection("runInference");
    long startTimeForReference = SystemClock.uptimeMillis();
    tflite.run(inputImageBuffer.getBuffer(), outputProbabilityBuffer.getBuffer().rewind());
    long endTimeForReference = SystemClock.uptimeMillis();
    Trace.endSection();
    LOGGER.v("Timecost to run model inference: " + (endTimeForReference - startTimeForReference));

    // Gets the map of label and probability.
    Map<String, Float> labeledProbability =
        new TensorLabel(labels, probabilityProcessor.process(outputProbabilityBuffer))
            .getMapWithFloatValue();
    Trace.endSection();

    // Gets top-k results.
    return getTopKProbability(labeledProbability);
  } 

不知道为什么这样行得通吗?

1 个答案:

答案 0 :(得分:0)

很抱歉迟到了。 labels.txt文件中可能有一些空行,或者labels.txt文件中可能有一些额外的标签。要检查一下。

相关问题