@@ -14,10 +14,11 @@ import org.apache.spark.storage.StorageLevel
1414 * ImageDataFrame expects dataframe with 2 required columns (lable:String, data:byte[]),
1515 * and 5 optional columns (id: String, channels :Int, height:Int, width:Int, encoded: Boolean).
1616 *
17- * ImageDataFrame could be configured via 2 MemoryDataLayer parameter:
17+ * ImageDataFrame could be configured via the following MemoryDataLayer parameter:
1818 * (1) dataframe_column_select ... a collection of dataframe SQL selection statements
1919 * (ex. "sampleId as id", "abs(height) as height")
20- * (2) image_ecnoded ... indicate whether image data are encoded or not. (default: false)
20+ * (2) image_encoded ... indicate whether image data are encoded or not. (default: false)
21+ * (3) dataframe_format ... Dataframe Format. (default: parquet)
2122 *
2223 * @param conf CaffeSpark configuration
2324 * @param layerId the layer index in the network protocol file
@@ -30,7 +31,10 @@ class ImageDataFrame(conf: Config, layerId: Int, isTrain: Boolean)
3031 def makeRDD (sc : SparkContext ): RDD [(String , String , Int , Int , Int , Boolean , Array [Byte ])] = {
3132 val sqlContext = new SQLContext (sc)
3233 // load DataFrame
33- var df : DataFrame = sqlContext.read.format(conf.inputFormat).load(sourceFilePath)
34+ var reader = sqlContext.read
35+ if (memdatalayer_param.hasDataframeFormat())
36+ reader = reader.format(memdatalayer_param.getDataframeFormat())
37+ var df : DataFrame = reader.load(sourceFilePath)
3438
3539 // select columns if specified
3640 if (memdatalayer_param.getDataframeColumnSelectCount() > 0 ) {
@@ -67,28 +71,4 @@ class ImageDataFrame(conf: Config, layerId: Int, isTrain: Boolean)
6771 (id, label, channels, height, width, encoded, data)
6872 }).persist(StorageLevel .DISK_ONLY )
6973 }
70- }
71-
72- /**
73- * ImageDataFrame using Parquet data frame format
74- *
75- * @param conf CaffeSpark configuration
76- * @param layerId the layer index in the network protocol file
77- * @param isTrain
78- */
79- class ImageDataFrameParquet (conf : Config , layerId : Int , isTrain : Boolean )
80- extends ImageDataFrame (conf, layerId, isTrain) {
81- conf.inputFormat = " parquet"
82- }
83-
84- /**
85- * ImageDataFrame using Json data frame format
86- *
87- * @param conf CaffeSpark configuration
88- * @param layerId the layer index in the network protocol file
89- * @param isTrain
90- */
91- class ImageDataFrameJson (conf : Config , layerId : Int , isTrain : Boolean )
92- extends ImageDataFrame (conf, layerId, isTrain) {
93- conf.inputFormat = " json"
94- }
74+ }
0 commit comments