Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updata200411 #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ make im2katex-trainval-ori
```bash
make im2katex-trainval-aug
```
### 预训练权重参数

**BaiduDisk:**

链接: https://pan.baidu.com/s/1cUCSxCaReXw9EPs8_lwCRQ

提取码: bx4b
### 训练自己的数据

#### 数据集预处理
Expand Down Expand Up @@ -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)
* [Dataset ori repo-数据集制作](https://github.com/Miffyli/im2latex-dataset)
2 changes: 1 addition & 1 deletion RunModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ... ...')

Expand Down
Binary file added asset/.DS_Store
Binary file not shown.
Binary file added asset/1.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 asset/10.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 asset/11.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 asset/12.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 asset/13.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 asset/14.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 asset/2.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 asset/3.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 modified asset/4.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 asset/6.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 asset/7.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 asset/8.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 asset/9.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 asset/katex_renedr.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 asset/web_demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions checkpoint/checkpoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
model_checkpoint_path: "seq2seqAtt_781500.ckpt"
all_model_checkpoint_paths: "seq2seqAtt_781500.ckpt"
1 change: 1 addition & 0 deletions checkpoint/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this model used the unifor dataloader, and has no augmentation
Binary file not shown.
Binary file added checkpoint/seq2seqAtt_781500.ckpt.index
Binary file not shown.
Binary file added checkpoint/seq2seqAtt_781500.ckpt.meta
Binary file not shown.
16 changes: 11 additions & 5 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand Down
Binary file added data/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions data/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

errorchecker_dataset/
im2latex_dataset/
errorchecker_dataset/*
im2latex_dataset/*
__pycache__/
*.pyc
2 changes: 1 addition & 1 deletion data/build_errorchecker_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions data/build_imglatex_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion data/config_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion data/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added data/properties.npy
Binary file not shown.
2 changes: 1 addition & 1 deletion dataset_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion init_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions load_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''


Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file added models/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion models/Dis_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/component/LnRnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/component/attention_cell_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/component/attention_cell_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/component/attention_cell_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/component/decoder_beamsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/component/decoder_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/component/decoder_greedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/component/encoder_cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
'''


Expand Down
2 changes: 1 addition & 1 deletion models/component/encoder_densenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion models/component/encoder_rnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/component/trainop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/component/word_embeding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/decoder_error_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''


Expand Down
2 changes: 1 addition & 1 deletion models/discrimitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''


Expand Down
Loading