【发布时间】:2018-09-01 07:31:33
【问题描述】:
我是机器学习的新手。我试图在数据集上进行预测,但是当我运行程序时,它给了我以下错误:
NameError: name 'classifier' is not defined
这是我的代码:
import numpy as np
from keras.preprocessing import image
test_image = image.load_img('dataset/single_prediction/1.jpg', target_size = (64, 64))
test_image = image.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis = 0)
result = classifier.predict(test_image)
training_set.class_indices
if result[0][0] == 1:
prediction = 'nsfw'
else:
prediction = 'sfw'
【问题讨论】:
-
这是意料之中的。您还没有在任何地方定义分类器
-
您必须为此目的加载已保存的分类器
标签: python-3.x tensorflow machine-learning keras prediction