【问题标题】:CNN for Sentiment Analysis using TFLearn model for Android to classify user input使用 TFLearn 模型进行情感分析的 CNN 对用户输入进行分类
【发布时间】:2018-09-13 18:14:36
【问题描述】:

我有一个用于文本分类的 CNN 模型,它使用预先训练的手套嵌入。我已经冻结了为推理优化的图形,并在 android studio 上使用它。问题是当我尝试将权重传递给模型进行推理时。我有一个 JSON 文件,其中包含单词和嵌入之间的键值对,用于从用户输入的文本中创建嵌入的输入。我已经可以从 JSON 文件中获取嵌入,但是当我尝试将其输入图表进行推理,它给了我以下错误:

java.lang.IllegalArgumentException: indices[0,3891] = -2 is not in [0, 
7459)
[[Node: EmbeddingLayer/embedding_lookup = Gather[Tindices=DT_INT32, 
Tparams=DT_FLOAT, _class=["loc:@EmbeddingLayer/W"], 
validate_indices=false, 
_device="/job:localhost/replica:0/task:0/device:CPU:0"] 

(EmbeddingLayer/W/read, EmbeddingLayer/Cast)]]

Android 代码在我的 GitHub 中 https://github.com/sushiboo/testNN1

给我带来问题的主要代码是 Classify 方法:

private void classify(float[] input){
TFInference = new TensorFlowInferenceInterface(getAssets(), MODEL_FILE);

TFInference.feed(INPUT_NODE, input, 1, input.length);
TFInference.run(OUTPUT_NODES);
float[] resu = new float[2];
TFInference.fetch(OUTPUT_NODE, resu);
tvResult.setText("Programmer: " + Float.toString(resu[0]) + "\n Construction" +  Float.toString(resu[1]));
Log.e("Result: ", Float.toString(resu[0]));
}

问题出在

TFInference.run(OUTPUT_NODES);

在错误消息中,数字“7459”表示嵌入层的输入维度。

我对这里发生的事情感到非常困惑,但我知道 index[0,3891] = -2 在其中起了一定作用。

【问题讨论】:

    标签: java android tensorflow tflearn


    【解决方案1】:

    问题出在模特儿身上。我已经修复了这个问题,现在我遇到了另一个错误。

    【讨论】:

      猜你喜欢
      • 2018-09-10
      • 2017-01-19
      • 2017-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-21
      • 1970-01-01
      相关资源
      最近更新 更多