{"id":13543422,"url":"https://github.com/watsonyanghx/CNN_LSTM_CTC_Tensorflow","last_synced_at":"2025-04-02T12:32:24.036Z","repository":{"id":201585945,"uuid":"98911887","full_name":"watsonyanghx/CNN_LSTM_CTC_Tensorflow","owner":"watsonyanghx","description":"CNN+LSTM+CTC based OCR implemented using tensorflow.","archived":false,"fork":false,"pushed_at":"2018-04-24T01:05:22.000Z","size":69,"stargazers_count":362,"open_issues_count":26,"forks_count":210,"subscribers_count":24,"default_branch":"master","last_synced_at":"2024-11-03T10:32:49.549Z","etag":null,"topics":["cnn","ctc","lstm","ocr","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/watsonyanghx.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,"governance":null}},"created_at":"2017-07-31T17:21:49.000Z","updated_at":"2024-10-06T03:48:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"fd39e31f-2aad-4b1a-bd37-bd18f47e972d","html_url":"https://github.com/watsonyanghx/CNN_LSTM_CTC_Tensorflow","commit_stats":null,"previous_names":["watsonyanghx/cnn_lstm_ctc_tensorflow"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watsonyanghx%2FCNN_LSTM_CTC_Tensorflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watsonyanghx%2FCNN_LSTM_CTC_Tensorflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watsonyanghx%2FCNN_LSTM_CTC_Tensorflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watsonyanghx%2FCNN_LSTM_CTC_Tensorflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/watsonyanghx","download_url":"https://codeload.github.com/watsonyanghx/CNN_LSTM_CTC_Tensorflow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246815871,"owners_count":20838532,"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":["cnn","ctc","lstm","ocr","tensorflow"],"created_at":"2024-08-01T11:00:31.421Z","updated_at":"2025-04-02T12:32:19.028Z","avatar_url":"https://github.com/watsonyanghx.png","language":"Python","funding_links":[],"categories":["Optical Character Recognition Engines and Frameworks"],"sub_categories":["CTPN [paper:2016](https://arxiv.org/pdf/1609.03605.pdf)"],"readme":"# CNN_LSTM_CTC_Tensorflow\n\nCNN+LSTM+CTC based OCR(Optical Character Recognition) implemented using tensorflow. \n\n**Note:** there is **No** restriction on the number of characters in the image (variable length). Have a look at the image bellow.\n\nI trained a model with 100k images using this code and got 99.75% accuracy on test dataset (200k images) in the [competition](http://meizu.baiducloud.top). The images in both dataset:\n\n![](https://github.com/watsonyanghx/CNN_LSTM_CTC_Tensorflow/blob/master/data/ico1-608634b7cb.png)\n\n![](https://github.com/watsonyanghx/CNN_LSTM_CTC_Tensorflow/blob/master/data/ico2-19c9d50d82.png)\n\n\n**Update 2017.11.6**:\n\nThe competiton page is not available now, if you want to reproduce this result, please see this [issue](https://github.com/watsonyanghx/CNN_LSTM_CTC_Tensorflow/issues/2) about dataset， the lable file (a .txt file) is in the same folder with images after extracting .tar.gz file.\n\n\n**Update 2018.4.24**:\n\nUpdate to tensorflow 1.7 and fix some bugs reported at issue [#8](https://github.com/watsonyanghx/CNN_LSTM_CTC_Tensorflow/issues/8).\n\n\n## Structure\n\nThe images are first processed by a CNN to extract features, then these extracted features are fed into a LSTM for character recognition.\n\nThe architecture of CNN is just `Convolution + Batch Normalization + Leaky Relu + Max Pooling` for simplicity, and the LSTM is a 2 layers stacked LSTM, you can also try out Bidirectional LSTM.\n\nYou can play with the network architecture (add dropout to CNN, stacked layers of LSTM etc.) and see what will happen. Have a look at [CNN part](https://github.com/watsonyanghx/CNN_LSTM_CTC_Tensorflow/blob/master/cnn_lstm_otc_ocr.py#L45) and [LSTM part](https://github.com/watsonyanghx/CNN_LSTM_CTC_Tensorflow/blob/master/cnn_lstm_otc_ocr.py#L60).\n\n\n## Prerequisite\n\n1. Python 3.6.4\n\n2. TensorFlow 1.2\n\n3. Opencv3 (Not a must, used to [read images](https://github.com/watsonyanghx/CNN_LSTM_CTC_Tensorflow/blob/master/utils.py#L72)).\n\n\n\n## How to run\n\nThere are many other parameters with which you can play, have a look at [utils.py](https://github.com/watsonyanghx/CNN_LSTM_CTC_Tensorflow/blob/master/utils.py#L11).\n\n**Note** that the [num_classes](https://github.com/watsonyanghx/CNN_LSTM_CTC_Tensorflow/blob/master/utils.py#L11) is not added to parameters talked above for clarification.\n\n\n``` shell\n# cd to the your workspace.\n# The code will evaluate the accuracy every validation_steps specified in parameters.\n\nls -R\n  .:\n  imgs  utils.py  helper.py  main.py  cnn_lstm_otc_ocr.py\n\n  ./imgs:\n  train  infer  val  labels.txt\n  \n  ./imgs/train:\n  1.png  2.png  ...  50000.png\n  \n  ./imgs/val:\n  1.png  2.png  ...  50000.png\n\n  ./imgs/infer:\n  1.png  2.png  ...  300000.png\n   \n  \n# Train the model.\nCUDA_VISIBLE_DEVICES=0 python ./main.py --train_dir=../imgs/train/ \\\n  --val_dir=../imgs/val/ \\\n  --image_height=60 \\\n  --image_width=180 \\\n  --image_channel=1 \\\n  --out_channels=64 \\\n  --num_hidden=128 \\\n  --batch_size=128 \\\n  --log_dir=./log/train \\\n  --num_gpus=1 \\\n  --mode=train\n\n# Inference\nCUDA_VISIBLE_DEVICES=0 python ./main.py --infer_dir=./imgs/infer/ \\\n  --checkpoint_dir=./checkpoint/ \\\n  --num_gpus=0 \\\n  --mode=infer\n\n```\n\n\n## Run with your own data.\n\n1. Prepare your data, make sure that all images are named in format: `id_label.jpg`, e.g: `004_(1+4)*2.jpg`.\n\n``` shell\n# make sure the data path is correct, have a look at helper.py.\n\npython helper.py\n```\n\n2. Run following [How to run](https://github.com/watsonyanghx/CNN_LSTM_CTC_Tensorflow#how-to-run)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatsonyanghx%2FCNN_LSTM_CTC_Tensorflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwatsonyanghx%2FCNN_LSTM_CTC_Tensorflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatsonyanghx%2FCNN_LSTM_CTC_Tensorflow/lists"}