This section of the chapter will provide the basic idea on how to write the code for CNN using Deeplearning4j. You'll be able to learn the syntax for using the various hyperparameters mentioned in this chapter.
To implement CNN using Deeplearning4j, the whole idea can be split into three core phases: loading data or preparation of the data, network configuration, and training and evaluation of the model.
For CNNs, generally, we only work on the image data to train the model. In Deeplearning4j, the images can be read using ImageRecordReader
. The following code snippet shows how to load 16Ã16 color images for the model:
RecordReader imageReader = new ImageRecordReader(16, 16, false); imageReader.initialize(new FileSplit(new File(System.getProperty("user.home"), "image_location")));
After that, using CSVRecordReader
, we can load all the image labels from the input CSV files, as follows:
int numLinesToSkip = 0; String delimiter = ","; RecordReader...