Coder Social home page Coder Social logo

luopeixiang / im2latex Goto Github PK

View Code? Open in Web Editor NEW
173.0 7.0 47.0 7.39 MB

Pytorch implemention of Deep CNN Encoder + LSTM Decoder with Attention for Image to Latex

License: MIT License

Python 100.00%
im2latex show-and-tell seq2seq imagecaptioning pytorch encoder-decoder-model

im2latex's Introduction

Im2Latex

License

Deep CNN Encoder + LSTM Decoder with Attention for Image to Latex, the pytorch implemention of the model architecture used by the Seq2Seq for LaTeX generation

Sample results from this implemention

sample_result

Experimental results on the IM2LATEX-100K test dataset

BLUE-4 Edit Distance Exact Match
40.80 44.23 0.27

Getting Started

Install dependency:

pip install -r requirement.txt

Download the dataset for training:

cd data
wget http://lstm.seas.harvard.edu/latex/data/im2latex_validate_filter.lst
wget http://lstm.seas.harvard.edu/latex/data/im2latex_train_filter.lst
wget http://lstm.seas.harvard.edu/latex/data/im2latex_test_filter.lst
wget http://lstm.seas.harvard.edu/latex/data/formula_images_processed.tar.gz
wget http://lstm.seas.harvard.edu/latex/data/im2latex_formulas.norm.lst
tar -zxvf formula_images_processed.tar.gz

Preprocess:

python preprocess.py

Build vocab

python build_vocab.py

Train:

 python train.py \
      --data_path=[data dir] \
      --save_dir=[the dir for saving ckpts] \
      --dropout=0.2 --add_position_features \
      --epoches=25 --max_len=150

Evaluate:

python evaluate.py --split=test \
     --model_path=[the path to model] \
     --data_path=[data dir] \
     --batch_size=32 \
     --ref_path=[the file to store reference] \
     --result_path=[the file to store decoding result]

Features

im2latex's People

Contributors

luopeixiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

im2latex's Issues

evaluate.py

你好,能提供预训练模型和evaluate.py文件吗

OOM problem 2

torch==1.3.1

在训练的时候,显卡内存一直上涨,大概训练几十轮后,最终内存溢出。

请教一个evaluate的问题

想验证一下效果,evalute的时候是不是只要输入一个公式图片就可以,但是网络forward的时候还要求latex。。。这个不知道应该怎么处理了

数据增强

我记得有个专门针对100K做数据增强的网站,还有人记得么?

python evaluate.py throws up ZeroDivisionError

Hi

I was able to train the model.

When I try to evaluate the model using the command, I get this following error. How do I overcome this ?

(pytG) Power-Ubuntu-18-9:~/im2latex-master$ python evaluate.py --split=test --model_path=/home/im2latex-master/save/best_ckpt.pt --data_path=/home/im2latex-master/data --batch_size=8
Load vocab including 394 words!
0%| | 0/1295 [00:00<?, ?it/s]/home/anaconda3/envs/pytG/lib/python3.8/site-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at /opt/conda/conda-bld/pytorch_1623448278899/work/c10/core/TensorImpl.h:1156.)
return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
0%| | 0/1295 [00:01<?, ?it/s]
Loaded 0 formulas from ./results/result.txt
Loaded 0 formulas from ./results/ref.txt
Traceback (most recent call last):
File "evaluate.py", line 89, in
main()
File "evaluate.py", line 84, in main
score = score_files(args.result_path, args.ref_path)
File "/home/im2latex-master/model/score.py", line 31, in score_files
"BLEU-4": bleu_score(refs, hyps)*100,
File "/home/im2latex-master/model/score.py", line 68, in bleu_score
BLEU_4 = nltk.translate.bleu_score.corpus_bleu(
File "/home/anaconda3/envs/pytG/lib/python3.8/site-packages/nltk/translate/bleu_score.py", line 205, in corpus_bleu
p_n = [
File "/home/anaconda3/envs/pytG/lib/python3.8/site-packages/nltk/translate/bleu_score.py", line 206, in
Fraction(p_numerators[i], p_denominators[i], _normalize=False)
File "/home/anaconda3/envs/pytG/lib/python3.8/fractions.py", line 178, in new
raise ZeroDivisionError('Fraction(%s, 0)' % numerator)
ZeroDivisionError: Fraction(0, 0)

I haven't changed anything on the repo copied. Training is successful, but this error shows in evaluating ( by default on test data).

Thanks in advance.
Shravan

evaluate运行识别问题

运行evaluate.py时,遇到如下报错,请问博主,这个该如何解决呀?
raise ZeroDivisionError('Fraction(%s, 0)' % numerator)
ZeroDivisionError: Fraction(0, 0)

OOM Problem

训练第一个epoch的时候碰到了这个错误
RuntimeError: CUDA out of memory. Tried to allocate 60.00 MiB (GPU 0; 10.76 GiB total capacity; 9.62 GiB already allocated; 31.12 MiB free; 308.09 MiB cached)

训练问题

after i trained the model ,the loss is very low ,but when i evaluate on the train and test dataset all the scores are very very low and the predict is very bad ,why?I haven't change any code.

Unable to Input picture

Hey all,
i was just training the model and i am struck after training that where should I input the picture to get the decoded output.
Thanks in advance

Preprocessing Out Of Memory

Hello,
when calling preprocess.py, it always exits with "-9".
This is due to the "pairs" list in line 21 stores all the 100k formulas with corresponding img.
Did somebody got this working so far ?
Using macOS Monterey (12.3.1) on Apple M1.
Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.