错误“\u ImageSchema”对象没有属性“readImages”

2024-07-05 07:35:47 发布

您现在位置:Python中文网/ 问答频道 /正文

正在尝试从pyspark中的文件夹加载图像

from pyspark.ml.image import ImageSchema
from pyspark.sql.functions import lit

zero_df = ImageSchema.readImages('../Transfer-Learning- 
PySpark/images/o').withColumn("label",lit(0))

抛出错误

     AttributeError                            Traceback (most recent call last)
     <ipython-input-9-29c9b120f9c2> in <module>
                   2 from pyspark.sql.functions import lit
                    3 
     ----> 4 zero_df = ImageSchema.readImages('../Transfer-Learning- 
     PySpark/images/o').withColumn("label",lit(0))

     AttributeError: '_ImageSchema' object has no attribute 'readImages'

Python 3.8 Spark v3.0.2


Tags: fromimportdfsqlfunctionspysparktransferlearning
1条回答
网友
1楼 · 发布于 2024-07-05 07:35:47

自Spark 2.4以来,可以使用image格式直接用DataFrameReader加载图像:

zero_df = spark.read.format("image").load(<path to files>)

更多详细信息请参见here

从那时起ImageSchema.readImages的用法一直是deprecated,该方法已在Spark 3.0.0中删除

相关问题 更多 >