Week 2

Aims:

  • Improve our submission to cats and dogs
  • Understand what we did in week 1 by copying out code manually
  • Enter a different competition of a similar nature

Steps:

0. Install bcolz

(to save numpy arrays efficiently)

1. Train a tiny linear model

(fit a line to some random numbers in x-y plane)

2. Fit a linear model to get cats and dogs from the labels of the Vgg16

(we want to learn if 'terrier', 'tabby' annd 'dashund' are cats or dogs)

x. Set up a workflow for using images as arrays

(We read .jpeg as an arrays, so we can cave them as arrays for convenience)

Manually type code

(We used code from the vgg16.py and utils.py files. Let's type it out)

Enter a new competition

(How about statefarm distracted drivers)

0. Install bcolz

Description:

Steps:

  1. SSH into to AWS
    • Go to the alias directory -> cd proj/dl/courses/setup
    • Start the alias -> source aws-alias.sh
    • Look at the alias commands -> alias
      • -> aws-get-t2
      • -> aws-ip
      • -> aws-start
      • -> aws-ssh
    • start a TMUX pane -> tmux
      • Split vertically -> ctrl-b %
      • Navigate to right pane -> ctrl-b o
      • Split right pane horizontally -> ctrl-b "
      • Navigate to bottom right pane -> ctrl-o
      • Start notebook -> jupyter notebook
      • Got to the notebook page in browser: ip:8888
      • Psw: dl_course
      • Open up lesson2 in courses/deeplearning1/nbs
  2. Install bcolz -> conda install -c anaconda bcolz=1.0.0
    • "-c" stands for channel to tell anaconda where to look
    • We'll need to do this on 2 aws instances (p2 and t2) as well as your local computer if you want to use it in all three places. Sort out the other ones later if need

1. Train a tiny linear model

Description:

  • Generate a 2 dimensional array of 30 sets of 2 x coordinates (x1 and x2)
  • Create a model of form y=m*x+c, but with two x dimensions: y = m1*x1 + m2*x2 + c. (our m1=2, m2=3, c=1)
  • We'll solve for m1, m2 and c by guessing, and then seeing which direction we need to move in then taking tiny steps in that direction
  • Each iteration (epoch) we should see the m and c improve
  • The model works by minimising the error between the actual and the predicted values (the square of the error, to ensure the error is always positive)

Steps:

  1. Run the code down to: "Train linear model on predictions"
  2. Note each step. If you want to explore something in more detail you can use: [thing]?.
    • Dense (Basically an array for multiplying y=mx+c at each of our 'nodes'): Normally in our networks at each node we multiply by a weight (m) and add a bias (c). We would also use an "activation function" after doing this, which helps speed up the model. An example function might be the ReLu function, which deletes any negative value and replaces it with a zero. But in this simple model we just want the y=mx+c. You can see the options for the dense function with: -> Dense?
  3. x=random: to set up the array of a certain size filled with random values between 0 and 1
    • The first 6 pairs of x's
      • x = array([[ 0.91 , 0.3497], [ 0.3419, 0.5972], [ 0.9416, 0.0185], [ 0.5317, 0.207 ], [ 0.1547, 0.9764], [ 0.7257, 0.701 ], ...])
  4. y=np.dot: to up the y values, by using matrix multiplication (dot product) of the random x array and the array [2,3]. Then we add a one to that.
  • Acronyms
    • MSE (Mean Squared Error): (predicted-y - actual_y) squared
    • SGD (Stochastic Gradient Descent): Incrementally adjusting the m and c values so that we gradually move downhill from a high total error to a teeny tiny error

Fit a linear model to get cats and dogs from the labels of the Vgg16

Description:

  • The Vgg16 model puts out so many different labels so if we just train our pictures of cats and dogs on it, we'll get overly-specific labels such as 'persian' and 'greyhound'
  • We can set up a simple model that takes the breeds and outputs either cat or dog
  • This will be a simple one-layer model, just like the tiny model we just made

x. Set up a workflow for using images as arrays

Description:

Steps:


In [ ]: