mirror of
https://github.com/open-mmlab/mmocr.git
synced 2025-06-03 21:54:47 +08:00
* 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>
50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
# Copyright (c) OpenMMLab. All rights reserved.
|
|
import pytest
|
|
import torch
|
|
|
|
from mmocr.models.textrecog.backbones import (ResNet31OCR, ShallowCNN,
|
|
VeryDeepVgg)
|
|
|
|
|
|
def test_resnet31_ocr_backbone():
|
|
"""Test resnet backbone."""
|
|
with pytest.raises(AssertionError):
|
|
ResNet31OCR(2.5)
|
|
|
|
with pytest.raises(AssertionError):
|
|
ResNet31OCR(3, layers=5)
|
|
|
|
with pytest.raises(AssertionError):
|
|
ResNet31OCR(3, channels=5)
|
|
|
|
# Test ResNet18 forward
|
|
model = ResNet31OCR()
|
|
model.init_weights()
|
|
model.train()
|
|
|
|
imgs = torch.randn(1, 3, 32, 160)
|
|
feat = model(imgs)
|
|
assert feat.shape == torch.Size([1, 512, 4, 40])
|
|
|
|
|
|
def test_vgg_deep_vgg_ocr_backbone():
|
|
|
|
model = VeryDeepVgg()
|
|
model.init_weights()
|
|
model.train()
|
|
|
|
imgs = torch.randn(1, 3, 32, 160)
|
|
feats = model(imgs)
|
|
assert feats.shape == torch.Size([1, 512, 1, 41])
|
|
|
|
|
|
def test_shallow_cnn_ocr_backbone():
|
|
|
|
model = ShallowCNN()
|
|
model.init_weights()
|
|
model.train()
|
|
|
|
imgs = torch.randn(1, 1, 32, 100)
|
|
feat = model(imgs)
|
|
assert feat.shape == torch.Size([1, 512, 8, 25])
|