def load2d(test=False, cols=None): X, y = load(test=test) X = X.reshape(-1, 1, 96, 96) return X, y
def vectorized_result(j): e = np.zeros(10) e[j] = 1.0 return e def normalize_input(X): return np.array([x / 255 for x in X]) images, labels = loadlocal_mnist( images_path='../Datasets/MNIST_digits/train-images-idx3-ubyte', labels_path='../Datasets/MNIST_digits/train-labels-idx1-ubyte') #net = network.Network([784, 64, 40, 10]) net = network.load('MNIST_digits', 20) #images = images[:10000] #labels = labels[:10000] for ep in range(10, 100): example = 0 ep_loss = 0 start = time.time() for X, y in zip(images, labels): ep_loss += net.train(normalize_input(X), vectorized_result(y), ep) #ep_loss += network.mse_loss(vectorized_result(y), net.feedforward(X)) example += 1 if example % 10000 == 0: end = time.time() if example > 0:
img = cv2.imread("/home/simon/Downloads/george-clooney.jpg") img = cv2.imread("/home/simon/Pictures/smoss.jpg") grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) rects = detect(grey) print rects, len(rects) face = rects[0] grey = grey[face[1]:face[3],face[0]:face[2]]/255.0 grey = cv2.resize(grey, (96,96)) draw_rects(img, rects, (0,255,0)) cv2.imshow("X", grey) net1 = pickle.load(file('net1.pickle')) net2 = pickle.load(file('net2.pickle')) sample1 = load(test=True)[0][6:7] print sample1 sample2 = load2d(test=True)[0][6:7] print grey.shape sample2 = grey.reshape(-1,1,96,96) sample2 = np.array(sample2, np.float32) print sample2 y_pred1 = net1.predict(sample1)[0] import time for i in range(100): y_pred2 = net2.predict(sample2)[0] print i
img = cv2.imread("/home/simon/Downloads/george-clooney.jpg") img = cv2.imread("/home/simon/Pictures/smoss.jpg") grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) rects = detect(grey) print rects, len(rects) face = rects[0] grey = grey[face[1]:face[3], face[0]:face[2]] / 255.0 grey = cv2.resize(grey, (96, 96)) draw_rects(img, rects, (0, 255, 0)) cv2.imshow("X", grey) net1 = pickle.load(file('net1.pickle')) net2 = pickle.load(file('net2.pickle')) sample1 = load(test=True)[0][6:7] print sample1 sample2 = load2d(test=True)[0][6:7] print grey.shape sample2 = grey.reshape(-1, 1, 96, 96) sample2 = np.array(sample2, np.float32) print sample2 y_pred1 = net1.predict(sample1)[0] import time for i in range(100): y_pred2 = net2.predict(sample2)[0] print i