def main(): parser = argparse.ArgumentParser() parser.add_argument('files', nargs='*', help="list of files to recognize") parser.add_argument('--mnist', help="count of random MNIST images", type=int) args = parser.parse_args(sys.argv[1:]) images = [np.flipud(1 - bmp.load(k, floatize=True)) for k in args.files] if args.mnist: m_images, m_labels = MNIST.get_data() random.shuffle(m_images) images.extend(m_images[:args.mnist]) drg = DigitRecognizerGui(images=images) drg.show()
def recognizer(paths, config_file='digit_recognizer.pkl'): with open(config_file, 'rb') as fd: config = pickle.load(fd) print("config file loaded") print("shape : {}".format(config['layers'])) network = Bpn.NeuralNetwork(config['layers']) if 'weights' in config: network.weights = config['weights'] print("weights restored") for path in paths: if isinstance(path, (np.ndarray)): image = path else: print("Path: {}".format(path)) image = bmp.load(path) image = np.flipud(1 - image / 255) image = image.reshape((functools.reduce(mul, image.shape))) # print(image) return network.run(image[None, :])
def test_load_bmp(self): image = bmp.load('test_image.bmp') self.assertIsNotNone(image)