标签:data 通道数 image soft 高级 park 路径 struct 架构
图像数据源用于从目录加载图像文件,它可以通过ImageIO Java库将压缩图像(jpeg,png等)加载为原始图像表示形式。加载的DataFrame具有一StructType列:“ image”,其中包含存储为图像架构的图像数据。该image列的架构为:
StringType代表图像的文件路径)IntegerType图像的高度)IntegerType图像的宽度)IntegerType图像通道数)IntegerType兼容OpenCV的类型)BinaryType以OpenCV兼容顺序的图像字节:大多数情况下按行BGR)代码实现:
val image_df = spark.read.format("image").option("dropInvalid", true)
.load("D:\\software\\spark-2.4.4\\data\\mllib\\images\\origin\\kittens")
image_df.schema.printTreeString()
image_df.select("image.origin", "image.width", "image.height")
.show(true)
执行结果:


LIBSVM数据源用于从目录加载“ libsvm”类型的文件。加载的DataFrame有两列:包含以double形式存储的标签编号和包含以Vectors存储的特征向量的特征。列的模式为:
DoubleType代表实例标签)VectorUDT代表特征向量)代码实现:
val libsvm_df = spark.read.format("libsvm").option("numFeatures", "780")
.load("D:\\software\\spark-2.4.4\\data\\mllib\\sample_libsvm_data.txt")
libsvm_df.show(10)
执行结果:

标签:data 通道数 image soft 高级 park 路径 struct 架构
原文地址:https://www.cnblogs.com/yszd/p/13628355.html