Ulog: Coding Neural Networks with Python part 2: the Convolutional Neural Network
Today I worked on building a Convolutional Neural Network, and let me tell you, it is quite convoluted.
Convolutional Neural Network
This Convolutional Neural Network will analyze images and determine whether it is an image of a cat or a dog. What makes it convoluted is the way it handles everything. First it takes an image file and compresses it down to a manageable size to reduce the number of pixels. Then it reduces the image further with some sampling and feature mapping. This could be things like detecting pointy ears, pupil shape, nose shape or length, whiskers, or any other feature or detail the AI might pick up on.
It then follows up with what's called pooling, where bits of data are averaged across a grid and again made smaller, even though more numerous.
Then it is flattened. End result of this step is all the values in the grids are stretched out and "flattened" in order to make a single line of data.
Next it is linked to a more simple Neural Network that just analyzes the parsed and optimized data. In this section, it goes through each piece collected and decides whether it's a dog part or a cat part. It then collects all the part decisions and outputs the best answer.
Here is the code to do all that.
I was given a folder containing 10,000 images for it to use: 8,000 to train and 2,000 to test. Using the last few lines of code, we begin the testing phase.
Pointing to the folder, the app reads all the pictures, then it decides cat or dog. In training, each image comes with the correct answer.
I started this before I left the office. Here's the output before I left for the day:
What this shows is it will process all 8000 training images 25 times, with each round being referred to as an epoch. With each epoch taking about a half hour, it should be just about done. I'll check it out in the morning and tell you how I did.
Posted using Partiko Android