Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Rush committed Dec 19, 2016
0 parents commit 19d4ca6
Show file tree
Hide file tree
Showing 1,213 changed files with 3,778 additions and 0 deletions.
74 changes: 74 additions & 0 deletions README.md
@@ -0,0 +1,74 @@
# Im2Text

A deep learning-based approach to learning the image-to-text conversion, built on top of the <a href="https://opennmt.github.io/">OpenNMT</a> system. It is completely data-driven, hence can be used for a variety of image-to-text problems, such as image captioning, optical character recognition and LaTeX decompilation.

Take LaTeX decompilation as an example, given a formula image:

<p align="center"><img src="http://lstm.seas.harvard.edu/latex/results/website/images/119b93a445-orig.png"></p>

The goal is to infer the LaTeX source that can be compiled to such an image:

```
d s _ { 1 1 } ^ { 2 } = d x ^ { + } d x ^ { - } + l _ { p } ^ { 9 } \frac { p _ { - } } { r ^ { 7 } } \delta ( x ^ { - } ) d x ^ { - } d x ^ { - } + d x _ { 1 } ^ { 2 } + \; \cdots \; + d x _ { 9 } ^ { 2 }
```

The paper (http://arxiv.org/pdf/1609.04938v1.pdf) provides more technical details of this model.

## Installation

Im2Text is built on top of <a href="https://opennmt.github.io/">OpenNMT</a>. You need to provide the path to <a href="https://opennmt.github.io/">OpenNMT</a> at run time. It also depends on `tds`, `cudnn` and `cutorch`. Currently we only support **GPU**.


## Quick Start

To get started, we provide a toy Math-to-LaTex example. We assume that the working directory is `Im2Text` throughout this document.

Im2Text consists of two commands:

1) Train the model.

```
th src/train.lua -phase train -gpu_id 1 -input_feed -model_dir model \
-image_dir data/images -data_path data/train.txt -val_data_path data/validate.txt -label_path data/labels.txt -vocab_file data/vocab.txt \
-batch_size 8 -beam_size 1 \
-max_num_tokens 150 -max_image_width 500 -max_image_height 160
```

2) Translate the images.

```
th src/train.lua -phase test -gpu_id 1 -load_model -model_dir model \
-image_dir data/images -data_path data/test.txt \
-output_dir results \
-batch_size 2 -beam_size 5 \
-max_num_tokens 500 -max_image_width 800 -max_image_height 800
```

The above dataset is sampled from the [processed-im2latex-100k-dataset](http://lstm.seas.harvard.edu/latex/processed-im2latex-100k-dataset.tgz). We provide a trained model [[link]](http://lstm.seas.harvard.edu/latex/model_latest) on this dataset. In order to use it, download and put it under `model_dir` before translating the images.

## Data Format

* `-image_dir`: The directory containing the images. Since images of the same size can be batched together, we suggest padding images of similar sizes to the same size in order to facilitate training.

* `-label_path`: The file storing the tokenized labels, one label per line. It shall look like:
```
<label0_token0> <label0_token1> ... <label0_tokenN0>
<label1_token0> <label1_token1> ... <label1_tokenN1>
<label2_token0> <label2_token1> ... <label2_tokenN2>
...
```

* `-data_path`: The file storing the image-label pairs. Each line starts with the path of the image (relative to `image_dir`), followed by the index of the label in `label_path` (index counts from 0). At test time, the label indexes can be omitted.
```
<image0_path> <label_index0>
<image1_path> <label_index1>
<image2_path> <label_index2>
...
```

* `-vocab_file`: The vocabulary file. Each line corresponds to a token. The tokens not in `vocab_file` will be considered unknown (UNK).


## Options

For a complete set of options, run `th src/train.lua -h`.
Binary file added data/images/1015942522.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/104c5cec5a.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/105ccc7946.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/105de61fa3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/108453837c.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/10b43f9ed8.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/10c37c445e.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/10fd6c9d3b.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/111bd8befd.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/11421b7af6.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/114f21eeed.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/1177fc20f5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/119b93a445.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/119cec3a3d.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/11a8eea207.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/11b8f564e0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/11e04d81c5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/11ff25534a.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/1213b8125f.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/121b29a34e.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/124a510572.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/12521128dc.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/12603c7701.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/12697ce419.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/12973ae6bf.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/12cc91e6d0.png
Binary file added data/images/12e9e7dd1f.png
Binary file added data/images/131a79148f.png
Binary file added data/images/1321dfa636.png
Binary file added data/images/132e4fe98e.png
Binary file added data/images/134ca7f589.png
Binary file added data/images/1355c92f46.png
Binary file added data/images/135b7e68ed.png
Binary file added data/images/13dbb0dd7c.png
Binary file added data/images/13ef0a5f7d.png
Binary file added data/images/1420ac42ed.png
Binary file added data/images/1434096391.png
Binary file added data/images/143e9de6ce.png
Binary file added data/images/144b2d2e28.png
Binary file added data/images/1466d6bf21.png
Binary file added data/images/146a5fa39e.png
Binary file added data/images/147dd662c6.png
Binary file added data/images/147dde7fd3.png
Binary file added data/images/1481a60f40.png
Binary file added data/images/148efc192d.png
Binary file added data/images/1493d744aa.png
Binary file added data/images/149b313ecf.png
Binary file added data/images/14bb617dee.png
Binary file added data/images/14fffb7ef9.png
Binary file added data/images/150630c544.png
Binary file added data/images/152f92a6b0.png
Binary file added data/images/15329206b1.png
Binary file added data/images/1532c71612.png
Binary file added data/images/153407229b.png
Binary file added data/images/15955bf916.png
Binary file added data/images/159bf72783.png
Binary file added data/images/15b9034ba8.png
Binary file added data/images/15c5d88a1a.png
Binary file added data/images/163bb3b656.png
Binary file added data/images/164c43af41.png
Binary file added data/images/164f87aa84.png
Binary file added data/images/1654a3bc38.png
Binary file added data/images/1671b4d29f.png
Binary file added data/images/16a0874240.png
Binary file added data/images/16a2ab5d25.png
Binary file added data/images/16ae1958c7.png
Binary file added data/images/16cb3262bd.png
Binary file added data/images/16e7e8f3f2.png
Binary file added data/images/16e90a4a4c.png
Binary file added data/images/17226e3e67.png
Binary file added data/images/173111e861.png
Binary file added data/images/177fda0427.png
Binary file added data/images/178ed65519.png
Binary file added data/images/179b37b3d3.png
Binary file added data/images/179ee2322b.png
Binary file added data/images/17ad05c612.png
Binary file added data/images/17b91d8c32.png
Binary file added data/images/17d9b6a683.png
Binary file added data/images/17f1c3c228.png
Binary file added data/images/18049a05a9.png
Binary file added data/images/180d06c7af.png
Binary file added data/images/18457514f2.png
Binary file added data/images/184acbfaf7.png
Binary file added data/images/18b0d1e4ff.png
Binary file added data/images/18b4418f08.png
Binary file added data/images/18c66a0966.png
Binary file added data/images/18d380f64a.png
Binary file added data/images/18dd5bebfe.png
Binary file added data/images/18fcea5309.png
Binary file added data/images/190a4d7839.png
Binary file added data/images/1915502af4.png
Binary file added data/images/1955b98ce0.png
Binary file added data/images/19aa0666cc.png
Binary file added data/images/19ac621c4b.png
Binary file added data/images/19b1816d8c.png
Binary file added data/images/19c9f9219d.png
Binary file added data/images/19d67be751.png
Binary file added data/images/1a09f0e488.png
Binary file added data/images/1a1372416e.png
Binary file added data/images/1a2262a3e2.png
Binary file added data/images/1a5e4f1ea5.png
Binary file added data/images/1a6ad5d0f5.png
Binary file added data/images/1a79f53af4.png
Binary file added data/images/1a87610486.png
Binary file added data/images/1a882641b7.png
Binary file added data/images/1a9a0575e7.png
Binary file added data/images/1a9e2f3773.png
Binary file added data/images/1ac344edfb.png
Binary file added data/images/1b430de29b.png
Binary file added data/images/1b9f888640.png
Binary file added data/images/1ba2cffb3c.png
Binary file added data/images/1ba3ebbf0c.png
Binary file added data/images/1bca8b366d.png
Binary file added data/images/1be1fb7939.png
Binary file added data/images/1be344a743.png
Binary file added data/images/1c275ce7be.png
Binary file added data/images/1c2883bfac.png
Binary file added data/images/1c30697876.png
Binary file added data/images/1c5f0abd11.png
Binary file added data/images/1c6c15eec1.png
Binary file added data/images/1c7a4617a5.png
Binary file added data/images/1c7a5e88b7.png
Binary file added data/images/1c7d2271ab.png
Binary file added data/images/1cbb05a562.png
Binary file added data/images/1ccca004c3.png
Binary file added data/images/1ccd797c55.png
Binary file added data/images/1cd201bfa8.png
Binary file added data/images/1ce187f40a.png
Binary file added data/images/1cfcbaafde.png
Binary file added data/images/1d01328b47.png
Binary file added data/images/1d320e1c45.png
Binary file added data/images/1d680e7a35.png
Binary file added data/images/1d796ff39a.png
Binary file added data/images/1d883568bc.png
Binary file added data/images/1d95e13fad.png
Binary file added data/images/1da914be75.png
Binary file added data/images/1dace34d4a.png
Binary file added data/images/1dcde3138e.png
Binary file added data/images/1dd5d34448.png
Binary file added data/images/1ddfa77a15.png
Binary file added data/images/1de15504a5.png
Binary file added data/images/1de2776366.png
Binary file added data/images/1de6b57b0c.png
Binary file added data/images/1e1505c92f.png
Binary file added data/images/1e1bbaef2b.png
Binary file added data/images/1e216001c4.png
Binary file added data/images/1e244f5909.png
Binary file added data/images/1e3aab9a4f.png
Binary file added data/images/1e3d03189c.png
Binary file added data/images/1e743773df.png
Binary file added data/images/1e74a275a2.png
Binary file added data/images/1e8595e5e1.png
Binary file added data/images/1eb0468393.png
Binary file added data/images/1eba968689.png
Binary file added data/images/1f1d28bc77.png
Binary file added data/images/1f2c64922b.png
Binary file added data/images/1f6cbf77e4.png
Binary file added data/images/1fa7f3fa13.png
Binary file added data/images/1fa9bb5655.png
Binary file added data/images/2002a31c69.png
Binary file added data/images/20032b2645.png
Binary file added data/images/200f79bf14.png
Binary file added data/images/20386b7947.png
Binary file added data/images/20470c3d5f.png
Binary file added data/images/20a17f575f.png
Binary file added data/images/20a6d707a0.png
Binary file added data/images/20ceea5819.png
Binary file added data/images/20d488de0e.png
Binary file added data/images/20e5eb8023.png
Binary file added data/images/20ecb2fa17.png
Binary file added data/images/20ecceacba.png
Binary file added data/images/21184c98a6.png
Binary file added data/images/2168ed75c2.png
Binary file added data/images/216b9616b6.png
Binary file added data/images/2177654260.png
Binary file added data/images/217c11c290.png
Binary file added data/images/2187611cd5.png
Binary file added data/images/21983b6f45.png
Binary file added data/images/21af95c2df.png
Binary file added data/images/21d9f45666.png
Binary file added data/images/21f28c027e.png
Binary file added data/images/2233f4b015.png
Binary file added data/images/224e79c77d.png
Binary file added data/images/22692da57d.png
Binary file added data/images/226979ee71.png
Binary file added data/images/227187aa68.png
Binary file added data/images/227301e73d.png
Binary file added data/images/2296f849c2.png
Binary file added data/images/22a003507e.png
Binary file added data/images/22ebca097d.png
Binary file added data/images/22f7232e98.png
Binary file added data/images/2319dc19dd.png
Binary file added data/images/232d6fea7c.png
Binary file added data/images/2336fcc2f1.png
Binary file added data/images/234d3db18a.png
Binary file added data/images/2350414e35.png
Binary file added data/images/2350b6d78e.png
Binary file added data/images/2358b58f46.png
Binary file added data/images/23a0256e05.png
Binary file added data/images/23cc1f9ade.png
Binary file added data/images/23d23c19eb.png
Binary file added data/images/23d91c1744.png
Binary file added data/images/23ec2a9866.png
Binary file added data/images/23ff5d43fa.png
Binary file added data/images/242a58bc3a.png
Binary file added data/images/24332daee4.png
Binary file added data/images/2440895f67.png
Binary file added data/images/2450656988.png
Binary file added data/images/2457925124.png
Binary file added data/images/247cffb096.png
Binary file added data/images/2480e734be.png
Binary file added data/images/248df5161d.png
Binary file added data/images/24b499dc70.png
Binary file added data/images/24c44bb286.png
Binary file added data/images/24d3cd46d2.png
Binary file added data/images/24d694e788.png
Binary file added data/images/24d85808a1.png
Binary file added data/images/252f1b9cea.png
Binary file added data/images/25346c4649.png
Binary file added data/images/25489864cf.png
Binary file added data/images/256f1e5b2a.png
Binary file added data/images/25765b9391.png
Binary file added data/images/2581f66470.png
Binary file added data/images/25a3d6b46b.png
Binary file added data/images/25ad6cf3b0.png
Binary file added data/images/25c3276f55.png
Binary file added data/images/25fe4d51bf.png
Binary file added data/images/2608ceb605.png
Binary file added data/images/260afae4fe.png
Binary file added data/images/263efbddad.png
Binary file added data/images/2670b0a52c.png
Binary file added data/images/2673247422.png
Binary file added data/images/267a44a011.png
Binary file added data/images/26a03f5f3e.png
Binary file added data/images/26c18afc01.png
Binary file added data/images/2724dd250b.png
Binary file added data/images/272667a2d1.png
Binary file added data/images/273e688d7e.png
Binary file added data/images/2763f1bb43.png
Binary file added data/images/2769dd9b8b.png
Binary file added data/images/276c373567.png
Binary file added data/images/277fac3048.png
Binary file added data/images/2792f30346.png
Binary file added data/images/27a2603118.png
Binary file added data/images/27b57bcd1f.png
Binary file added data/images/27f2b37ce9.png
Binary file added data/images/27f2d26053.png
Binary file added data/images/27fa6d2160.png
Binary file added data/images/2812d8bfc3.png
Binary file added data/images/2817a56674.png
Binary file added data/images/285feda2c2.png
Binary file added data/images/286b161118.png
Binary file added data/images/288ea38816.png
Binary file added data/images/28a38729aa.png
Binary file added data/images/28a7805724.png
Binary file added data/images/28bd09a362.png
Binary file added data/images/28bee01ebd.png
Binary file added data/images/28e6358ab6.png
Binary file added data/images/293efbf748.png
Binary file added data/images/294619977e.png
Binary file added data/images/2983f1a42e.png
Binary file added data/images/29a11d16e3.png
Binary file added data/images/29a6048204.png
Binary file added data/images/29ccf58bd1.png
Binary file added data/images/2a20b5b1cf.png
Binary file added data/images/2a2d9f39aa.png
Binary file added data/images/2a381e5b6c.png
Binary file added data/images/2a54d2ba3b.png
Binary file added data/images/2a7a69318b.png
Binary file added data/images/2a7b3479a9.png
Binary file added data/images/2a8ab3e43c.png
Binary file added data/images/2a8be07a0d.png
Binary file added data/images/2aa5a25f06.png
Binary file added data/images/2abcf2603a.png
Binary file added data/images/2ae8eccc13.png
Binary file added data/images/2af5ce9da2.png
Binary file added data/images/2b50c97ed0.png
Binary file added data/images/2b891b21ac.png
Binary file added data/images/2b8c88ee64.png
Binary file added data/images/2b8e14887f.png
Binary file added data/images/2bbcda22c8.png
Binary file added data/images/2bc4a215e1.png
Binary file added data/images/2bceca2af5.png
Binary file added data/images/2bcf312d4d.png
Binary file added data/images/2bdee6dc8c.png
Binary file added data/images/2be537b9e3.png
Binary file added data/images/2beadd086b.png
Binary file added data/images/2c06a9690c.png
Binary file added data/images/2c65d65f05.png
Binary file added data/images/2c7002c337.png
Binary file added data/images/2cb4925807.png
Binary file added data/images/2cb87ed9c8.png
Binary file added data/images/2ce5749395.png
Binary file added data/images/2d0a8b7347.png
Binary file added data/images/2d2e6105f4.png
Binary file added data/images/2d7d315ab7.png
Binary file added data/images/2d8ebc9df7.png
Binary file added data/images/2df6c7abd6.png
Binary file added data/images/2dfcef9eb0.png

0 comments on commit 19d4ca6

Please sign in to comment.