gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 14:27:01 27 4
gpt4 key购买 nike

尝试运行代码实验室:
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);
}

不知道为什么这是有效的,任何人都可以帮忙吗?

最佳答案

对不起,来晚了。
您的 labels.txt 文件中可能有一些空行,或者您的 labels.txt 文件中可能有一些额外的标签。检查一下。

关于java - TensorFlow 标签号与轴上的形状不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60020156/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com