10.11.2016 Views

Learning Data Mining with Python

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Classifying Objects in Images Using Deep <strong>Learning</strong><br />

GPU optimization<br />

Neural networks can grow quite large in size. This has some implications for<br />

memory use; however, efficient structures such as sparse matrices mean that we<br />

don't generally run into problems fitting a neural network in memory.<br />

The main issue when neural networks grow large is that they take a very long time<br />

to compute. In addition, some datasets and neural networks will need to run many<br />

epochs of training to get a good fit for the dataset. The neural network we will train<br />

in this chapter takes more than 8 minutes per epoch on my reasonably powerful<br />

computer, and we expect to run dozens, potentially hundreds, of epochs. Some<br />

larger networks can take hours to train a single epoch. To get the best performance,<br />

you may be considering thousands of training cycles.<br />

The math obviously doesn't give a nice result here.<br />

One positive is that neural networks are, at their core, full of floating point<br />

operations. There are also a large number of operations that can be performed<br />

in parallel, as neural network training is composed of mainly matrix operations.<br />

These factors mean that computing on GPUs is an attractive option to speed up<br />

this training.<br />

When to use GPUs for computation<br />

GPUs were originally designed to render graphics for display. These graphics<br />

are represented using matrices and mathematical equations on those matrices,<br />

which are then converted into the pixels that we see on our screen. This process<br />

involves lots of computation in parallel. While modern CPUs may have a number<br />

of cores (your computer may have 2, 4, or even 16—or more!), GPUs have<br />

thousands of small cores designed specifically for graphics.<br />

A CPU is therefore better for sequential tasks, as the cores tend to be individually<br />

faster and tasks such as accessing the computer's memory are more efficient. It is<br />

also, honestly, easier to just let the CPU do the heavy lifting. Almost every machine<br />

learning library defaults to using the CPU, and there is extra work involved before<br />

you can use the GPU for computing. The benefits though, can be quite significant.<br />

GPUs are therefore better suited for tasks in which there are lots of small<br />

operations on numbers that can be performed at the same time. Many machine<br />

learning tasks are like this, lending themselves to efficiency improvements through<br />

the use of a GPU.<br />

[ 258 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!