craft-detector 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ *.pyc
2
+ *.swp
3
+ *.pkl
4
+ *.pth
5
+ result*
6
+ weights*
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2019-present NAVER Corp.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.4
2
+ Name: craft-detector
3
+ Version: 0.2.1
4
+ Summary: Python package for Official implementation of Character Region Awareness for Text Detection (CRAFT)
5
+ Author-email: "Clova AI Research, NAVER Corp." <youngmin.baek@navercorp.com>
6
+ Maintainer-email: Won-Kyu Park <wkpark@gmail.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Keywords: craft,deep-learning,machine-learning,ml,pytorch,text,text-detection
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Education
16
+ Classifier: Topic :: Scientific/Engineering
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
19
+ Classifier: Topic :: Software Development :: Libraries
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: opencv-python>=4.10.0
23
+ Requires-Dist: scikit-image>=0.25.1
24
+ Requires-Dist: scipy>=1.14.0
25
+ Requires-Dist: torch>=2.1.2
26
+ Requires-Dist: torchvision>=0.17.2
27
+ Description-Content-Type: text/markdown
28
+
29
+ ## CRAFT: Character-Region Awareness For Text detection
30
+ Official Pytorch implementation of CRAFT text detector | [Paper](https://arxiv.org/abs/1904.01941) | [Pretrained Model](https://drive.google.com/open?id=1Jk4eGD7crsqCCg9C9VjCLkMN3ze8kutZ) | [Supplementary](https://youtu.be/HI8MzpY8KMI)
31
+
32
+ **[Youngmin Baek](mailto:youngmin.baek@navercorp.com), Bado Lee, Dongyoon Han, Sangdoo Yun, Hwalsuk Lee.**
33
+
34
+ Clova AI Research, NAVER Corp.
35
+
36
+ ### Sample Results
37
+
38
+ ### Overview
39
+ PyTorch implementation for CRAFT text detector that effectively detect text area by exploring each character region and affinity between characters. The bounding box of texts are obtained by simply finding minimum bounding rectangles on binary map after thresholding character region and affinity scores.
40
+
41
+ <img width="1000" alt="teaser" src="./figures/craft_example.gif">
42
+
43
+ ## Updates
44
+ **13 Jun, 2019**: Initial update
45
+ **20 Jul, 2019**: Added post-processing for polygon result
46
+ **28 Sep, 2019**: Added the trained model on IC15 and the link refiner
47
+
48
+
49
+ ## Getting started
50
+ ### Install dependencies
51
+ #### Requirements
52
+ - PyTorch>=2.1.0
53
+ - torchvision>=0.17.2
54
+ - opencv-python>=4.10.0
55
+ - check requiremtns.txt
56
+ ```
57
+ pip install -r requirements.txt
58
+ ```
59
+
60
+ ### Training
61
+ The code for training is not included in this repository, and we cannot release the full training code for IP reason.
62
+
63
+
64
+ ### Test instruction using pretrained model
65
+ - Download the trained models
66
+
67
+ *Model name* | *Used datasets* | *Languages* | *Purpose* | *Model Link* |
68
+ | :--- | :--- | :--- | :--- | :--- |
69
+ General | SynthText, IC13, IC17 | Eng + MLT | For general purpose | [Click](https://drive.google.com/open?id=1Jk4eGD7crsqCCg9C9VjCLkMN3ze8kutZ)
70
+ IC15 | SynthText, IC15 | Eng | For IC15 only | [Click](https://drive.google.com/open?id=1i2R7UIUqmkUtF0jv_3MXTqmQ_9wuAnLf)
71
+ LinkRefiner | CTW1500 | - | Used with the General Model | [Click](https://drive.google.com/open?id=1XSaFwBkOaFOdtk4Ane3DFyJGPRw6v5bO)
72
+
73
+ * Run with pretrained model
74
+ ``` (with python 3.7)
75
+ python test.py --trained_model=[weightfile] --test_folder=[folder path to test images]
76
+ ```
77
+
78
+ The result image and socre maps will be saved to `./result` by default.
79
+
80
+ ### Arguments
81
+ * `--trained_model`: pretrained model
82
+ * `--text_threshold`: text confidence threshold
83
+ * `--low_text`: text low-bound score
84
+ * `--link_threshold`: link confidence threshold
85
+ * `--gpu`: use GPU for inference (default:False)
86
+ * `--canvas_size`: max image size for inference
87
+ * `--mag_ratio`: image magnification ratio
88
+ * `--poly`: enable polygon type result
89
+ * `--show_time`: show processing time
90
+ * `--test_folder`: folder path to input images
91
+ * `--refine`: use link refiner for sentense-level dataset
92
+ * `--refiner_model`: pretrained refiner model
93
+
94
+
95
+ ## Links
96
+ - Repo of recognition : https://github.com/clovaai/deep-text-recognition-benchmark
97
+
98
+ ## Citation
99
+ ```
100
+ @inproceedings{baek2019character,
101
+ title={Character Region Awareness for Text Detection},
102
+ author={Baek, Youngmin and Lee, Bado and Han, Dongyoon and Yun, Sangdoo and Lee, Hwalsuk},
103
+ booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},
104
+ pages={9365--9374},
105
+ year={2019}
106
+ }
107
+ ```
108
+
109
+ ## License
110
+ ```
111
+ Copyright (c) 2019-present NAVER Corp.
112
+
113
+ Permission is hereby granted, free of charge, to any person obtaining a copy
114
+ of this software and associated documentation files (the "Software"), to deal
115
+ in the Software without restriction, including without limitation the rights
116
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
117
+ copies of the Software, and to permit persons to whom the Software is
118
+ furnished to do so, subject to the following conditions:
119
+
120
+ The above copyright notice and this permission notice shall be included in
121
+ all copies or substantial portions of the Software.
122
+
123
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
124
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
125
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
126
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
127
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
128
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
129
+ THE SOFTWARE.
130
+ ```
@@ -0,0 +1,102 @@
1
+ ## CRAFT: Character-Region Awareness For Text detection
2
+ Official Pytorch implementation of CRAFT text detector | [Paper](https://arxiv.org/abs/1904.01941) | [Pretrained Model](https://drive.google.com/open?id=1Jk4eGD7crsqCCg9C9VjCLkMN3ze8kutZ) | [Supplementary](https://youtu.be/HI8MzpY8KMI)
3
+
4
+ **[Youngmin Baek](mailto:youngmin.baek@navercorp.com), Bado Lee, Dongyoon Han, Sangdoo Yun, Hwalsuk Lee.**
5
+
6
+ Clova AI Research, NAVER Corp.
7
+
8
+ ### Sample Results
9
+
10
+ ### Overview
11
+ PyTorch implementation for CRAFT text detector that effectively detect text area by exploring each character region and affinity between characters. The bounding box of texts are obtained by simply finding minimum bounding rectangles on binary map after thresholding character region and affinity scores.
12
+
13
+ <img width="1000" alt="teaser" src="./figures/craft_example.gif">
14
+
15
+ ## Updates
16
+ **13 Jun, 2019**: Initial update
17
+ **20 Jul, 2019**: Added post-processing for polygon result
18
+ **28 Sep, 2019**: Added the trained model on IC15 and the link refiner
19
+
20
+
21
+ ## Getting started
22
+ ### Install dependencies
23
+ #### Requirements
24
+ - PyTorch>=2.1.0
25
+ - torchvision>=0.17.2
26
+ - opencv-python>=4.10.0
27
+ - check requiremtns.txt
28
+ ```
29
+ pip install -r requirements.txt
30
+ ```
31
+
32
+ ### Training
33
+ The code for training is not included in this repository, and we cannot release the full training code for IP reason.
34
+
35
+
36
+ ### Test instruction using pretrained model
37
+ - Download the trained models
38
+
39
+ *Model name* | *Used datasets* | *Languages* | *Purpose* | *Model Link* |
40
+ | :--- | :--- | :--- | :--- | :--- |
41
+ General | SynthText, IC13, IC17 | Eng + MLT | For general purpose | [Click](https://drive.google.com/open?id=1Jk4eGD7crsqCCg9C9VjCLkMN3ze8kutZ)
42
+ IC15 | SynthText, IC15 | Eng | For IC15 only | [Click](https://drive.google.com/open?id=1i2R7UIUqmkUtF0jv_3MXTqmQ_9wuAnLf)
43
+ LinkRefiner | CTW1500 | - | Used with the General Model | [Click](https://drive.google.com/open?id=1XSaFwBkOaFOdtk4Ane3DFyJGPRw6v5bO)
44
+
45
+ * Run with pretrained model
46
+ ``` (with python 3.7)
47
+ python test.py --trained_model=[weightfile] --test_folder=[folder path to test images]
48
+ ```
49
+
50
+ The result image and socre maps will be saved to `./result` by default.
51
+
52
+ ### Arguments
53
+ * `--trained_model`: pretrained model
54
+ * `--text_threshold`: text confidence threshold
55
+ * `--low_text`: text low-bound score
56
+ * `--link_threshold`: link confidence threshold
57
+ * `--gpu`: use GPU for inference (default:False)
58
+ * `--canvas_size`: max image size for inference
59
+ * `--mag_ratio`: image magnification ratio
60
+ * `--poly`: enable polygon type result
61
+ * `--show_time`: show processing time
62
+ * `--test_folder`: folder path to input images
63
+ * `--refine`: use link refiner for sentense-level dataset
64
+ * `--refiner_model`: pretrained refiner model
65
+
66
+
67
+ ## Links
68
+ - Repo of recognition : https://github.com/clovaai/deep-text-recognition-benchmark
69
+
70
+ ## Citation
71
+ ```
72
+ @inproceedings{baek2019character,
73
+ title={Character Region Awareness for Text Detection},
74
+ author={Baek, Youngmin and Lee, Bado and Han, Dongyoon and Yun, Sangdoo and Lee, Hwalsuk},
75
+ booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},
76
+ pages={9365--9374},
77
+ year={2019}
78
+ }
79
+ ```
80
+
81
+ ## License
82
+ ```
83
+ Copyright (c) 2019-present NAVER Corp.
84
+
85
+ Permission is hereby granted, free of charge, to any person obtaining a copy
86
+ of this software and associated documentation files (the "Software"), to deal
87
+ in the Software without restriction, including without limitation the rights
88
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
89
+ copies of the Software, and to permit persons to whom the Software is
90
+ furnished to do so, subject to the following conditions:
91
+
92
+ The above copyright notice and this permission notice shall be included in
93
+ all copies or substantial portions of the Software.
94
+
95
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
96
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
97
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
98
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
99
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
100
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
101
+ THE SOFTWARE.
102
+ ```
@@ -0,0 +1,3 @@
1
+ from .craft import *
2
+
3
+ __version__ = '0.2.0'
File without changes
@@ -0,0 +1,75 @@
1
+ from collections import namedtuple
2
+
3
+ import torch
4
+ import torch.nn as nn
5
+ import torch.nn.init as init
6
+ from torchvision import models
7
+ from torchvision.models.vgg import VGG16_BN_Weights
8
+
9
+ def init_weights(modules):
10
+ for m in modules:
11
+ if isinstance(m, nn.Conv2d):
12
+ init.xavier_uniform_(m.weight.data)
13
+ if m.bias is not None:
14
+ m.bias.data.zero_()
15
+ elif isinstance(m, nn.BatchNorm2d):
16
+ m.weight.data.fill_(1)
17
+ m.bias.data.zero_()
18
+ elif isinstance(m, nn.Linear):
19
+ m.weight.data.normal_(0, 0.01)
20
+ m.bias.data.zero_()
21
+
22
+ class vgg16_bn(torch.nn.Module):
23
+ def __init__(self, pretrained=True, freeze=True):
24
+ super(vgg16_bn, self).__init__()
25
+ # Use the weights parameter based on the pretrained flag
26
+ weights = VGG16_BN_Weights.IMAGENET1K_V1 if pretrained else None
27
+ vgg_pretrained_features = models.vgg16_bn(weights=weights).features
28
+
29
+ self.slice1 = torch.nn.Sequential()
30
+ self.slice2 = torch.nn.Sequential()
31
+ self.slice3 = torch.nn.Sequential()
32
+ self.slice4 = torch.nn.Sequential()
33
+ self.slice5 = torch.nn.Sequential()
34
+ for x in range(12): # conv2_2
35
+ self.slice1.add_module(str(x), vgg_pretrained_features[x])
36
+ for x in range(12, 19): # conv3_3
37
+ self.slice2.add_module(str(x), vgg_pretrained_features[x])
38
+ for x in range(19, 29): # conv4_3
39
+ self.slice3.add_module(str(x), vgg_pretrained_features[x])
40
+ for x in range(29, 39): # conv5_3
41
+ self.slice4.add_module(str(x), vgg_pretrained_features[x])
42
+
43
+ # fc6, fc7 without atrous conv
44
+ self.slice5 = torch.nn.Sequential(
45
+ nn.MaxPool2d(kernel_size=3, stride=1, padding=1),
46
+ nn.Conv2d(512, 1024, kernel_size=3, padding=6, dilation=6),
47
+ nn.Conv2d(1024, 1024, kernel_size=1)
48
+ )
49
+
50
+ if not pretrained:
51
+ init_weights(self.slice1.modules())
52
+ init_weights(self.slice2.modules())
53
+ init_weights(self.slice3.modules())
54
+ init_weights(self.slice4.modules())
55
+
56
+ init_weights(self.slice5.modules()) # no pretrained model for fc6 and fc7
57
+
58
+ if freeze:
59
+ for param in self.slice1.parameters(): # only first conv
60
+ param.requires_grad= False
61
+
62
+ def forward(self, X):
63
+ h = self.slice1(X)
64
+ h_relu2_2 = h
65
+ h = self.slice2(h)
66
+ h_relu3_2 = h
67
+ h = self.slice3(h)
68
+ h_relu4_3 = h
69
+ h = self.slice4(h)
70
+ h_relu5_3 = h
71
+ h = self.slice5(h)
72
+ h_fc7 = h
73
+ vgg_outputs = namedtuple("VggOutputs", ['fc7', 'relu5_3', 'relu4_3', 'relu3_2', 'relu2_2'])
74
+ out = vgg_outputs(h_fc7, h_relu5_3, h_relu4_3, h_relu3_2, h_relu2_2)
75
+ return out
@@ -0,0 +1,83 @@
1
+ """
2
+ Copyright (c) 2019-present NAVER Corp.
3
+ MIT License
4
+ """
5
+
6
+ # -*- coding: utf-8 -*-
7
+ import torch
8
+ import torch.nn as nn
9
+ import torch.nn.functional as F
10
+
11
+ from .basenet.vgg16_bn import vgg16_bn, init_weights
12
+
13
+ class double_conv(nn.Module):
14
+ def __init__(self, in_ch, mid_ch, out_ch):
15
+ super(double_conv, self).__init__()
16
+ self.conv = nn.Sequential(
17
+ nn.Conv2d(in_ch + mid_ch, mid_ch, kernel_size=1),
18
+ nn.BatchNorm2d(mid_ch),
19
+ nn.ReLU(inplace=True),
20
+ nn.Conv2d(mid_ch, out_ch, kernel_size=3, padding=1),
21
+ nn.BatchNorm2d(out_ch),
22
+ nn.ReLU(inplace=True)
23
+ )
24
+
25
+ def forward(self, x):
26
+ x = self.conv(x)
27
+ return x
28
+
29
+
30
+ class CRAFT(nn.Module):
31
+ def __init__(self, pretrained=False, freeze=False):
32
+ super(CRAFT, self).__init__()
33
+
34
+ """ Base network """
35
+ self.basenet = vgg16_bn(pretrained, freeze)
36
+
37
+ """ U network """
38
+ self.upconv1 = double_conv(1024, 512, 256)
39
+ self.upconv2 = double_conv(512, 256, 128)
40
+ self.upconv3 = double_conv(256, 128, 64)
41
+ self.upconv4 = double_conv(128, 64, 32)
42
+
43
+ num_class = 2
44
+ self.conv_cls = nn.Sequential(
45
+ nn.Conv2d(32, 32, kernel_size=3, padding=1), nn.ReLU(inplace=True),
46
+ nn.Conv2d(32, 32, kernel_size=3, padding=1), nn.ReLU(inplace=True),
47
+ nn.Conv2d(32, 16, kernel_size=3, padding=1), nn.ReLU(inplace=True),
48
+ nn.Conv2d(16, 16, kernel_size=1), nn.ReLU(inplace=True),
49
+ nn.Conv2d(16, num_class, kernel_size=1),
50
+ )
51
+
52
+ init_weights(self.upconv1.modules())
53
+ init_weights(self.upconv2.modules())
54
+ init_weights(self.upconv3.modules())
55
+ init_weights(self.upconv4.modules())
56
+ init_weights(self.conv_cls.modules())
57
+
58
+ def _forward_impl(self, x):
59
+ """ Base network """
60
+ sources = self.basenet(x)
61
+
62
+ """ U network """
63
+ y = torch.cat([sources[0], sources[1]], dim=1)
64
+ y = self.upconv1(y)
65
+
66
+ y = F.interpolate(y, size=sources[2].size()[2:], mode='bilinear', align_corners=False)
67
+ y = torch.cat([y, sources[2]], dim=1)
68
+ y = self.upconv2(y)
69
+
70
+ y = F.interpolate(y, size=sources[3].size()[2:], mode='bilinear', align_corners=False)
71
+ y = torch.cat([y, sources[3]], dim=1)
72
+ y = self.upconv3(y)
73
+
74
+ y = F.interpolate(y, size=sources[4].size()[2:], mode='bilinear', align_corners=False)
75
+ y = torch.cat([y, sources[4]], dim=1)
76
+ feature = self.upconv4(y)
77
+
78
+ y = self.conv_cls(feature)
79
+
80
+ return y.permute(0,2,3,1), feature
81
+
82
+ def forward(self, x):
83
+ return self._forward_impl(x)