{"id":18395779,"url":"https://github.com/x-raylaser/keras-auto-hwr","last_synced_at":"2026-04-13T02:02:09.939Z","repository":{"id":51682939,"uuid":"218747833","full_name":"X-rayLaser/keras-auto-hwr","owner":"X-rayLaser","description":"A micro-framework for building a handwritten text recognition (HTR) system","archived":false,"fork":false,"pushed_at":"2023-01-04T12:50:17.000Z","size":3602,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-16T02:24:57.315Z","etag":null,"topics":["ctc-loss","deep-learning","deep-learning-framework","handwritten-text-recognition","keras","lstm","machine-learning","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/X-rayLaser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-31T11:11:50.000Z","updated_at":"2020-01-21T14:00:40.000Z","dependencies_parsed_at":"2023-02-02T13:00:38.735Z","dependency_job_id":null,"html_url":"https://github.com/X-rayLaser/keras-auto-hwr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/X-rayLaser%2Fkeras-auto-hwr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/X-rayLaser%2Fkeras-auto-hwr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/X-rayLaser%2Fkeras-auto-hwr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/X-rayLaser%2Fkeras-auto-hwr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/X-rayLaser","download_url":"https://codeload.github.com/X-rayLaser/keras-auto-hwr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248580549,"owners_count":21128006,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ctc-loss","deep-learning","deep-learning-framework","handwritten-text-recognition","keras","lstm","machine-learning","tensorflow"],"created_at":"2024-11-06T02:11:55.425Z","updated_at":"2026-04-13T02:02:09.863Z","avatar_url":"https://github.com/X-rayLaser.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\n\nkeras-auto-hwr is a micro-framework for building a handwritten text \nrecognition (HTR) system built on top of Keras and TensorFlow.\n\nThe central philosophy is to enable one to quickly train and test \nan RNN to perform HTR with minimum upfront efforts. One only needs \nto implement a thin API specifying how and where raw data for \ntraining should be fetched from. The framework's pipeline will \nautomatically take care of steps such as pre-processing, \nnormalization, converting target sequences into one-hot \nrepresentation and more.\n\n# Features\n- minimal pre-processing\n- automatic data normalization\n- automatic encoding of text into a sequence of one-hot vectors\n- built-in model (bidirectional LSTM model trained with CTC loss)\n- train on GPU, predict on CPU\n- saving/resuming training after any epoch\n- interactive demo for testing a trained model live\n- language-agnostic (work in progress)\n- deploy a trained model for use with TensorFlow.js\n- built-in Token Passing decoding algorithm\n\n# Limitations\nAt the time of this writing, there are a few major limitations such as:\n- No support for building an offline recognition system.\n- Currently, the only model that is supported is the architecture \nbased around connectionist temporal classification\n- Fixed number of layers (2) and units (100)\n- No built-in encoder-decoder network architecture\n\n# Installation\n\nClone the repository\n```\ngit clone \u003cclone_url\u003e\n```\n\n, create a virtualenv environment using Python 3\n```\nvirtualenv --python='/path/to/python3/executable' venv\n```\n, activate the environment\n```\n. venv/bin/activate\n```\n\n, go inside the directory containing a hidden git folder and install \nall python modules required for the app\n```\npip install -r requirements.txt\n```\n\n# Quick Start\n\n## Training from scratch on Iam Online DB data set\n\nFirst, download the data set, unzip it and place it under \n./datasets/iam_online_db/ folder. The layout of datasets folder should\nbe as follows:\n\niam_online_db/\n\n--ascii-all/\n\n--lineImages-all/\n\n--lineStrokes-all/\n\n--original-xml-all/\n\n--original-xml-part/\n\nCompile the data set:\n\n```\npython compile.py 'IamSource' 'default' --num_examples=7000\n```\n\nThis command will compile a data set using IAM-OnDB data set, default\npre-processor. It will create training/validation/test data split\ncontaining a total of 7000 examples.\n\nTrain a bidirectional LSTM model with CTC loss:\n```\npython train_ctc.py --cuda=true\n```\n\nSet flag \"cuda\" to use CuDNNLSTM implementation instead of LSTM.\n\nYou can suspend the script after any epoch and resume training later.\n\nWhen training is complete, run an OCR demo script:\n```\npython demo/ocr_demo.py\n```\n\nFinally, deploy the model to be used in javascript:\n```\npython deploy.py\n```\n\nYour deployed model will be in ./weights/deployed/blstm folder.\n\n## Training on arbitrary data set\n\n\n\nCreate a subclass of BaseSource class in the data/providers.py \nmodule by implementing constructor, get_sequences and \n__len__ methods. You are free to do anything in those methods. \nFor instance, you can read the data in from the file or fetch \nthem through the network.\n\nThe get_sequences method should return a \ngenerator that returns raw handwriting data and corresponding \ntranscription text. Each handwriting should be a list of strokes. \nEach stroke is itself a list of the following format: \n(x1, y1, t1), (x2, y2, t2), ..., where x and y are pen position \ncoordinates and t is the time respectively. Add necessary \npre-processing if you need to.\n\nHere is an example.\n\n```\nclass MyDataProvider(BaseSource):\n    def __init__(self, num_lines):\n        pass\n\n    def get_sequences(self):\n        hwr = [\n            [(23, 8, 323), (25, 9, 325)], # first stroke\n            [(55, 2, 340), (58, 2, 380)]  # second stroke\n        ]\n        \n        transcription = 'foobar'\n        \n        yield hwr, transcription\n\n    def __len__(self):\n        return 1\n```\n\nNext, compile a data set using a newly implemented data provider:\n```\npython compile.py 'MyDataProvider' 'default' --num_examples=1\n```\n\n## Testing pre-trained model\n\n### Run demo script using Best Path Decoding algorithm\n```\npython demo/ocr_demo.py\n```\n\n### Run demo script using Token Passing Decoding algorithm\n\nChange your current working directory to ./algorithms/cpp:\n```\ncd ./algorithms/cpp\n```\n\nCompile and link C++ code into binary:\n```\n./make_binary.sh\n```\n\nReturn to the root path of the project\n```\ncd ../../\n```\n\nBuild a dictionary and language model (e. g. containing 4000 words)\n```\npython build_lang_model.py dictionary --max_words=4000\n```\n\nNow you should be able to use Token Passing algorithm\nfor decoding RNN output in a demo script.\nFor that, simply set a \"token_passing\" flag to true:\n```\npython demo/ocr_demo.py --token_passing=\"true\"\n```\n\n### About pre-trained model\n\nThe model has 1 bidirectional LSTM layer with 100 hidden units followed by a softmax layer \ncontaining 100 units (one unit per character plus special codes and blank code). \nThe model was trained on the IAM On-Line Handwriting Database using 9450 examples of the \nform: handwriting patterns -\u003e text lines. It was trained with Adam optimizer with a \nlearning rate of 0.001 and CTC loss. The training was terminated after 31 epochs.\n\n## Running tests\n\n```\npython -m unittest discover -s tests\n```\n\n# License\n\nThis software is licensed under MIT license (see LICENSE).\n\n# References\n\n[1] [Alex Graves et. al. Unconstrained Online Handwriting Recognition with Recurrent Neural Networks](https://papers.nips.cc/paper/3213-unconstrained-on-line-handwriting-recognition-with-recurrent-neural-networks.pdf)\n\n[2] [S. Young, N. Russell, and J. Thornton.  Token passing: A simple conceptual model for connected speech recognition system](https://pdfs.semanticscholar.org/963c/f8f238745100ac6cc5cf730653a6e1849b62.pdf?_ga=2.58290915.813220193.1572590064-1733760606.1572590064)\n\n[3] [Liwicki, M. and Bunke, H.: IAM-OnDB - an On-Line English Sentence Database Acquired from Handwritten Text on a Whiteboard](http://www.fki.inf.unibe.ch/databases/iam-on-line-handwriting-database/iam-on-line-handwriting-database#LiBu05-03)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx-raylaser%2Fkeras-auto-hwr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fx-raylaser%2Fkeras-auto-hwr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx-raylaser%2Fkeras-auto-hwr/lists"}