This tutorial shows how to create a simple binary image classifier using a convolutional neural network, that can assign images of Java community mascot, Duke, to one of two possible categories:
1) Duke or
2) Non-Duke image.
Step by Step Instructions
- Download the Deep Netts
- Download the image data set with examples of Duke and Non-Duke images. Unpack downloaded zip.
- Run the Deep Netts development tool (for details you can look at Getting Started doc in the downloaded package)
- Create a new Deep Netts project by clicking [File > New Project] in the main menu, enter project name and click [Next]
- Choose [Classify Images] option and click [Next]
- Choose [Binary Classification] option (since there are only two categories of images: duke or non-duke image). Click [Next]
- Specify image directory to unpacked downloaded image set. Wizard will automatically detect or generate category labels image index. Click Next.
- Set image data preprocessing option: resize and center, uncheck invert pixels and upsample to balance classes. These settings are not critical for this small data set, so other settings would work as well. Click [Next]
- Specify small convolutional neural network architecture (add 1 convolutional layer with 3 channels that perform image filtering and feature detection, one max-pooling layer that scales down an image, and one fully connected layer that helps with classification with width 16). Other settings are preselected by the expert wizard for this type of task. Click [Next]
- Set main training parameters that include network architecture and training/test set split options (or accept settings provided by the expert wizard). Click Next.
- Set additional training algorithm parameters (or accept settings provided by the expert wizard ). Click Next.
- Run Training by right-clicking training file and then select [Run Training File] menu option. In training dialog check [Visualize Layers] option to be able to observe layer activity during the training. You can also observe network outputs, error and accuracy graphs and inspect detailed logs for each training iteration (aka epoch). You can analyze the training process and test metrics in log (confusion matrix, accuracy, precision, recall). An entire log file will be available for later inspection and comparison in [Training Logs] project folder.
- The trained convolutional network is available as a serialized object in [Trained Networks] project folder
- To test the classification of the trained model with the entire data set use [Tools > Test Image Set] in the main menu
- You can use the trained network in your Java application using Deep Netts library which is also available as a part of the download package.
To use the trained convolutional network in your Java app, use the following Java code:
// Load trained convolutional network ConvolutionalNetwork trainedNet= FileIO.createFromFile("trainedNetwork.dnet", ConvolutionalNetwork.class); // turn on image preprocessing used during the training ((ImagePreprocessing)trainedNet.getPreprocessing()).setEnabled(true); // Create image classifier based on trained network and VisRec API ImageClassifierNetwork imageClassifier = new ImageClassifierNetwork (trainedNet); // load image to classify BufferedImage image = ImageIO.read(new File("someImage.jpg")); // Classify new image and get probabilities for all possible classes Map<String, Float> results = imageClassifier.classify(image);
Follow the same procedure to create binary classifiers for other image sets, and note that it may require to tune some of the parameters.
- Machine Learning basics – if you’re completely new to machine learning
- From Basic Machine Learning to Deep Learning in 5 minutes – if you want to get a brief overview of the basic principles of deep learning and convolutional neural networks
- Basic Deep Learning Terms Explained Briefly – A very brief explanation of the common terms you find in deep learning examples. Also, let us know what would you like to see explained on Twitter @deepnetts use hashtag #explain