Machine Learning in R: Airplanes vs Automobiles Building a Neural Network Using Your Own Images

In this project, I am going to teach you how to build your own Neural Network from scratch and training it on your own dataset. I am going to use 12 random images from the internet as my dataset: Six of the images are cars and six are airplanes (downloaded randomly). Since the images are of different sizes, I will show you how to pre-process them (which is a key learning from this project) and get them ready for the Neural Network. We will then split the images into a training and test set and train the Neural Network to perform this classification task.

Join for Free
Machine Learning in R: Airplanes vs Automobiles Building a Neural Network Using Your Own Images

Duration (mins)


5.0 / 5


Task List

We will cover the following tasks in 44 minutes:


In this task I am going to show you what we’re going to do in this tutorial. I will show you the random images we’re going to use as our dataset, I’ll explain how the Rhyme Interface works and finish telling you a little bit about me.

Loading Pictures

In this short task, we are going to have to do a little grunt work by creating a vector of names. This will help us in the following tasks by allowing us to pull in the images into R using a simple for loop.


I will show you how to upload the images into R using EBImage using a for loop. If you haven’t used a for loop before, no worries - I will explain what it is the loop is doing while we go through it. If you want to learn more about it don’t stop the video. Wait until after and do a google search - you can learn the for loop in 30 minutes.


The images that I pulled down from the Internet are all images of different sizes. However, our Neural Network model will expect training examples of the same exact shape. Therefore, we will need to resize the images so that they are all of the same shape. We will use a resize function in EBImage to complete this.

Reshaping Data for Neural Network

From this task onwards, we will be performing a basic Neural Network protocol. In this lesson we will be using the array_reshape function which allows us to reshape a multi dimensional array that will allow us to input the data into the Neural Network.

Creating Training Set

As you are probably aware when doing a Machine Learning problem or in this case a Neural Network we need to create the model using a training set. We then test our model on a testing set to see how well it performs. In our case we only have 12 images so we need to figure out how we’re going to set this up. Come on in and we’ll work through this.

Creating Test Set

In this task, we will be build out the test set. Again, since we’re only dealing with 12 images we will only have one image of an airplane and one image of a car in our test set. This will work, but is not ideal. Generally, you will want a much bigger training and test set. The purpose of this project is to show you how to create and train a Neural Networks from scratch using a custom dataset and not one of the pre-processed datasets which come packaged with deep learning libraries.

Creating Labels and One Hot Encoding

We need to set up our labels in this chapter. We will use categorical variables; say 0 and 1. 0 will represent absence of a class and 1 will represent presence of a class. We do this so that we can pass the images through the network and it will know whether it’s a plane or an automobile at the end of the network based on the output. The first index of the label vector represents the class Aeroplane and the second index represents the class Car.

Neural Network Framework

We will build the Neural Network architecture in this task. Our Neural Network will have just one hidden layer. We will be using relu activations on the hidden layer and softmax activations on the output layer. The softmax activation is a natural choice where we want probability distribution across our classes as our output. Once you get familiar with this terminology, building Neural Networks becomes easier. It takes a couple of models though before you get there. So be patient with yourself.

Training the Model

This is the moment of truth! In this task, we will be training our Neural Network model on the dataset. Since we have a very small dataset, it may take a few tries before the model actually catches on the relevant features of our images that help it classify the images properly.

Testing the Model

In this task, we are testing the model’s performance. Remember that we’re using a very small test set. But when we trained the model, we saw that it did very well. So it is likely to do well on a larger test set as well. In any event, this project is to show you how to set the problem up. You can make your models as big as you want or as small as the one we are creating today. You can use much larger training and test sets as well.

How Does Model Perform on New Images?

In this task, we’re going to test our model on images the model hasn’t seen. I happen to know that it works out pretty good. But I’ll show you how to get there. We will then do a quick overview of the journey we’ve taken and after that conclude!

Watch Preview

Preview the instructions that you will follow along in a hands-on session in your browser.

Rhyme Authors

About the Host

Rhyme Authors

Frequently Asked Questions

In Rhyme, all projects are completely hands-on. You don't just passively watch someone else. You use the software directly while following the host's (Rhyme Authors) instructions. Using the software is the only way to achieve mastery. With the "Live Guide" option, you can ask for help and get immediate response.
Nothing! Just join through your web browser. Your host (Rhyme Authors) has already installed all required software and configured all data.
Absolutely! Your host (Rhyme Authors) has provided this session completely free of cost!
You can go to, sign up for free, and follow this visual guide How to use Rhyme to create your own projects. If you have custom needs or company-specific environment, please email us at
Absolutely. We offer Rhyme for workgroups as well larger departments and companies. Universities, academies, and bootcamps can also buy Rhyme for their settings. You can select projects and trainings that are mission critical for you and, as well, author your own that reflect your own needs and tech environments. Please email us at
Rhyme strives to ensure that visual instructions are helpful for reading impairments. The Rhyme interface has features like resolution and zoom that will be helpful for visual impairments. And, we are currently developing a close-caption functionality to help with hearing impairments. Most of the accessibility options of the cloud desktop's operating system or the specific application can also be used in Rhyme. If you have questions related to accessibility, please email us at
We started with windows and linux cloud desktops because they have the most flexibility in teaching any software (desktop or web). However, web applications like Salesforce can run directly through a virtual browser. And, others like Jupyter and RStudio can run on containers and be accessed by virtual browsers. We are currently working on such features where such web applications won't need to run through cloud desktops. But, the rest of the Rhyme learning, authoring, and monitoring interfaces will remain the same.
Please email us at and we'll respond to you within one business day.

Ready to join this 44 minutes session for free?