加载模型并使用keras和tensorflow进行预测

时间:2018-03-26 02:17:22

标签: tensorflow keras

我需要一些帮助。 如何尝试加载模型并从本教程预测(https://cloud.google.com/blog/big-data/2017/10/intro-to-text-classification-with-keras-automatically-tagging-stack-overflow-posts)。

我想要实现的是创建另一个python文件来加载模型并进行预测。我可以从该教程中保存模型,但不确定如何预测。

max_words = 1000
tokenize = text.Tokenizer(num_words=max_words, char_level=False)
txt = "angular expression in ng-repeat and ng-click  i am trying to call a function using <code>ng-click</code> which is dynamically generated by <code>ng-repeat</code> the problem is that i am not able to get the parameter value passed in <code>ng-click</code> function. my html code is   <pre><code>&lt;div class= col-md-4 col-xs-12 col-lg-4  ng-repeat= (key  value) in uploadedfiles &gt;     &lt;b&gt;value.filename is {{value.filename}}&lt;/b&gt;     &lt;img ng-if= value.filetype== jpg   ng-src= http://localhost:3000/uploads/{{value.filename}}  class= img img-responsive thumbnail uploadedfile-thumb /&gt;     &lt;img ng-if= value.filetype== pdf   ng-src= images/pdf-thumb.jpg  class= img img-responsive thumbnail uploadedfile-thumb /&gt;     &lt;a ng-href= http://localhost:3000/uploads/{{value.filename}}  target= _blank  class= uploaded-file-links &gt;view&lt;/a&gt;     &lt;a ng-href= #  ng-click= deletefile(value.filename);  class= uploaded-file-links &gt;delete&lt;/a&gt; &lt;/div&gt; </code></pre>   i am not getting the filename which is passed in <code>deletefile()</code>  bit it is working in <code>&lt;b&gt;</code> tag in 2nd line so finally this is a problem with my angular expression so how should i write it"
tokenize.fit_on_texts(txt)
x_test = tokenize.texts_to_matrix(txt)
print(x_test.shape)
prediction = model.predict(np.array([x_test[0]]))

我收到此错误消息

  

ValueError:检查时出错:期望的dense_1_input有2个维度,但是有形状的数组(1,1223,1000)

您能帮忙提供正确的样品吗?

0 个答案:

没有答案