我有几个图像样本,我想预测这些图像是否包含文本/字符。
我在此步骤中尝试运行代码时遇到错误:
model = cPickle.load(f)
is_text = model.predict(image_samples)
image_samples是我的样本,模型如下所示:
Pipeline(steps=[
('hog', HOGFeatures(cells_per_block=(2, 2), orientations=10,
pixels_per_cell=(5, 5), size=(20, 20))),
('clf', LinearSVC(C=2.0, class_weight=None, dual=True,
fit_intercept=True,
intercept_scaling=1, loss='l2', max_iter=None,
multi_class='ovr', penalty='l2',
random_state=None, tol=0.0001, verbose=0))
])
我得到的错误信息是:
File "/home/parallels/Desktop/Python/ImageTextRecognition-master/userimageski.py", line 104, in select_text_among_candidates
is_text = model.predict(self.candidates['flattened'])
File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/metaestimators.py", line 37, in <lambda>
out = lambda *args, **kwargs: self.fn(obj, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/sklearn/pipeline.py", line 180, in predict
return self.steps[-1][-1].predict(Xt)
File "/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/base.py", line 228, in predict
return self.classes_[indices]
AttributeError: 'LinearSVC' object has no attribute 'classes_'
有人能帮帮我吗? 非常感谢你
答案 0 :(得分:0)
我遇到了同样的问题。这实际上是sklearn版本的问题。在终端中运行python2.7并检查>>> import sklearn
>>> sklearn.__version__
如果你有一个以前的版本而不是当前版本,截至目前0.17.1是当前的,那么你需要升级sklearn。只需sudo pip install -U scikit-learn
升级并重新运行代码