Preparing the ND4j dataset

As I said, we need an intermediate conversion and pre-process to get the training set to contain feature vectors as well as labels. The conversion is pretty straightforward: we need the feature vector and the business labels.

For this, we have the makeND4jDataSets class (see makeND4jDataSets.scala for details). The class creates a ND4j dataset object from the data structure from the alignLables function in the form of List[(imgID, bizID, labels, pixelVector)]. First, we prepare the dataset using the makeDataSet() method:

def makeDataSet(alignedData: featureAndDataAligner, bizClass: Int): DataSet = {
val alignedXData = alignedData.getImgVectors.toNDArray
val alignedLabs = alignedData.getBusinessLabels.map(x =>
if (x.contains(bizClass)) Vector(1, 0)
else Vector(0, 1)).toNDArray
new DataSet(alignedXData, alignedLabs)
}

Then we need to convert the preceding data structure further, into INDArray, which can then be consumed by the CNNs:

def makeDataSetTE(alignedData: featureAndDataAligner): INDArray = {
alignedData.getImgVectors.toNDArray
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset