Use ImageSchema from PySpark to apply Principal Components Analysis

Viewed 295

I have three different PySpark Dataframe containing images. When I print these ImageSchema, I have this :

root
 |-- image: struct (nullable = true)
 |    |-- origin: string (nullable = true)
 |    |-- height: integer (nullable = true)
 |    |-- width: integer (nullable = true)
 |    |-- nChannels: integer (nullable = true)
 |    |-- mode: integer (nullable = true)
 |    |-- data: binary (nullable = true)

I want to apply a PCA (or another dimension reduction from Pyspark) on these, but I can't understand how to do this. I think of using pandas_udf, as I see that DeepImageFeaturizer from DataBricks is now deprecated and pandas_udf is now advised, but I can't understand how to use it for this type of data...

# Different examples of lines I saw on tutorials to use pandas_udf

multiple_test_udf = pandas_udf(multiple_test_df['image.data'], returnType=?)

pandas_udf(return_type, PandasUDFType.SCALAR_ITER)

I think that image.data of ImageSchema is the only interesting part in the ImageSchema to apply my PCA, and image.data is the one to be converted as pandas_udf. Also, I think pandas_udf is the input of the PCA. I "just" don't understand how to do these steps in practise...

Thanks for your help ;)

PS : I use :

  • Python 3.7
  • Pyspark 3.0
  • Pandas 0.24 I run my code on a Jupyter Notebook put into an Anaconda 3 server.
1 Answers

Update of the day !

With more researches and some help, I have a theorical idea :

  1. use image.data and transform it into a tensorflow-compatible format
  2. do a dimension reduction with mobilenetv2
  3. shape data to make it compatible with pandas_udf output
  4. apply classification model (for example)

I just can't find how to do points 1) and 3)

Related