Python “获取错误”;TypeError:无法将序列转换为<;类别';int'&燃气轮机&引用;在for循环中查找图像的感兴趣区域时

Python “获取错误”;TypeError:无法将序列转换为<;类别';int'&燃气轮机&引用;在for循环中查找图像的感兴趣区域时,python,scikit-learn,anaconda,data-science,Python,Scikit Learn,Anaconda,Data Science,我是数据科学的新手,正在尝试处理我的图像。下面是自定义转换器的代码,我使用它首先将图像转换为灰度,然后进行裁剪,然后调整大小。 当对单个图像执行这些方法时,不会显示此类错误。 但在For循环中执行时,获取类型错误 class Preprocessing(TransformerMixin): def __init__(self,dataset): # the constructor lets you specify which channel to select

我是数据科学的新手,正在尝试处理我的图像。下面是自定义转换器的代码,我使用它首先将图像转换为灰度,然后进行裁剪,然后调整大小。 当对单个图像执行这些方法时,不会显示此类错误。 但在For循环中执行时,获取类型错误

class Preprocessing(TransformerMixin):
    def __init__(self,dataset):
        # the constructor lets you specify which channel to select
        self.dataset=dataset
        X_data=[]
        #self.image_files=image_files

    def fit(self):
        # If the transformation depends on attributes of the training data
        # you can check those attributes here and store them on `self`.
        # However most transformers are "stateless" and immediately return self.
        return self

    def transform(self,image_files):
        # the transform method does the extraction
        X_data=[]
        for raw_image in image_files:
            image=cv2.imread(raw_image)
            image_gray=skimage.util.img_as_ubyte(skimage.color.rgb2grey(image[:,:,::-1]))
            row=self.dataset.index[self.dataset['Filename']==raw_image].tolist()
            row_data=self.dataset.iloc[row,:]
            Roi_X1=self.dataset.iloc[row,3]
            Roi_Y1=self.dataset.iloc[row,4]
            Roi_X2=self.dataset.iloc[row,5]
            Roi_Y2=self.dataset.iloc[row,6]
            region_of_interest=image_gray[int(Roi_X1):int(Roi_X2),int(Roi_Y1):int(Roi_Y2)]
            region_of_interest=skimage.util.img_as_ubyte(region_of_interest)
            image_resized = resize(region_of_interest, (64,64),anti_aliasing=True)
            image_resized=skimage.util.img_as_ubyte(image_resized)
            X_data.append(image_resized)


        return np.array(X_data, dtype='uint8')



dataset=pd.read_csv('Common.csv',sep=";")
image_files = [os.path.basename(x) for x in glob.glob('E:\Mtech\Machine learning\Assessment\My_data-Copy\Work_folder\*.ppm')] 
preprocessing_pipeline = Pipeline([('Image Preprocessing', Preprocessing(dataset))])
my_processed_images = preprocessing_pipeline.transform(image_files)
错误显示在第行中

---> 26  region_of_interest=image_gray[int(Roi_X1):int(Roi_X2),int(Roi_Y1):int(Roi_Y2)]
as 
~\Anaconda3\lib\site-packages\pandas\core\series.py in wrapper(self) --> 131  raise TypeError("cannot convert the series to " "{0}".format(str(converter)))
TypeError: cannot convert the series to class 'int'

... ... 您是否尝试在该行之前检查/打印相关数据以查看可能发生的情况?
Roi\ux?
应该是一个系列,还是你期望它是一个标量?或者您正在尝试将序列中的所有值转换为整数?列表中包含多少项:
row=self.dataset.index[self.dataset['Filename']==raw\u image].tolist()
?如果它不止一个,这意味着您正试图转换为具有多个值的int系列,这就是为什么会出现此错误。这本身就意味着在您的数据集中有重复项。@wwii I在对单个图像执行这些操作时确实打印了Roi_X1、Roi_X2、Roi_Y1、Roi_Y2。下面是输出行索引为[259]行数据是文件名宽度高度Roi.X1 Roi.Y1 Roi.X2 Roi.Y2 ClassId 259 00019_00001.ppm 92 96 8 84 88 28 X1是259 8名称:Roi.X1,数据类型:int64 Y1是259 8名称:Roi.Y1,数据类型:int64 X2是259 84名称:Roi.X2,数据类型:int64 Y2是259 88名称:Roi.Y2,数据类型:int64。有了这个Roi度量,我得到了单个图像的裁剪,但当用于it显示时error@Namarta
row
是整数列表,因为您在末尾调用了
tolist
。如果该列表中的整数数为1,则代码将正常工作,否则将抛出错误。检查
行的长度