python - 名称错误 : name 'skimage' is not defined

标签 python svm scikit-image train-test-split

我试图弄清楚如何使用 SVM 使用我自己的数据集中的图像进行图像分类,我使用他的链接中的笔记本:https://github.com/whimian/SVM-Image-Classification 。问题是,对于我使用 skimage 的任何其他项目,它都可以正常工作,但对于这个项目,我在以下行的标题中收到上述错误:

img = skimage.io.imread(file)

我已经使用了命令 pip uninstall scikit-image 并安装,但仍然不起作用。

此外,下线出现以下错误,不确定是否与此问题有关:

image_dataset.data, image_dataset.target, test_size=0.3,random_state=109

NameError: name 'image_dataset' is not defined


clf.fit(X_train, y_train)

NameError: name 'X_train' is not defined

为了可视化,这里是错误所属的代码片段:

image_dir = Path(container_path)
folders = [directory for directory in image_dir.iterdir() if directory.is_dir()]
categories = [fo.name for fo in folders]

descr = "A image classification dataset"
images = []
flat_data = []
target = []
for i, direc in enumerate(folders):
    for file in direc.iterdir():
        img = skimage.io.imread(file)
        img_resized = resize(img, dimension, anti_aliasing=True, mode='reflect')
        flat_data.append(img_resized.flatten()) 
        images.append(img_resized)
        target.append(i)
flat_data = np.array(flat_data)
target = np.array(target)
images = np.array(images)

return Bunch(data=flat_data,
             target=target,
             target_names=categories,
             images=images,
             DESCR=descr)

至于进口:

from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
%matplotlib notebook
from sklearn import svm, metrics, datasets
from sklearn.utils import Bunch
from sklearn.model_selection import GridSearchCV, train_test_split

from skimage.io import imread
from skimage.transform import resize

最佳答案

 img = skimage.io.imread(file)

将此行更改为

 img = imread(file)

关于python - 名称错误 : name 'skimage' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61567096/

相关文章:

r - 如何在R中使用e1071包的 'svm'进行多类分类

r - R中的SVM:“预测变量必须是数字或有序的。”

python - 如何在 scikit learn 中使用向量作为特征

Python Slippy-map 平铺生成

python - 使用 Twisted Python 的多个通信 channel

python - 单击按钮时 Odoo 重新加载

Python > Selenium + CSV : Webdriver to read, 访问 .csv 文件中的所有链接

python - 识别具有相同值的下一行并创建新列 pandas 数据框

python - 在 Python 中为图像中的每个像素选择 7*7 相邻像素的最快方法

python - 图像去模糊