def main(): # parse command line options from neural.py args = neural.user_options() # import training data and labels train_set, train_labels = neural.read_data(path="digits_train_scaled.csv", rows=args.num_train) print("Successfully loaded training data with %i training images." % train_set.shape[0]) # initialize neural network object with specified command line arguments neuralNet = neural.neural(num_features = train_set.shape[1], num_hidden = 100, num_classes = 10, \ learn_rate = 0.001, reg_strength = 0.1, drop_prop = 0.1) # run k-fold cross-validation accuracies = cross_validate(num_iters = args.num_iters, train_data = train_set, batch_size = args.batch_size, \ train_labels = train_labels, neuralNet = neuralNet, crossEnt = args.cross_entropy, L2Reg = args.L2_reg, dropout = args.dropout, XavierHe = args.XavierHe_init, K = args.K) print("Average %i-fold cross-validation training accuracy: %.4f" % (args.K, np.mean(accuracies))) # import test data and labels test_set, test_labels = neural.read_data(path="digits_test_scaled.csv", rows=args.num_test) # compute accuracy on test data test_accuracy = neuralNet.compute_accuracy(data=test_set.transpose(), labels=test_labels) print("Accuracy on %i test images: %.4f" % (test_set.shape[0], test_accuracy))
def nocr(filename): print("nocr:" + filename) # bounding box, find and log a box around the characters of interest bounded_image = bounding_box(filename) # separate characters, placing each in the log_images directory (individual_images, space_locations) = separate_chars(filename, bounded_image) # return predicted string nospace_string = neural(individual_images) print(nospace_string) final_string = '' offset = 0 for index in range(0, len(nospace_string)): if (index + offset) in space_locations: final_string = final_string + ' ' offset = offset + 1 final_string = final_string + nospace_string[index] return final_string
import numpy as np import neural as nn #Sample with AND logic gate: s = [2, 3, 1] in_set = np.array([[0., 0.], [0., 1.], [1., 0.], [1., 1.]]) out_set = np.array([[0.], [0.], [0.], [1.]]) n = nn.neural(s) n.train(in_set, out_set, 3000) n.forward(in_set) print n.o
import neural j = 0 k = 10 errors = 1 b = neural.neural() c = b.point(-2, 2) g = b.etalon(c) print(g) while errors != 0: errors = 0 while j < 10 and k < 20: v = b.window(c, j, k) m = b.check_error(v, g[k]) if m: errors += 1 b.hoff(c, m, j, k) j += 1 k += 1 print b.get_w()
def reply1(message): Brand = db.getBrand(message.text) if Brand is not None: sent = bot.send_message(message.chat.id, "Окей, у вас %s" % Brand) db.updateBrand(message.chat.id, Brand) bot.register_next_step_handler(sent, reply2) else: sent = bot.send_message("Не удалось распознать марку автомобиля") bot.register_next_step_handler(sent, reply1) def reply2(message): check = neur.check_cat(message.text) sent = bot.send_message(message.chat.id, '{name}. Заканчивай.'.format(name=message.text)) bot.register_next_step_handler(sent, start) if __name__ == '__main__': createdb.createtables() db = DB.DBLayer(config.database) neur = neural.neural() neur.data_init() while True: try: bot.polling(none_stop=True, interval=5) except Exception as e: print('Error occurred:') print(sys.stderr, str(e))
print "file read error" raise def fill_data(self): for line in self.ftrain: intval = map(int,line.strip().split(" ")) self.train_data.append(intval) #print intval for line in self.ftrail: intval = map(int,line.strip().split(" ")) self.test_data.append(intval) for line in self.forgtrain: intval = map(int,line.strip().split(" ")) self.train_org.append(intval) print len(self.train_org) for line in self.forgtrail: intval = map(int,line.strip().split(" ")) self.test_org.append(intval) #print intval print len(self.test_org) if __name__ == "__main__": data = Data() data.fill_data() #nn = neural.neural(len(data.train_data[0])-1,10,0,data.train_data,data.test_data,11,1000) #nn.train() nn = neural.neural(len(data.train_org[0])-1,10,64,data.train_org,data.test_org,21,100) nn.train()