【问题标题】:How do i use the saved weights to do prediction next time without any training process?如何在没有任何训练过程的情况下使用保存的权重进行下次预测?
【发布时间】:2019-05-25 19:42:05
【问题描述】:

我已经训练了一个用于肺炎检测的 CNN。我已将训练模型的权重保存在同一路径中。现在我重新启动程序后无法使用保存的模型来预测数据。

我尝试执行负责预测的特定代码行,但随后出现导入错误,从中我可以理解我必须重新运行整个程序,这又需要时间。这是实际的预测代码。

res = classifier.predict(test_image)
if res[0][0] == 1:
        prediction = 'pnemonia'
elif res[0][0] == 0:
        prediction = 'normal'
print(prediction)

实际结果一定是预测。相反,我得到了

Using TensorFlow backend.
Traceback (most recent call last):
  File "<input>", line 5, in <module>
NameError: name 'np' is not defined

【问题讨论】:

    标签: python keras model load predict


    【解决方案1】:

    np 通常是 Numpy 模块的简写。我打赌您需要在遇到错误的模块中import numpy as np。可能没有调用导入,因为您不再使用不同的模块来生成权重。

    【讨论】:

      猜你喜欢
      • 2021-02-28
      • 1970-01-01
      • 2020-01-12
      • 2016-07-26
      • 2020-02-19
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      相关资源
      最近更新 更多