image_neural_net

Animal recognition using a neural network.
Log | Files | Refs | README

test_neural_net.py (1254B)


      1 import numpy as np
      2 import operator as op
      3 
      4 def sigmoid(x, deriv = False):
      5     if (deriv == False):
      6         x = np.clip(x, -500, 500)
      7         result = 1/(1+np.exp(-x))
      8     else:
      9         result = x*(1-x)
     10     return result
     11 
     12 testDog = np.load('../test/testingDog.npy')
     13 testCat = np.load('../test/testingCat.npy')
     14 testBird = np.load('../test/testingBird.npy')
     15 testDolphin = np.load('../test/testingDolphin.npy')
     16 
     17 syn0 = np.loadtxt('../neuralnet/syn0')
     18 syn1 = np.loadtxt('../neuralnet/syn1')
     19 syn2 = np.loadtxt('../neuralnet/syn2')
     20 
     21 inputLayer = testDog
     22 layer1 = sigmoid(np.dot(inputLayer, syn0))
     23 layer2 = sigmoid(np.dot(layer1, syn1))
     24 layer3 = sigmoid(np.dot(layer2, syn2))
     25 print ("Dog Output:")
     26 print (layer3)
     27 
     28 inputLayer = testCat
     29 layer1 = sigmoid(np.dot(inputLayer, syn0))
     30 layer2 = sigmoid(np.dot(layer1, syn1))
     31 layer3 = sigmoid(np.dot(layer2, syn2))
     32 print ("Cat Output:")
     33 print (layer3)
     34 
     35 inputLayer = testBird
     36 layer1 = sigmoid(np.dot(inputLayer, syn0))
     37 layer2 = sigmoid(np.dot(layer1, syn1))
     38 layer3 = sigmoid(np.dot(layer2, syn2))
     39 print ("Bird Output:")
     40 print (layer3)
     41 
     42 inputLayer = testDolphin
     43 layer1 = sigmoid(np.dot(inputLayer, syn0))
     44 layer2 = sigmoid(np.dot(layer1, syn1))
     45 layer3 = sigmoid(np.dot(layer2, syn2))
     46 print ("Dolphin Output:")
     47 print (layer3)