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

[Feature] Add Satrn #405

Merged
merged 37 commits into from
Aug 19, 2021
Merged

[Feature] Add Satrn #405

merged 37 commits into from
Aug 19, 2021

Conversation

2793145003
Copy link
Contributor

Hi, 我在我自己的数据集(10w条数据)上使用了 SATRN(https://arxiv.org/pdf/1910.04396.pdf)的 small 版本,最开始的几天 acc 完全没有变化,但之后上升得很快,目前 word_acc=0.9245 并且还在缓慢上升中(执行时间 266:17:00)。
不过我没有足够的资源和时间使用公开数据集,也没有足够显存运行完整的模型,所以没有相应的指标,也不能保证 satrn_academic(论文中的结构)也能得到好的效果……

@codecov
Copy link

codecov bot commented Aug 2, 2021

Codecov Report

Merging #405 (421c57b) into main (7571763) will increase coverage by 0.16%.
The diff coverage is 100.00%.

❗ Current head 421c57b differs from pull request most recent head ed821c0. Consider uploading reports for the commit ed821c0 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #405      +/-   ##
==========================================
+ Coverage   85.34%   85.50%   +0.16%     
==========================================
  Files         139      142       +3     
  Lines        9380     9502     +122     
  Branches     1343     1353      +10     
==========================================
+ Hits         8005     8125     +120     
- Misses       1065     1066       +1     
- Partials      310      311       +1     
Flag Coverage Δ
unittests 85.50% <100.00%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmocr/utils/ocr.py 75.69% <ø> (ø)
mmocr/models/textrecog/backbones/shallow_cnn.py 100.00% <100.00%> (ø)
mmocr/models/textrecog/encoders/satrn_encoder.py 100.00% <100.00%> (ø)
mmocr/models/textrecog/layers/transformer_layer.py 99.44% <100.00%> (+0.32%) ⬆️
mmocr/models/textrecog/recognizer/satrn.py 100.00% <100.00%> (ø)
mmocr/datasets/pipelines/transforms.py 81.18% <0.00%> (-0.34%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7571763...ed821c0. Read the comment docs.

Copy link
Collaborator

@gaotongxiao gaotongxiao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! Your work is excellent and really constructive to MMOCR!

I had compared your implementation with the official release and found some differences that should be addressed. Some are not significant but might slightly affect the performance. (We want to be conservative on this model due to its long training cycle) I had also commented on some parts that I'm not quite sure and we can discuss.

Meanwhile, we are also training the full Satrn model so we'll see if the model can match the claimed performance.

mmocr/models/textrecog/backbones/shallow_cnn.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/backbones/shallow_cnn.py Outdated Show resolved Hide resolved
configs/textrecog/satrn/satrn_academic.py Outdated Show resolved Hide resolved
configs/textrecog/satrn/satrn_small.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
configs/textrecog/satrn/satrn_academic.py Outdated Show resolved Hide resolved
configs/textrecog/satrn/satrn_small.py Outdated Show resolved Hide resolved
tests/test_models/test_ocr_encoder.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@gaotongxiao gaotongxiao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the config to get a closer implementation to the official implementation.

configs/textrecog/satrn/satrn_small.py Outdated Show resolved Hide resolved
configs/textrecog/satrn/satrn_academic.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
2793145003 and others added 12 commits August 9, 2021 12:44
Co-authored-by: Tong Gao <gaotongxiao@gmail.com>
Co-authored-by: Tong Gao <gaotongxiao@gmail.com>
Co-authored-by: Tong Gao <gaotongxiao@gmail.com>
Co-authored-by: Tong Gao <gaotongxiao@gmail.com>
Co-authored-by: Tong Gao <gaotongxiao@gmail.com>
Co-authored-by: Tong Gao <gaotongxiao@gmail.com>
Co-authored-by: Tong Gao <gaotongxiao@gmail.com>
Co-authored-by: Tong Gao <gaotongxiao@gmail.com>
Co-authored-by: Tong Gao <gaotongxiao@gmail.com>
Co-authored-by: Tong Gao <gaotongxiao@gmail.com>
Co-authored-by: Tong Gao <gaotongxiao@gmail.com>
@gaotongxiao
Copy link
Collaborator

For now, I've trained your original Satrn implementation on Synthtext + Mjsynth for 5 epochs, but only got ~ 10%-20% accuracy on test sets. The modified version is still in its first training epoch but gets an average loss of ~0.02 which is 10 times smaller than the original one. I think we are on the right track.

@gaotongxiao gaotongxiao changed the title Add Satrn [Feature] Add Satrn Aug 9, 2021
@gaotongxiao
Copy link
Collaborator

Well, here's the best result after the 4th epoch:

IIIT5k SVT IC13 IC15 SVTP CT80
0.9607 0.9351 0.9567 0.8406 0.8853 0.9028

It's even better than what the original paper have claimed. I feel the model is good enough for now, and I will continue to wrap it up and publish this model soon. Good job!

@2793145003
Copy link
Contributor Author

好耶!感谢大佬的review和指点!

Copy link
Collaborator

@gaotongxiao gaotongxiao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final code style pass, just a bit of refactoring. I'll push a new readme and ocr.py to this PR soon.
BTW, Github now supports applying multiple suggestions in a single commit :)

mmocr/models/textrecog/backbones/shallow_cnn.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/backbones/shallow_cnn.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
mmocr/models/textrecog/layers/transformer_layer.py Outdated Show resolved Hide resolved
@gaotongxiao gaotongxiao requested a review from Harold-lkk August 12, 2021 05:10
@gaotongxiao
Copy link
Collaborator

@innerlee @cuhk-hbsun Any general comments? If not, it will be merged tomorrow

@open-mmlab open-mmlab deleted a comment from 2793145003 Aug 19, 2021
@gaotongxiao gaotongxiao merged commit 8f377f2 into open-mmlab:main Aug 19, 2021
@2793145003 2793145003 deleted the satrn branch August 20, 2021 03:05
gaotongxiao added a commit to gaotongxiao/mmocr that referenced this pull request Jul 15, 2022
* Add SATRN

* Create satrn_small_academic.py

* Update README.md

* change config name

* Update mmocr/models/textrecog/backbones/shallow_cnn.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update configs/textrecog/satrn/satrn_academic.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update configs/textrecog/satrn/satrn_small.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update shallow_cnn.py

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update test_ocr_encoder.py

* change keep_aspect_ratio=False

* Update transformer_layer.py

* Update configs/textrecog/satrn/satrn_small.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update configs/textrecog/satrn/satrn_academic.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update transformer_layer.py

* Apply suggestions from code review

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update transformer_layer.py

* update satrn readme

* add satrn to ocr.py

* add satrn_sm and fix configs

* add a test for config

* add copyright info

* use mmocr registry

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>
gaotongxiao added a commit to gaotongxiao/mmocr that referenced this pull request Jul 15, 2022
* Add SATRN

* Create satrn_small_academic.py

* Update README.md

* change config name

* Update mmocr/models/textrecog/backbones/shallow_cnn.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update configs/textrecog/satrn/satrn_academic.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update configs/textrecog/satrn/satrn_small.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update shallow_cnn.py

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update test_ocr_encoder.py

* change keep_aspect_ratio=False

* Update transformer_layer.py

* Update configs/textrecog/satrn/satrn_small.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update configs/textrecog/satrn/satrn_academic.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update mmocr/models/textrecog/layers/transformer_layer.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update transformer_layer.py

* Apply suggestions from code review

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

* Update transformer_layer.py

* update satrn readme

* add satrn to ocr.py

* add satrn_sm and fix configs

* add a test for config

* add copyright info

* use mmocr registry

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants