sparknlp.base.image_assembler
#
Contains classes for the ImageAssembler.
Module Contents#
Classes#
Prepares images read by Spark into a format that is processable by Spark NLP. |
- class ImageAssembler[source]#
Prepares images read by Spark into a format that is processable by Spark NLP. This component is needed to process images.
Input Annotation types
Output Annotation type
NONE
IMAGE
- Parameters:
- inputCol
Input column name
- outputCol
Output column name
Examples
>>> import sparknlp >>> from sparknlp.base import * >>> from pyspark.ml import Pipeline >>> data = spark.read.format("image").load("./tmp/images/").toDF("image") >>> imageAssembler = ImageAssembler().setInputCol("image").setOutputCol("image_assembler") >>> result = imageAssembler.transform(data) >>> result.select("image_assembler").show() >>> result.select("image_assembler").printSchema() root |-- image_assembler: array (nullable = true) | |-- element: struct (containsNull = true) | | |-- annotatorType: string (nullable = true) | | |-- origin: string (nullable = true) | | |-- height: integer (nullable = true) | | |-- width: integer (nullable = true) | | |-- nChannels: integer (nullable = true) | | |-- mode: integer (nullable = true) | | |-- result: binary (nullable = true) | | |-- metadata: map (nullable = true) | | | |-- key: string | | | |-- value: string (valueContainsNull = true)
- setInputCol(value)[source]#
Sets input column name.
- Parameters:
- valuestr
Name of the input column that has image format loaded via spark.read.format(“image”).load(PATH)
- setTextCol(value)[source]#
Sets an optional text column name.
- Parameters:
- valuestr
Name of an optional input text column
- classmethod loadImagesAsBytes(spark: pyspark.sql.SparkSession, path: str)[source]#
Loads images from a given path and returns them as raw bytes, instead of the default OpenCV-compatible format. Supported image types include JPEG, PNG, GIF, and BMP.
Multimodal inference with llama.cpp requires raw bytes as input.
- Parameters:
- sparkSparkSession
The active SparkSession.
- pathstr
The path to the images. Supported image types are JPEG, PNG, GIF, and BMP.
- Returns:
- DataFrame
A DataFrame containing the images as raw bytes along with their metadata.