diff --git a/LICENSE b/LICENSE index 5cde388..602932f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 xiaofeng + (c) 2019 xiaofeng Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all +The above notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +AUTHORS OR HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 14d89f5..bbb84a3 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,13 @@ make im2katex-trainval-ori ```bash make im2katex-trainval-aug ``` +### 预训练权重参数 +**BaiduDisk:** + +链接: https://pan.baidu.com/s/1cUCSxCaReXw9EPs8_lwCRQ + +提取码: bx4b ### 训练自己的数据 #### 数据集预处理 @@ -163,4 +169,4 @@ make im2katex-trainval-aug * [Original model repo-网络模型TF](https://github.com/ritheshkumar95/im2latex-tensorflow) * [Another model repo--网络模型TF](https://github.com/baoblackcoal/RFR-solution) * [知乎解释](https://zhuanlan.zhihu.com/p/25031185) -* [Dataset ori repo-数据集制作](https://github.com/Miffyli/im2latex-dataset) \ No newline at end of file +* [Dataset ori repo-数据集制作](https://github.com/Miffyli/im2latex-dataset) diff --git a/RunModel.py b/RunModel.py index 678f26e..3656c38 100644 --- a/RunModel.py +++ b/RunModel.py @@ -7,7 +7,7 @@ Last Modified: Saturday, 29th December 2018 6:35:57 pm Modified By: xiaofeng (sxf1052566766@163.com>) ----- -Copyright 2018.06 - 2018 onion Math, onion Math + 2018.06 - 2018 Latex Math, Latex Math ''' from __future__ import print_function diff --git a/app.py b/app.py index 07b6d5c..c7f1621 100644 --- a/app.py +++ b/app.py @@ -123,10 +123,10 @@ def upload_file(): logger_name='server') logger.info('Server is working ...') # Generate the vocab - _vocab = cfg.VocabSeq2Seq(_config, logger) + _vocab = cfg.VocabSeq2Seq(_config, logger,vacab_file="data/properties.npy") Moedl = LoadModel(ConfClass=_Configure, _config=_config, - _vocab=_vocab, logger=logger, trainable=False) + _vocab=_vocab, logger=logger, pretrainde="./checkpoint/",trainable=False) print('Load models done ... ...') diff --git a/asset/.DS_Store b/asset/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/asset/.DS_Store differ diff --git a/asset/1.png b/asset/1.png new file mode 100644 index 0000000..af7a13c Binary files /dev/null and b/asset/1.png differ diff --git a/asset/10.png b/asset/10.png new file mode 100644 index 0000000..f7fb63d Binary files /dev/null and b/asset/10.png differ diff --git a/asset/11.png b/asset/11.png new file mode 100644 index 0000000..92479e3 Binary files /dev/null and b/asset/11.png differ diff --git a/asset/12.png b/asset/12.png new file mode 100644 index 0000000..543b3dd Binary files /dev/null and b/asset/12.png differ diff --git a/asset/13.png b/asset/13.png new file mode 100644 index 0000000..5affec7 Binary files /dev/null and b/asset/13.png differ diff --git a/asset/14.png b/asset/14.png new file mode 100644 index 0000000..fc86c39 Binary files /dev/null and b/asset/14.png differ diff --git a/asset/2.png b/asset/2.png new file mode 100644 index 0000000..8e6f0eb Binary files /dev/null and b/asset/2.png differ diff --git a/asset/3.png b/asset/3.png new file mode 100644 index 0000000..3843497 Binary files /dev/null and b/asset/3.png differ diff --git a/asset/4.png b/asset/4.png index 015ae4c..35cfb57 100644 Binary files a/asset/4.png and b/asset/4.png differ diff --git a/asset/6.png b/asset/6.png new file mode 100644 index 0000000..418a8f3 Binary files /dev/null and b/asset/6.png differ diff --git a/asset/7.png b/asset/7.png new file mode 100644 index 0000000..df21106 Binary files /dev/null and b/asset/7.png differ diff --git a/asset/8.png b/asset/8.png new file mode 100644 index 0000000..1fcfe34 Binary files /dev/null and b/asset/8.png differ diff --git a/asset/9.png b/asset/9.png new file mode 100644 index 0000000..aa5861b Binary files /dev/null and b/asset/9.png differ diff --git a/asset/katex_renedr.png b/asset/katex_renedr.png new file mode 100644 index 0000000..7437bc2 Binary files /dev/null and b/asset/katex_renedr.png differ diff --git a/asset/web_demo.png b/asset/web_demo.png new file mode 100644 index 0000000..0c1a7a3 Binary files /dev/null and b/asset/web_demo.png differ diff --git a/checkpoint/checkpoint b/checkpoint/checkpoint new file mode 100644 index 0000000..a417411 --- /dev/null +++ b/checkpoint/checkpoint @@ -0,0 +1,2 @@ +model_checkpoint_path: "seq2seqAtt_781500.ckpt" +all_model_checkpoint_paths: "seq2seqAtt_781500.ckpt" diff --git a/checkpoint/readme.txt b/checkpoint/readme.txt new file mode 100644 index 0000000..8bf76a6 --- /dev/null +++ b/checkpoint/readme.txt @@ -0,0 +1 @@ +this model used the unifor dataloader, and has no augmentation diff --git a/checkpoint/seq2seqAtt_781500.ckpt.data-00000-of-00001 b/checkpoint/seq2seqAtt_781500.ckpt.data-00000-of-00001 new file mode 100644 index 0000000..c88f10f Binary files /dev/null and b/checkpoint/seq2seqAtt_781500.ckpt.data-00000-of-00001 differ diff --git a/checkpoint/seq2seqAtt_781500.ckpt.index b/checkpoint/seq2seqAtt_781500.ckpt.index new file mode 100644 index 0000000..00e84e0 Binary files /dev/null and b/checkpoint/seq2seqAtt_781500.ckpt.index differ diff --git a/checkpoint/seq2seqAtt_781500.ckpt.meta b/checkpoint/seq2seqAtt_781500.ckpt.meta new file mode 100644 index 0000000..3dc5488 Binary files /dev/null and b/checkpoint/seq2seqAtt_781500.ckpt.meta differ diff --git a/config.py b/config.py index 35ff566..5c1537c 100644 --- a/config.py +++ b/config.py @@ -7,7 +7,7 @@ Last Modified: Wednesday, 5th December 2018 5:32:04 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' import logging @@ -41,9 +41,10 @@ def __init__(self, data_type, gpu, encoder_type='conv'): self.model() self.dataset() self.predict() - self.initalize_dirs() + def model(self): + _model = edict() _model.batch_size = 16 _model.test_batch_size = 1 @@ -179,14 +180,19 @@ def save_cfg(self): class VocabSeq2Seq: - def __init__(self, config, logger): + def __init__(self, config, logger,vacab_file=None): self._config = config self._logger = logger + self.vacab_file=vacab_file self.load_vocab() def load_vocab(self): - vocab_dir = os.path.abspath(self._config.dataset.vocabulary_file) - vocabulary = np.load(vocab_dir).tolist() + if self.vacab_file is None: + vocab_dir = os.path.abspath(self._config.dataset.vocabulary_file) + else: + vocab_dir=self.vacab_file + print("vocab_dir",vocab_dir) + vocabulary = np.load(vocab_dir,allow_pickle=True).tolist() self.vocab_size = vocabulary['vocab_size'] self.idx_to_token = vocabulary['idx_to_str'] self.token_to_idx = vocabulary['str_to_idx'] diff --git a/data/.DS_Store b/data/.DS_Store new file mode 100644 index 0000000..9b72378 Binary files /dev/null and b/data/.DS_Store differ diff --git a/data/.gitignore b/data/.gitignore index 3fab023..b11773b 100644 --- a/data/.gitignore +++ b/data/.gitignore @@ -1,5 +1,5 @@ -errorchecker_dataset/ -im2latex_dataset/ +errorchecker_dataset/* +im2latex_dataset/* __pycache__/ *.pyc diff --git a/data/build_errorchecker_data.py b/data/build_errorchecker_data.py index a7b047a..0802b74 100644 --- a/data/build_errorchecker_data.py +++ b/data/build_errorchecker_data.py @@ -9,7 +9,7 @@ Last Modified: Monday, 24th December 2018 12:23:37 pm Modified By: xiaofeng (sxf1052566766@163.com>) ----- -Copyright 2018.06 - 2018 onion Math, onion Math + 2018.06 - 2018 Latex Math, Latex Math ''' from __future__ import absolute_import, division, print_function diff --git a/data/build_imglatex_data.py b/data/build_imglatex_data.py index 071250f..44c320f 100644 --- a/data/build_imglatex_data.py +++ b/data/build_imglatex_data.py @@ -7,7 +7,7 @@ Last Modified: Wednesday, 11th July 2018 6:33:16 pm Modified By: xiaofeng (sxf1052566766@163.com>) ----- -Copyright 2018.06 - 2018 onion Math, onion Math + 2018.06 - 2018 Latex Math, Latex Math ''' import json @@ -232,7 +232,7 @@ def generate_dataset(parameters, config): if __name__ == '__main__': print('local or remote represents 0 or 1') - print('Enhance style is: ori, diff_threshold, Onion') + print('Enhance style is: ori, diff_threshold, Latex') local_or_not = int(input('Please select the location: local(0) or remote(1):')) enhance_type = int( diff --git a/data/config_dataset.py b/data/config_dataset.py index af02e39..6134bac 100644 --- a/data/config_dataset.py +++ b/data/config_dataset.py @@ -7,7 +7,7 @@ Last Modified: Tuesday, 11th December 2018 10:58:47 am Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' import numpy as np import os diff --git a/data/data_utils.py b/data/data_utils.py index e821d34..f05b7be 100644 --- a/data/data_utils.py +++ b/data/data_utils.py @@ -9,7 +9,7 @@ Last Modified: Friday, 30th November 2018 5:32:08 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' import copy diff --git a/data/properties.npy b/data/properties.npy new file mode 100644 index 0000000..afb6e25 Binary files /dev/null and b/data/properties.npy differ diff --git a/dataset_iter.py b/dataset_iter.py index 90484de..464db37 100644 --- a/dataset_iter.py +++ b/dataset_iter.py @@ -7,7 +7,7 @@ Last Modified: Sunday, 9th December 2018 4:38:25 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' import os diff --git a/init_logger.py b/init_logger.py index 6d6a65f..da4b0e9 100644 --- a/init_logger.py +++ b/init_logger.py @@ -7,7 +7,7 @@ Last Modified: Sunday, 9th December 2018 6:11:15 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' import logging diff --git a/load_model.py b/load_model.py index e6c2d8c..8abab95 100644 --- a/load_model.py +++ b/load_model.py @@ -7,7 +7,7 @@ Last Modified: Wednesday, 26th December 2018 12:45:11 pm Modified By: xiaofeng (sxf1052566766@163.com>) ----- -Copyright 2018.06 - 2018 onion Math, onion Math +2018.06 - 2018 Latex Math, Latex Math ''' @@ -37,22 +37,23 @@ class LoadModel(object): - def __init__(self, ConfClass, _config, _vocab, logger, trainable=False): + def __init__(self, ConfClass, _config, _vocab, logger, pretrainde=None,trainable=False): self.ConfClass=ConfClass self.config = _config self.vocab = _vocab self.trainable = trainable self.logger = logger + self.pretrainde=pretrainde self.target_height = self.vocab.target_height self.bucket_size = self.vocab.bucket_size self.setup() - def setup(self): + def setup(self,): """ Load model """ self.Model = Seq2SeqAttModel(config=self.config, vocab=self.vocab, logger=self.logger, trainable=self.trainable) self.Model.build_inference() - _ = self.Model.restore_session() + _ = self.Model.restore_session(pretrainde=self.pretrainde) self.temp_path = os.path.abspath(self.config.predict.temp_path) self.preprocess_dir = os.path.abspath(self.config.predict.preprocess_dir) diff --git a/main.py b/main.py index 804a415..219f014 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ Last Modified: Wednesday, 5th December 2018 5:20:32 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' from __future__ import print_function diff --git a/makefile b/makefile index d80de1a..f5bac47 100644 --- a/makefile +++ b/makefile @@ -28,7 +28,10 @@ error-inference: python3 main.py --mode infer --predict_img_path /home/xiaofeng/data/image2latex/handwritten/process/img_padding --model_type im2katex -server: +server-cpu: + python3 app.py --data_type merged --gpu=-1 + +server-gpu: python3 app.py --data_type merged --gpu=0 # full: build train eval diff --git a/models/.DS_Store b/models/.DS_Store new file mode 100644 index 0000000..c588b5e Binary files /dev/null and b/models/.DS_Store differ diff --git a/models/Dis_model.py b/models/Dis_model.py index 42e1004..4dec919 100644 --- a/models/Dis_model.py +++ b/models/Dis_model.py @@ -7,7 +7,7 @@ Last Modified: Tuesday, 3rd July 2018 11:58:46 am Modified By: xiaofeng (sxf1052566766@163.com>) ----- -Copyright 2018.06 - 2018 onion Math, onion Math + 2018.06 - 2018 Latex Math, Latex Math ''' import sys import time diff --git a/models/__init__.py b/models/__init__.py index fa05e45..a4e2768 100755 --- a/models/__init__.py +++ b/models/__init__.py @@ -7,7 +7,7 @@ Last Modified: Sunday, 2nd December 2018 4:12:02 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' from .seq2seq_model import Seq2SeqAttModel diff --git a/models/component/LnRnn.py b/models/component/LnRnn.py index 5ff12ac..6044f6c 100644 --- a/models/component/LnRnn.py +++ b/models/component/LnRnn.py @@ -7,7 +7,7 @@ Last Modified: Friday, 14th December 2018 5:17:47 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' from __future__ import absolute_import, division, print_function diff --git a/models/component/attention_cell_compile.py b/models/component/attention_cell_compile.py index 8b5cbf0..647be52 100644 --- a/models/component/attention_cell_compile.py +++ b/models/component/attention_cell_compile.py @@ -7,7 +7,7 @@ Last Modified: Sunday, 2nd December 2018 2:26:37 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' import collections diff --git a/models/component/attention_cell_sequence.py b/models/component/attention_cell_sequence.py index 20f3144..852a12b 100644 --- a/models/component/attention_cell_sequence.py +++ b/models/component/attention_cell_sequence.py @@ -7,7 +7,7 @@ Last Modified: Friday, 28th December 2018 6:50:40 pm Modified By: xiaofeng (sxf1052566766@163.com>) ----- -Copyright 2018.06 - 2018 onion Math, onion Math + 2018.06 - 2018 Latex Math, Latex Math ''' import collections diff --git a/models/component/attention_cell_step.py b/models/component/attention_cell_step.py index 54abcb5..643b475 100644 --- a/models/component/attention_cell_step.py +++ b/models/component/attention_cell_step.py @@ -7,7 +7,7 @@ Last Modified: Sunday, 2nd December 2018 2:26:37 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' import tensorflow as tf diff --git a/models/component/decoder_beamsearch.py b/models/component/decoder_beamsearch.py index 11da2ec..8ca6947 100644 --- a/models/component/decoder_beamsearch.py +++ b/models/component/decoder_beamsearch.py @@ -7,7 +7,7 @@ Last Modified: Thursday, 29th November 2018 7:38:14 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' import tensorflow as tf diff --git a/models/component/decoder_dynamic.py b/models/component/decoder_dynamic.py index b348c7f..3cb3158 100644 --- a/models/component/decoder_dynamic.py +++ b/models/component/decoder_dynamic.py @@ -7,7 +7,7 @@ Last Modified: Thursday, 29th November 2018 7:39:08 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' import tensorflow as tf diff --git a/models/component/decoder_greedy.py b/models/component/decoder_greedy.py index bc4cd68..d7c55e5 100644 --- a/models/component/decoder_greedy.py +++ b/models/component/decoder_greedy.py @@ -7,7 +7,7 @@ Last Modified: Thursday, 29th November 2018 7:38:26 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' import tensorflow as tf diff --git a/models/component/encoder_cnn.py b/models/component/encoder_cnn.py index bec340e..17a35e2 100644 --- a/models/component/encoder_cnn.py +++ b/models/component/encoder_cnn.py @@ -7,7 +7,7 @@ Last Modified: Friday, 14th December 2018 3:33:12 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' diff --git a/models/component/encoder_densenet.py b/models/component/encoder_densenet.py index 907ff82..7687d0f 100644 --- a/models/component/encoder_densenet.py +++ b/models/component/encoder_densenet.py @@ -7,7 +7,7 @@ Last Modified: Sunday, 9th December 2018 8:38:04 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' from __future__ import absolute_import, division, print_function diff --git a/models/component/encoder_rnn.py b/models/component/encoder_rnn.py index 6e64bf8..d89219b 100644 --- a/models/component/encoder_rnn.py +++ b/models/component/encoder_rnn.py @@ -7,7 +7,7 @@ Last Modified: Friday, 14th December 2018 5:37:07 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' from __future__ import absolute_import, division, print_function diff --git a/models/component/trainop.py b/models/component/trainop.py index 2e52461..47a0758 100644 --- a/models/component/trainop.py +++ b/models/component/trainop.py @@ -7,7 +7,7 @@ Last Modified: Sunday, 2nd December 2018 2:28:25 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' import numpy as np diff --git a/models/component/word_embeding.py b/models/component/word_embeding.py index 052f1fe..603b464 100644 --- a/models/component/word_embeding.py +++ b/models/component/word_embeding.py @@ -7,7 +7,7 @@ Last Modified: Sunday, 2nd December 2018 2:39:14 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' import tensorflow as tf diff --git a/models/decoder.py b/models/decoder.py index f76e996..f08204e 100755 --- a/models/decoder.py +++ b/models/decoder.py @@ -7,7 +7,7 @@ Last Modified: Sunday, 2nd December 2018 4:09:59 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' from __future__ import division diff --git a/models/decoder_error_checker.py b/models/decoder_error_checker.py index 6927266..59cb06f 100755 --- a/models/decoder_error_checker.py +++ b/models/decoder_error_checker.py @@ -7,7 +7,7 @@ Last Modified: Saturday, 29th December 2018 3:07:45 pm Modified By: xiaofeng (sxf1052566766@163.com>) ----- -Copyright 2018.06 - 2018 onion Math, onion Math + 2018.06 - 2018 Latex Math, Latex Math ''' diff --git a/models/discrimitor.py b/models/discrimitor.py index d4b84a2..fb3963d 100644 --- a/models/discrimitor.py +++ b/models/discrimitor.py @@ -7,7 +7,7 @@ Last Modified: Friday, 22nd February 2019 10:53:59 am Modified By: xiaofeng (sxf1052566766@163.com>) ----- -Copyright 2018.06 - 2019 onion Math, onion Math + 2018.06 - 2019 Latex Math, Latex Math ''' diff --git a/models/encoder.py b/models/encoder.py index ea0a961..afee3be 100755 --- a/models/encoder.py +++ b/models/encoder.py @@ -7,7 +7,7 @@ Last Modified: Sunday, 2nd December 2018 4:09:49 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' from __future__ import absolute_import, division, print_function diff --git a/models/encoder_error_checker.py b/models/encoder_error_checker.py index a2cd45c..cafa4cb 100644 --- a/models/encoder_error_checker.py +++ b/models/encoder_error_checker.py @@ -7,7 +7,7 @@ Last Modified: Saturday, 29th December 2018 3:05:33 pm Modified By: xiaofeng (sxf1052566766@163.com>) ----- -Copyright 2018.06 - 2018 onion Math, onion Math + 2018.06 - 2018 Latex Math, Latex Math ''' diff --git a/models/error_checker_model.py b/models/error_checker_model.py index 2a31876..f6531db 100644 --- a/models/error_checker_model.py +++ b/models/error_checker_model.py @@ -7,7 +7,7 @@ Last Modified: Tuesday, 3rd July 2018 11:58:46 am Modified By: xiaofeng (sxf1052566766@163.com>) ----- -Copyright 2018.06 - 2018 onion Math, onion Math + 2018.06 - 2018 Latex Math, Latex Math ''' import sys import time diff --git a/models/evaluate/image.py b/models/evaluate/image.py index 30de9dc..6e53df4 100644 --- a/models/evaluate/image.py +++ b/models/evaluate/image.py @@ -7,7 +7,7 @@ Last Modified: Saturday, 22nd December 2018 4:00:03 pm Modified By: xiaofeng (sxf1052566766@163.com>) ----- -Copyright 2018.06 - 2018 onion Math, onion Math + 2018.06 - 2018 Latex Math, Latex Math ''' from os import listdir diff --git a/models/evaluate/text.py b/models/evaluate/text.py index fdbae37..ac7bea5 100644 --- a/models/evaluate/text.py +++ b/models/evaluate/text.py @@ -7,7 +7,7 @@ Last Modified: Saturday, 22nd December 2018 4:00:46 pm Modified By: xiaofeng (sxf1052566766@163.com>) ----- -Copyright 2018.06 - 2018 onion Math, onion Math + 2018.06 - 2018 Latex Math, Latex Math ''' import os diff --git a/models/model_base.py b/models/model_base.py index 576ed64..129ab38 100644 --- a/models/model_base.py +++ b/models/model_base.py @@ -7,7 +7,7 @@ Last Modified: Thursday, 6th December 2018 7:40:45 pm Modified By: xiaofeng (sxf1052566766@163.com) --------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath +: 2018.06 - 2018 . ''' import codecs @@ -46,7 +46,7 @@ def how_many_paras(self, checkpoint_path): def init_session(self): NotImplemented - def restore_session(self): + def restore_session(self,pretrainde=None): """Reload weights into session Args: @@ -54,7 +54,10 @@ def restore_session(self): return: restore_iter: int """ - dir_model = self._ckpt_dir + if pretrainde is None: + dir_model = self._ckpt_dir + else: + dir_model=pretrainde # print('Model directionary is [{:s}]'.format(dir_model)) restore_iter = 0 if os.listdir(dir_model): diff --git a/models/seq2seq_model.py b/models/seq2seq_model.py index 6c5de0f..d52f4a9 100644 --- a/models/seq2seq_model.py +++ b/models/seq2seq_model.py @@ -7,7 +7,7 @@ Last Modified: Tuesday, 3rd July 2018 11:58:46 am Modified By: xiaofeng (sxf1052566766@163.com>) ----- -Copyright 2018.06 - 2018 onion Math, onion Math + 2018.06 - 2018 Latex Math, Latex Math ''' import sys import time diff --git a/setup.sh b/setup.sh index c1ef874..9cafe24 100644 --- a/setup.sh +++ b/setup.sh @@ -12,3 +12,4 @@ export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY # cd ${SHELL_FOLDER} # Run the model # python3 app.py --device gpu --crnn Densenet +pip install easydict nltk distance \ No newline at end of file diff --git a/static/preprocess/15865866565539892-2.png b/static/preprocess/15865866565539892-2.png new file mode 100644 index 0000000..6dbaec6 Binary files /dev/null and b/static/preprocess/15865866565539892-2.png differ diff --git a/static/preprocess/158658715275716-1a0a2bdae8.png b/static/preprocess/158658715275716-1a0a2bdae8.png new file mode 100644 index 0000000..df1b311 Binary files /dev/null and b/static/preprocess/158658715275716-1a0a2bdae8.png differ diff --git a/static/preprocess/15865874728250759-1a0ad579d6.png b/static/preprocess/15865874728250759-1a0ad579d6.png new file mode 100644 index 0000000..dcc20de Binary files /dev/null and b/static/preprocess/15865874728250759-1a0ad579d6.png differ diff --git a/static/preprocess/15865874859745102-1a00b6791d.png b/static/preprocess/15865874859745102-1a00b6791d.png new file mode 100644 index 0000000..85cec5c Binary files /dev/null and b/static/preprocess/15865874859745102-1a00b6791d.png differ diff --git a/static/preprocess/1586587493175126-1a0a2bdae8.png b/static/preprocess/1586587493175126-1a0a2bdae8.png new file mode 100644 index 0000000..df1b311 Binary files /dev/null and b/static/preprocess/1586587493175126-1a0a2bdae8.png differ diff --git a/static/preprocess/15865875079271822-1a0ad579d6.png b/static/preprocess/15865875079271822-1a0ad579d6.png new file mode 100644 index 0000000..dcc20de Binary files /dev/null and b/static/preprocess/15865875079271822-1a0ad579d6.png differ diff --git a/static/preprocess/1586587520752586-13.png b/static/preprocess/1586587520752586-13.png new file mode 100644 index 0000000..60403b7 Binary files /dev/null and b/static/preprocess/1586587520752586-13.png differ diff --git a/static/preprocess/1586587530193481-3.png b/static/preprocess/1586587530193481-3.png new file mode 100644 index 0000000..8e2c401 Binary files /dev/null and b/static/preprocess/1586587530193481-3.png differ diff --git a/static/preprocess/1586587557282547-1a00b6791d.png b/static/preprocess/1586587557282547-1a00b6791d.png new file mode 100644 index 0000000..85cec5c Binary files /dev/null and b/static/preprocess/1586587557282547-1a00b6791d.png differ diff --git a/static/preprocess/1586587601574955-1a0fcb9fb1.png b/static/preprocess/1586587601574955-1a0fcb9fb1.png new file mode 100644 index 0000000..f58d7da Binary files /dev/null and b/static/preprocess/1586587601574955-1a0fcb9fb1.png differ diff --git a/static/preprocess/1586587638629975-1a1ee0df37.png b/static/preprocess/1586587638629975-1a1ee0df37.png new file mode 100644 index 0000000..995e69c Binary files /dev/null and b/static/preprocess/1586587638629975-1a1ee0df37.png differ diff --git a/static/preprocess/1586587704373087-1a1ee0df37.png b/static/preprocess/1586587704373087-1a1ee0df37.png new file mode 100644 index 0000000..995e69c Binary files /dev/null and b/static/preprocess/1586587704373087-1a1ee0df37.png differ diff --git a/static/preprocess/1586587831208693-15.png b/static/preprocess/1586587831208693-15.png new file mode 100644 index 0000000..fb2dbb5 Binary files /dev/null and b/static/preprocess/1586587831208693-15.png differ diff --git a/static/preprocess/1586587918020267-4.png b/static/preprocess/1586587918020267-4.png new file mode 100644 index 0000000..5b20ca2 Binary files /dev/null and b/static/preprocess/1586587918020267-4.png differ diff --git a/static/preprocess/1586587931671571-7.png b/static/preprocess/1586587931671571-7.png new file mode 100644 index 0000000..9f367c3 Binary files /dev/null and b/static/preprocess/1586587931671571-7.png differ diff --git a/static/render/15865866565539892-2.tex b/static/render/15865866565539892-2.tex new file mode 100644 index 0000000..7501e76 --- /dev/null +++ b/static/render/15865866565539892-2.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +\tilde { \gamma } _ { \mathrm { i n e f } } \simeq \sum _ { n > 0 } \tilde { G } _ { \mathrm { i n } } \frac { ( - a ) } { 2 ^ { 2 n - } } +\end{displaymath} + +\end{document} diff --git a/static/render/158658715275716-1a0a2bdae8.tex b/static/render/158658715275716-1a0a2bdae8.tex new file mode 100644 index 0000000..b4f4487 --- /dev/null +++ b/static/render/158658715275716-1a0a2bdae8.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +{ \cal K } _ { a } ^ { \mu } { \frac { \partial } { \partial z _ { \omega } } } = { \frac { \theta } { \partial \psi _ { a } } } +\end{displaymath} + +\end{document} diff --git a/static/render/15865874728250759-1a0ad579d6.tex b/static/render/15865874728250759-1a0ad579d6.tex new file mode 100644 index 0000000..23ab9d9 --- /dev/null +++ b/static/render/15865874728250759-1a0ad579d6.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +Q ^ { a } = \pm \frac { 2 i } { a } \Upsilon _ { } _ { { } ^ { +\end{displaymath} + +\end{document} diff --git a/static/render/15865874859745102-1a00b6791d.tex b/static/render/15865874859745102-1a00b6791d.tex new file mode 100644 index 0000000..9c58fa8 --- /dev/null +++ b/static/render/15865874859745102-1a00b6791d.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +{ { F } _ { \mu \nu } ^ { \nu } = \partial _ { \mu } { \bf A } _ { \nu } - \partial _ { \nu } { _ { \mu } { \mu } _ { +\end{displaymath} + +\end{document} diff --git a/static/render/1586587493175126-1a0a2bdae8.tex b/static/render/1586587493175126-1a0a2bdae8.tex new file mode 100644 index 0000000..b4f4487 --- /dev/null +++ b/static/render/1586587493175126-1a0a2bdae8.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +{ \cal K } _ { a } ^ { \mu } { \frac { \partial } { \partial z _ { \omega } } } = { \frac { \theta } { \partial \psi _ { a } } } +\end{displaymath} + +\end{document} diff --git a/static/render/15865875079271822-1a0ad579d6.tex b/static/render/15865875079271822-1a0ad579d6.tex new file mode 100644 index 0000000..23ab9d9 --- /dev/null +++ b/static/render/15865875079271822-1a0ad579d6.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +Q ^ { a } = \pm \frac { 2 i } { a } \Upsilon _ { } _ { { } ^ { +\end{displaymath} + +\end{document} diff --git a/static/render/1586587520752586-13.tex b/static/render/1586587520752586-13.tex new file mode 100644 index 0000000..400ca9e --- /dev/null +++ b/static/render/1586587520752586-13.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +z _ { i j } ( x ) = \frac { 1 } { e ^ { 2 } } \delta _ { i _ { 1 } } \; \; \phi ^ { a } ( x ) = \phi ^ { a } , \; \; \; ( a \, \phi ^ { a } : \mathrm { c o n s i } +\end{displaymath} + +\end{document} diff --git a/static/render/1586587530193481-3.tex b/static/render/1586587530193481-3.tex new file mode 100644 index 0000000..9356009 --- /dev/null +++ b/static/render/1586587530193481-3.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +( ( L _ { n } } { { ) } ) _ { i i } = 0 . \quad ( { \cal \cal } _ { { } H ) _ { i k k } = 0 . +\end{displaymath} + +\end{document} diff --git a/static/render/1586587557282547-1a00b6791d.tex b/static/render/1586587557282547-1a00b6791d.tex new file mode 100644 index 0000000..9c58fa8 --- /dev/null +++ b/static/render/1586587557282547-1a00b6791d.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +{ { F } _ { \mu \nu } ^ { \nu } = \partial _ { \mu } { \bf A } _ { \nu } - \partial _ { \nu } { _ { \mu } { \mu } _ { +\end{displaymath} + +\end{document} diff --git a/static/render/1586587601574955-1a0fcb9fb1.tex b/static/render/1586587601574955-1a0fcb9fb1.tex new file mode 100644 index 0000000..5629f38 --- /dev/null +++ b/static/render/1586587601574955-1a0fcb9fb1.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +{ \cal F } _ { x } { } ^ { \mu ^ { \mu } = \frac 1 2 - f } ^ { \mu } { } ^ { \mu } , +\end{displaymath} + +\end{document} diff --git a/static/render/1586587638629975-1a1ee0df37.tex b/static/render/1586587638629975-1a1ee0df37.tex new file mode 100644 index 0000000..d98b6c1 --- /dev/null +++ b/static/render/1586587638629975-1a1ee0df37.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +h _ { { 1 } { 2 } \frac { \varepsilon ^ { p - s } } { s } } { \, - +\end{displaymath} + +\end{document} diff --git a/static/render/1586587704373087-1a1ee0df37.tex b/static/render/1586587704373087-1a1ee0df37.tex new file mode 100644 index 0000000..d98b6c1 --- /dev/null +++ b/static/render/1586587704373087-1a1ee0df37.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +h _ { { 1 } { 2 } \frac { \varepsilon ^ { p - s } } { s } } { \, - +\end{displaymath} + +\end{document} diff --git a/static/render/1586587831208693-15.tex b/static/render/1586587831208693-15.tex new file mode 100644 index 0000000..8d9d01e --- /dev/null +++ b/static/render/1586587831208693-15.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +s _ { L } ( q ) = \sum _ { n = 1 } ^ { L } \, p _ { L } ( m ) \, \frac { 1 } { q ^ { n - 1 } } \, . +\end{displaymath} + +\end{document} diff --git a/static/render/1586587918020267-4.tex b/static/render/1586587918020267-4.tex new file mode 100644 index 0000000..d03a572 --- /dev/null +++ b/static/render/1586587918020267-4.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +S _ { s { s u s } } = 2 \pi \sqrt { N _ { { ( 1 ) } 1 ) } 5 } ^ { ( 2 ) } N _ { N _ { { ( 3 ) } } \left( \sqrt { \pi } + \sqrt { \pi } +\end{displaymath} + +\end{document} diff --git a/static/render/1586587931671571-7.tex b/static/render/1586587931671571-7.tex new file mode 100644 index 0000000..3497a8a --- /dev/null +++ b/static/render/1586587931671571-7.tex @@ -0,0 +1,11 @@ + +\documentclass[12pt]{article} +\pagestyle{empty} +\usepackage{amsmath} +\begin{document} + +\begin{displaymath} +\mathrm { d } \, ^ { * } H = \kappa \, ^ { * } d d = 5 _ { 6 } +\end{displaymath} + +\end{document} diff --git a/temp/imgs/uploaded/15865866565539892-2.png b/temp/imgs/uploaded/15865866565539892-2.png new file mode 100644 index 0000000..8e6f0eb Binary files /dev/null and b/temp/imgs/uploaded/15865866565539892-2.png differ diff --git a/temp/imgs/uploaded/158658715275716-1a0a2bdae8.png b/temp/imgs/uploaded/158658715275716-1a0a2bdae8.png new file mode 100644 index 0000000..853c37a Binary files /dev/null and b/temp/imgs/uploaded/158658715275716-1a0a2bdae8.png differ diff --git a/temp/imgs/uploaded/15865874728250759-1a0ad579d6.png b/temp/imgs/uploaded/15865874728250759-1a0ad579d6.png new file mode 100644 index 0000000..785d9ab Binary files /dev/null and b/temp/imgs/uploaded/15865874728250759-1a0ad579d6.png differ diff --git a/temp/imgs/uploaded/15865874859745102-1a00b6791d.png b/temp/imgs/uploaded/15865874859745102-1a00b6791d.png new file mode 100644 index 0000000..89d9a74 Binary files /dev/null and b/temp/imgs/uploaded/15865874859745102-1a00b6791d.png differ diff --git a/temp/imgs/uploaded/1586587493175126-1a0a2bdae8.png b/temp/imgs/uploaded/1586587493175126-1a0a2bdae8.png new file mode 100644 index 0000000..853c37a Binary files /dev/null and b/temp/imgs/uploaded/1586587493175126-1a0a2bdae8.png differ diff --git a/temp/imgs/uploaded/15865875079271822-1a0ad579d6.png b/temp/imgs/uploaded/15865875079271822-1a0ad579d6.png new file mode 100644 index 0000000..785d9ab Binary files /dev/null and b/temp/imgs/uploaded/15865875079271822-1a0ad579d6.png differ diff --git a/temp/imgs/uploaded/1586587520752586-13.png b/temp/imgs/uploaded/1586587520752586-13.png new file mode 100644 index 0000000..5affec7 Binary files /dev/null and b/temp/imgs/uploaded/1586587520752586-13.png differ diff --git a/temp/imgs/uploaded/1586587530193481-3.png b/temp/imgs/uploaded/1586587530193481-3.png new file mode 100644 index 0000000..3843497 Binary files /dev/null and b/temp/imgs/uploaded/1586587530193481-3.png differ diff --git a/temp/imgs/uploaded/1586587557282547-1a00b6791d.png b/temp/imgs/uploaded/1586587557282547-1a00b6791d.png new file mode 100644 index 0000000..89d9a74 Binary files /dev/null and b/temp/imgs/uploaded/1586587557282547-1a00b6791d.png differ diff --git a/temp/imgs/uploaded/1586587601574955-1a0fcb9fb1.png b/temp/imgs/uploaded/1586587601574955-1a0fcb9fb1.png new file mode 100644 index 0000000..4b15a79 Binary files /dev/null and b/temp/imgs/uploaded/1586587601574955-1a0fcb9fb1.png differ diff --git a/temp/imgs/uploaded/1586587638629975-1a1ee0df37.png b/temp/imgs/uploaded/1586587638629975-1a1ee0df37.png new file mode 100644 index 0000000..30401ae Binary files /dev/null and b/temp/imgs/uploaded/1586587638629975-1a1ee0df37.png differ diff --git a/temp/imgs/uploaded/1586587704373087-1a1ee0df37.png b/temp/imgs/uploaded/1586587704373087-1a1ee0df37.png new file mode 100644 index 0000000..30401ae Binary files /dev/null and b/temp/imgs/uploaded/1586587704373087-1a1ee0df37.png differ diff --git a/temp/imgs/uploaded/1586587831208693-15.png b/temp/imgs/uploaded/1586587831208693-15.png new file mode 100644 index 0000000..2135f48 Binary files /dev/null and b/temp/imgs/uploaded/1586587831208693-15.png differ diff --git a/temp/imgs/uploaded/1586587918020267-4.png b/temp/imgs/uploaded/1586587918020267-4.png new file mode 100644 index 0000000..35cfb57 Binary files /dev/null and b/temp/imgs/uploaded/1586587918020267-4.png differ diff --git a/temp/imgs/uploaded/1586587931671571-7.png b/temp/imgs/uploaded/1586587931671571-7.png new file mode 100644 index 0000000..df21106 Binary files /dev/null and b/temp/imgs/uploaded/1586587931671571-7.png differ diff --git a/templates/.DS_Store b/templates/.DS_Store new file mode 100644 index 0000000..7f56805 Binary files /dev/null and b/templates/.DS_Store differ diff --git a/utils/TextUtil.py b/utils/TextUtil.py index 08188f5..99fa97f 100644 --- a/utils/TextUtil.py +++ b/utils/TextUtil.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright (c) 2008-11 Qtrac Ltd. All rights reserved. +# (c) 2008-11 Qtrac Ltd. All rights reserved. # This program or module is free software: you can redistribute it and/or # modify it under the terms of the GNU General Public License as published # by the Free Software Foundation, either version 3 of the License, or diff --git a/utils/frozen.py b/utils/frozen.py new file mode 100644 index 0000000..b63af65 --- /dev/null +++ b/utils/frozen.py @@ -0,0 +1,22 @@ +import tensorflow as tf +import os + +project_path = os.path.abspath(os.path.basename(os.path.join(os.path.realpath(__file__), '..'))) +checkpoints = tf.train.get_checkpoint_state(project_path + '/checkpoint') +input_checkpoint = checkpoints.model_checkpoint_path +print('input_checkpoint:', input_checkpoint) + +absolute_model = '/'.join(input_checkpoint.split('/')[:-1]) +print('absolute_model:', absolute_model) +out_graph = absolute_model+'/fozen_model.pb' + +with tf.Session(graph=tf.Graph()) as sess: + saver = tf.train.import_meta_graph(input_checkpoint + '.meta', clear_devices=True) + + saver.restore(sess, input_checkpoint) + + for op in tf.get_default_graph().get_operations(): + print(op.name, op.values()) + # NOTE: 模型的输出tensor名称是什么? + output_graph = tf.graph_util.convert_variables_to_constants( + sess, tf.get_default_graph().as_graph_def(), output_node_names=['']) diff --git a/utils/process_image.py b/utils/process_image.py index 12e6763..d0a0f9f 100644 --- a/utils/process_image.py +++ b/utils/process_image.py @@ -7,7 +7,7 @@ Last Modified: Saturday, 22nd December 2018 11:59:35 am Modified By: xiaofeng (sxf1052566766@163.com>) ----- -Copyright 2018.06 - 2018 onion Math, onion Math + 2018.06 - 2018 Latex Math, Latex Math ''' import os diff --git a/utils/render_image.py b/utils/render_image.py index 0629844..15c32c1 100644 --- a/utils/render_image.py +++ b/utils/render_image.py @@ -1,14 +1,20 @@ -''' -Filename: render_image.py -Project: utils -File Created: Tuesday, 18th December 2018 7:15:40 pm -Author: xiaofeng (sxf1052566766@163.com) --------------------------- -Last Modified: Tuesday, 18th December 2018 7:46:31 pm -Modified By: xiaofeng (sxf1052566766@163.com) ---------------------------- -Copyright: 2018.06 - 2018 OnionMath. OnionMath -''' +# !/usr/bin/env python +# -*- coding:utf-8 -*- +# ================================================================== +# Life is short, You need Python! +# [File] : render_image.py +# [Project] : shixiaofeng +# [CreatedDate] : Thursday, 2019-03-14 11:42:56 +# [Author] : shixiaofeng +# ================================================================== +# [LastModified] : Saturday, 2020-04-11 14:38:34 +# [ModifiedBy] : shixiaofeng +# [Descriptions] : +# +# ================================================================== +# [ChangeLog]: +# [Date] [Author] [Comments] +# ------------------------------------------------------------------ import glob import os @@ -49,45 +55,49 @@ def latex_to_image(formula, file_name_no_ext, logger, quality=200, density=200): render the image based latex """ - rend_setup = RENDERING_SETUPS - full_path = file_name_no_ext - # Create latex source - _latex = rend_setup[0] % formula - # Write latex source - with open(full_path + ".tex", "w") as f: - f.write(_latex) - - # Call pdflatex to turn .tex into .pdf - code = call(["pdflatex", '-interaction=nonstopmode', '-halt-on-error', - full_path + ".tex"], stdout=DEVNULL, stderr=DEVNULL) - - if code != 0: - os.system("rm -rf " + full_path + "*") - logger.info('The latex is [{:s}] and can not be rendered'.format(formula)) - return False - - # Turn .pdf to .png - # Handles variable number of places to insert path. - # i.e. "%s.tex" vs "%s.pdf %s.png" - - cmd_str = (quality, density, full_path + ".pdf", full_path + ".png") - code = call((rend_setup[1] % cmd_str).split(" "), stdout=DEVNULL, stderr=DEVNULL) - # Remove files try: - remove_temp_files(full_path) + rend_setup = RENDERING_SETUPS + full_path = file_name_no_ext + # Create latex source + _latex = rend_setup[0] % formula + # Write latex source + with open(full_path + ".tex", "w") as f: + f.write(_latex) + + # Call pdflatex to turn .tex into .pdf + code = call(["pdflatex", '-interaction=nonstopmode', '-halt-on-error', + full_path + ".tex"], stdout=DEVNULL, stderr=DEVNULL) + + if code != 0: + os.system("rm -rf " + full_path + "*") + logger.info('The latex is [{:s}] and can not be rendered'.format(formula)) + return False + + # Turn .pdf to .png + # Handles variable number of places to insert path. + # i.e. "%s.tex" vs "%s.pdf %s.png" + + cmd_str = (quality, density, full_path + ".pdf", full_path + ".png") + code = call((rend_setup[1] % cmd_str).split(" "), stdout=DEVNULL, stderr=DEVNULL) + # Remove files + try: + remove_temp_files(full_path) + except Exception as e: + # try-except in case one of the previous scripts removes these files + # already + logger.info('Can not remove the temp rendering files') + return False + + # Detect of convert created multiple images -> multi-page PDF + + if code != 0: + # Error during rendering, remove files and return None + os.system("rm -rf " + full_path + "*") + logger.info('Can not convert pdf to png, please check the cmd message: {}'.format( + (rend_setup[1] % cmd_str).split(" "))) + return False + else: + return True except Exception as e: - # try-except in case one of the previous scripts removes these files - # already - logger.info('Can not remove the temp rendering files') - return False - - # Detect of convert created multiple images -> multi-page PDF - - if code != 0: - # Error during rendering, remove files and return None - os.system("rm -rf " + full_path + "*") - logger.info('Can not convert pdf to png, please check the cmd message: {}'.format( - (rend_setup[1] % cmd_str).split(" "))) + print("render image error {}".format(e)) return False - else: - return True