Skip to content

Commit 018c7e3

Browse files
author
Andy Feng
committed
configure dataframe via prototxt, and remove format specific subclass
1 parent a05755d commit 018c7e3

5 files changed

Lines changed: 16 additions & 41 deletions

File tree

‎caffe-grid/src/main/scala/com/yahoo/ml/caffe/Config.scala‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ class Config(sc: SparkContext, args: Array[String]) extends Serializable {
2424
options.addOption("test", "test", false, "test mode")
2525
options.addOption("features", "features", true, "name of output blobs")
2626
options.addOption("label", "label", true, "name of label blobs to be included in features")
27-
options.addOption("inputFormat", "inputFormat", true,
28-
"input dataframe format, currently support json and parquet, default: json")
29-
options.addOption("select", "select", true, "Dataframe SQL statements. default: none")
3027
options.addOption("outputFormat", "outputFormat", true,
3128
"feature output format, currently support json and parquet, default: json")
3229
options.addOption("model", "model", true, "model path")
@@ -136,11 +133,7 @@ class Config(sc: SparkContext, args: Array[String]) extends Serializable {
136133
}
137134

138135
/**
139-
* Input dataframe format. json or parquet
140-
*/
141-
var inputFormat : String = if (cmd.hasOption("inputFormat")) cmd.getOptionValue("inputFormat") else "json"
142-
/**
143-
* Output dataframe format. json or parquet
136+
* Output dataframe format.
144137
*/
145138
var outputFormat : String = if (cmd.hasOption("outputFormat")) cmd.getOptionValue("outputFormat") else "json"
146139

@@ -212,7 +205,6 @@ class Config(sc: SparkContext, args: Array[String]) extends Serializable {
212205
buildr.append("test:").append(isTest).append("\n")
213206
buildr.append("features:").append(features.mkString(",")).append("\n")
214207
buildr.append("label:").append(label).append("\n")
215-
buildr.append("inputFormat:").append(inputFormat).append("\n")
216208
buildr.append("outputFormat:").append(outputFormat).append("\n")
217209
buildr.append("model:").append(modelPath).append("\n")
218210
buildr.append("output:").append(outputPath).append("\n")

‎caffe-grid/src/main/scala/com/yahoo/ml/caffe/ImageDataFrame.scala‎

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

‎caffe-public‎

‎data/lenet_dataframe_train_test.prototxt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ layer {
77
include {
88
phase: TRAIN
99
}
10-
source_class: "com.yahoo.ml.caffe.ImageDataFrameParquet"
10+
source_class: "com.yahoo.ml.caffe.ImageDataFrame"
1111
memory_data_param {
1212
source: "hdfs:///projects/machine_learning/image_dataset/mnist_train_dataframe/"
1313
batch_size: 64
@@ -28,7 +28,7 @@ layer {
2828
include {
2929
phase: TEST
3030
}
31-
source_class: "com.yahoo.ml.caffe.ImageDataFrameParquet"
31+
source_class: "com.yahoo.ml.caffe.ImageDataFrame"
3232
memory_data_param {
3333
source: "hdfs:///projects/machine_learning/image_dataset/mnist_test_dataframe/"
3434
batch_size: 100

‎scripts/travis/travis_install.sh‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ add-apt-repository -y ppa:kubuntu-ppa/backports
55
# for proto2.5
66
add-apt-repository -y ppa:chris-lea/protobuf
77
apt-get -y update
8-
./caffe-public/scripts/travis/travis_install.sh
8+
# remove CONDA directory
9+
rm -rf $CONDA_DIR
10+
# invoke BVLC caffe scripts
11+
./caffe-public/scripts/travis/travis_install.sh

0 commit comments

Comments
 (0)