# Machine Learning

## A conversation between Man & Machine

`Ok sure, teach me how to do it, in simple terms!`

### Let's learn to classify Moths!

`Ok, but I can't generalise from raw images!`

### What do you want then?

`I need features. I work with numbers!`

## How to classify a Moth photo:

3. ### Look for one of these distinctive patterns..

4. ....
`Oh man, this is hard. I've got to do mollusks and fish and beer bottles too..`
`Isn't there an easier way?`

## How to classify a Moth photo:

3. ### Pick the category of the closest image

`Sounds easy!`
`But.. how do I convert an image to a set of numbers?`

Feed the image through a pretrained neural network classifier and extract the values of one of the inner layers.

`Eh...what?`
`But.. how do I convert an image to a set of numbers?`

Just use ImageNet.. It is a neural network that has learned all about vision and the features that make up images. Its inner layers are general image descriptors..

`okayyyy...`

Think of it as a black box translator from pixels to semantics.

`ok.. so what is the output?`

A list of 4096 numbers!

`And what do they mean?`

Nobody knows! Nothing individually, but together they describe higher level features of images.

`oh yeah... of course...`

Well its just a point in a 4096 dimensional space.. so you just calculate the distance between them?

`So how do I compare these numbers?`

Doesn't matter, you don't need to visualise it.. just calculate the distance in the same way as 2d space.. square root of the sum of the squared differences, remember?

`4096 dimensional..wat!`
`oh yeah...one of those greek dudes said that yeah?`
`Dude I don't even get 3D!`
`Ok, so my database has 100k images and their 4096 dim numbers.. How do I know which ones to compare against?`

You don't! You need to calculate the distance to all of them.

`But.. 100k.. and counting!`

You better do it quick so! Just use Postgres, all will be fine :) Oh and you can do a rough search first across binarized codes using Hamming distance.. it's super fast.

`sure..`
```Ok, awesome, it works, it is fast!
But am I  really learning?

I feel like this isn't real machine learning? We are still using someone else's neural net..```

Of course you are. As we add more data the results get better.  The neural net is just a generic vision translator.

`But I don't think I know what a moth is!`

Of course you don't!  But you don't need to. You need to classify moths, not describe them.

`Fair enough, but that doesn't sound very intelligent`

You're not. You are just doing statistics & math. Nothing special.

`Aww.. that hurts :(`
`But no one else needs to know that.. I can pretend I am an all powerful AI, even smarter than Siri.. `

just with a Moth obsession..

`It's a job! Just don't tell anyone else how I do it ok.. `

# How?

## How to train your Neural Network

1. Set the top input layer to raw pixel values.

2. Calculate the values of the next layer from the previous layer and the

3. Repeat 2 until final layer.

4. Calculate the difference between the outputs and the expected output

By Fergal Walsh

• 354