问题描述
尝试从 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
解决方法
从 Spark 2.4 开始,图像可以使用 image
格式直接加载 DataFrameReader:
zero_df = spark.read.format("image").load(<path to files>)
可以在here找到更多详细信息。
从那时起 ImageSchema.readImages
的用法一直是 deprecated,并且该方法已在 Spark 3.0.0 中删除