NameError: name 'skimage' is not defined

NameError: name 'skimage' is not defined

我正在尝试弄清楚如何使用来自我自己的数据集的图像使用 SVM 进行图像分类,我正在使用他 link 的笔记本: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)