一、准备
python+torch版Github:https://github.com/OpenNMT/OpenNMT-py
python+torch版说明:http://zh.opennmt.net/OpenNMT-py/main.html
环境:ubuntu+python3+torch
需求:将图片公式转化为latex格式的半结构化字符串
案例:http://zh.opennmt.net/OpenNMT-py/im2text.html
二、过程
1.Download the data.
wget -O data/im2text.tgz http://lstm.seas.harvard.edu/latex/im2text_small.tgz; tar zxf data/im2text.tgz -C data/
2.Preprocess the data.
python3 preprocess.py -data_type img -src_dir data/im2text/images/ -train_src data/im2text/src-train.txt -train_tgt data/im2text/tgt-train.txt -valid_src data/im2text/src-val.txt -valid_tgt data/im2text/tgt-val.txt -save_data data/im2text/demo -tgt_seq_length 150 -tgt_words_min_frequency 2 -shard_size 500 -image_channel_size 1
3.Train the model.
nohup python3 train.py -model_type img -data data/im2text/demo -save_model demo-model -gpu_ranks 0 -batch_size 20 -max_grad_norm 20 -learning_rate 0.1 -word_vec_size 80 -encoder_type brnn -image_channel_size 1 &
4.Translate the images.<