SHARE
TWEET

Untitled

a guest Jun 18th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. conv = Conv3x3(8)                  # 28x28x1 -> 26x26x8
  2. pool = MaxPool2()                  # 26x26x8 -> 13x13x8
  3. softmax = Softmax(13 * 13 * 8, 10) # 13x13x8 -> 10
  4.  
  5. def forward(image, label):
  6.   '''
  7.   Completes a forward pass of the CNN and calculates the accuracy and
  8.   cross-entropy loss.
  9.   - image is a 2d numpy array
  10.   - label is a digit
  11.   '''
  12.   # We transform the image from [0, 255] to [-0.5, 0.5] to make it easier
  13.   # to work with. This is standard practice.
  14.   out = conv.forward((image / 255) - 0.5)
  15.   out = pool.forward(out)
  16.   out = softmax.forward(out)
  17.  
  18.   # Calculate cross-entropy loss and accuracy. np.log() is the natural log.
  19.   loss = -np.log(out[label])
  20.   acc = 1 if np.argmax(out) == label else 0
  21.  
  22.   return out, loss, acc
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top