def load_data(self): mn = MNIST('.') mn.test() data = mn.train_images data = np.array(data) data.astype(np.float32) data = data/255.0 return data
def load_targets(self): mn = MNIST('.') mn.test() targets = [] for t in mn.train_labels: #print t out = np.zeros(self.output) out[t] = 1 targets.append(out) targets = np.array(targets) return targets
data = data/255.0 return data def load_targets(self): mn = MNIST('.') mn.test() targets = [] for t in mn.train_labels: #print t out = np.zeros(self.output) out[t] = 1 targets.append(out) targets = np.array(targets) return targets if __name__ == '__main__': mn = MNIST('.') mn.test() MLP = MLP_Classifier(28*28+1,40,10) datas = MLP.load_data() targets = MLP.load_targets() MLP.fit(datas,targets) result = MLP.predict(mn.test_images) accurate = 0 for i in range(len(result)): if result[i] == mn.test_labels[i]: accurate+=1 print accurate