Skip to content

Commit

Permalink
update readme, fix a bug in parse_log.py
Browse files Browse the repository at this point in the history
  • Loading branch information
xmfbit committed Mar 26, 2017
1 parent f9a2287 commit 0753939
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 1 deletion.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,39 @@ There is a toy demo in `examples/warpctc_captcha`, which can train a 2-layer lst

This repo is a personal project.

## How to run the demo

In this demo, captcha images can contain digit sequence with different length(more specifically, 1~5 digits). CTC loss is very suitable for this kind of variable length sequence learning. See the three images below for detail of the examples in the demo.

![captcha image with 3 digits](/docs/images/captcha/99944-492.png)
![captcha image with 4 digits](/docs/images/captcha/99938-4518.png)
![captcha image with 5 digits](/docs/images/captcha/99937-82028.png)

To run the demo, first, make sure you are in `$CAFFE_ROOT` directory. Then, run the scripts to generate data using python `captcha` library and hdf5 files for trainning and testing.

```
# generate data
python examples/warpctc_captcha/generate_captcha.py
# generate hdf5 files
python examples/warpctc_captcha/generate_dataset.py
```

Due to different hardware capabilities, this process may take a different time. Then you should find captcha images in directory `$CAFFE_ROOT/data/captcha`. You can change the parameters in the above two scripts to get larger dataset and use more threads to accerate the process.

Then, you can run the bash script to train the 2-layer lstm model using ctc loss.

```
./examples/warpctc_captcha/train.sh
```

Have a cup of coffee when tranning!

## Demo results

I ran the demo for several times and the model can converge finally. The accuracy of the model is not too high, but enough to prove the power of the naive 2-layer lstm network.

![trainning loss result](/docs/images/captcha/train_loss.png)
![test loss result](/docs/images/captcha/test_loss.png)
![test accuracy](/docs/images/captcha/test_accuracy.png)

The model I trainned can be downloaded from [Google Drive](https://drive.google.com/file/d/0B98MUaCGMMG0UVd1WWFrNHZLdTg/view?usp=sharing).
Binary file added docs/images/captcha/99937-82028.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/captcha/99938-4518.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/captcha/99944-492.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/captcha/test_accuracy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/captcha/test_loss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/captcha/train_loss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion examples/warpctc_captcha/parse_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def main(log_file):
# plt accracy
plt.plot(accuracy)
plt.title('test accuracy')
plt.show()
plt.savefig('test_accuracy.png')
plt.show()
plt.close()

def print_help():
print """this script do simple string match to parse train log file of warpctc demo
Expand Down

0 comments on commit 0753939

Please sign in to comment.