Spaces:
Running
Running
Delete synthdog
Browse files- synthdog/README.md +0 -63
- synthdog/config_en.yaml +0 -119
- synthdog/config_ja.yaml +0 -119
- synthdog/config_ko.yaml +0 -119
- synthdog/config_zh.yaml +0 -119
- synthdog/elements/__init__.py +0 -12
- synthdog/elements/background.py +0 -24
- synthdog/elements/content.py +0 -118
- synthdog/elements/document.py +0 -65
- synthdog/elements/paper.py +0 -17
- synthdog/elements/textbox.py +0 -43
- synthdog/layouts/__init__.py +0 -9
- synthdog/layouts/grid.py +0 -68
- synthdog/layouts/grid_stack.py +0 -74
- synthdog/resources/background/bedroom_83.jpg +0 -0
- synthdog/resources/background/bob+dylan_83.jpg +0 -0
- synthdog/resources/background/coffee_122.jpg +0 -0
- synthdog/resources/background/coffee_18.jpeg +0 -3
- synthdog/resources/background/crater_141.jpg +0 -3
- synthdog/resources/background/cream_124.jpg +0 -3
- synthdog/resources/background/eagle_110.jpg +0 -0
- synthdog/resources/background/farm_25.jpg +0 -0
- synthdog/resources/background/hiking_18.jpg +0 -0
- synthdog/resources/corpus/enwiki.txt +0 -0
- synthdog/resources/corpus/jawiki.txt +0 -0
- synthdog/resources/corpus/kowiki.txt +0 -0
- synthdog/resources/corpus/zhwiki.txt +0 -0
- synthdog/resources/font/en/NotoSans-Regular.ttf +0 -0
- synthdog/resources/font/en/NotoSerif-Regular.ttf +0 -0
- synthdog/resources/font/ja/NotoSansJP-Regular.otf +0 -3
- synthdog/resources/font/ja/NotoSerifJP-Regular.otf +0 -3
- synthdog/resources/font/ko/NotoSansKR-Regular.otf +0 -3
- synthdog/resources/font/ko/NotoSerifKR-Regular.otf +0 -3
- synthdog/resources/font/zh/NotoSansSC-Regular.otf +0 -3
- synthdog/resources/font/zh/NotoSerifSC-Regular.otf +0 -3
- synthdog/resources/paper/paper_1.jpg +0 -3
- synthdog/resources/paper/paper_2.jpg +0 -3
- synthdog/resources/paper/paper_3.jpg +0 -3
- synthdog/resources/paper/paper_4.jpg +0 -3
- synthdog/resources/paper/paper_5.jpg +0 -3
- synthdog/resources/paper/paper_6.jpg +0 -3
- synthdog/template.py +0 -130
synthdog/README.md
DELETED
@@ -1,63 +0,0 @@
|
|
1 |
-
# SynthDoG 🐶: Synthetic Document Generator
|
2 |
-
|
3 |
-
SynthDoG is synthetic document generator for visual document understanding (VDU).
|
4 |
-
|
5 |
-
![image](../misc/sample_synthdog.png)
|
6 |
-
|
7 |
-
## Prerequisites
|
8 |
-
|
9 |
-
- python>=3.6
|
10 |
-
- [synthtiger](https://github.com/clovaai/synthtiger) (`pip install synthtiger`)
|
11 |
-
|
12 |
-
## Usage
|
13 |
-
|
14 |
-
```bash
|
15 |
-
# Set environment variable (for macOS)
|
16 |
-
$ export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
|
17 |
-
|
18 |
-
synthtiger -o ./outputs/SynthDoG_en -c 50 -w 4 -v template.py SynthDoG config_en.yaml
|
19 |
-
|
20 |
-
{'config': 'config_en.yaml',
|
21 |
-
'count': 50,
|
22 |
-
'name': 'SynthDoG',
|
23 |
-
'output': './outputs/SynthDoG_en',
|
24 |
-
'script': 'template.py',
|
25 |
-
'verbose': True,
|
26 |
-
'worker': 4}
|
27 |
-
{'aspect_ratio': [1, 2],
|
28 |
-
.
|
29 |
-
.
|
30 |
-
'quality': [50, 95],
|
31 |
-
'short_size': [720, 1024]}
|
32 |
-
Generated 1 data (task 3)
|
33 |
-
Generated 2 data (task 0)
|
34 |
-
Generated 3 data (task 1)
|
35 |
-
.
|
36 |
-
.
|
37 |
-
Generated 49 data (task 48)
|
38 |
-
Generated 50 data (task 49)
|
39 |
-
46.32 seconds elapsed
|
40 |
-
```
|
41 |
-
|
42 |
-
Some important arguments:
|
43 |
-
|
44 |
-
- `-o` : directory path to save data.
|
45 |
-
- `-c` : number of data to generate.
|
46 |
-
- `-w` : number of workers.
|
47 |
-
- `-s` : random seed.
|
48 |
-
- `-v` : print error messages.
|
49 |
-
|
50 |
-
To generate ECJK samples:
|
51 |
-
```bash
|
52 |
-
# english
|
53 |
-
synthtiger -o {dataset_path} -c {num_of_data} -w {num_of_workers} -v template.py SynthDoG config_en.yaml
|
54 |
-
|
55 |
-
# chinese
|
56 |
-
synthtiger -o {dataset_path} -c {num_of_data} -w {num_of_workers} -v template.py SynthDoG config_zh.yaml
|
57 |
-
|
58 |
-
# japanese
|
59 |
-
synthtiger -o {dataset_path} -c {num_of_data} -w {num_of_workers} -v template.py SynthDoG config_ja.yaml
|
60 |
-
|
61 |
-
# korean
|
62 |
-
synthtiger -o {dataset_path} -c {num_of_data} -w {num_of_workers} -v template.py SynthDoG config_ko.yaml
|
63 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synthdog/config_en.yaml
DELETED
@@ -1,119 +0,0 @@
|
|
1 |
-
quality: [50, 95]
|
2 |
-
landscape: 0.5
|
3 |
-
short_size: [720, 1024]
|
4 |
-
aspect_ratio: [1, 2]
|
5 |
-
|
6 |
-
background:
|
7 |
-
image:
|
8 |
-
paths: [resources/background]
|
9 |
-
weights: [1]
|
10 |
-
|
11 |
-
effect:
|
12 |
-
args:
|
13 |
-
# gaussian blur
|
14 |
-
- prob: 1
|
15 |
-
args:
|
16 |
-
sigma: [0, 10]
|
17 |
-
|
18 |
-
document:
|
19 |
-
fullscreen: 0.5
|
20 |
-
landscape: 0.5
|
21 |
-
short_size: [480, 1024]
|
22 |
-
aspect_ratio: [1, 2]
|
23 |
-
|
24 |
-
paper:
|
25 |
-
image:
|
26 |
-
paths: [resources/paper]
|
27 |
-
weights: [1]
|
28 |
-
alpha: [0, 0.2]
|
29 |
-
grayscale: 1
|
30 |
-
crop: 1
|
31 |
-
|
32 |
-
content:
|
33 |
-
margin: [0, 0.1]
|
34 |
-
text:
|
35 |
-
path: resources/corpus/enwiki.txt
|
36 |
-
font:
|
37 |
-
paths: [resources/font/en]
|
38 |
-
weights: [1]
|
39 |
-
bold: 0
|
40 |
-
layout:
|
41 |
-
text_scale: [0.0334, 0.1]
|
42 |
-
max_row: 10
|
43 |
-
max_col: 3
|
44 |
-
fill: [0.5, 1]
|
45 |
-
full: 0.1
|
46 |
-
align: [left, right, center]
|
47 |
-
stack_spacing: [0.0334, 0.0334]
|
48 |
-
stack_fill: [0.5, 1]
|
49 |
-
stack_full: 0.1
|
50 |
-
textbox:
|
51 |
-
fill: [0.5, 1]
|
52 |
-
textbox_color:
|
53 |
-
prob: 0.2
|
54 |
-
args:
|
55 |
-
gray: [0, 64]
|
56 |
-
colorize: 1
|
57 |
-
content_color:
|
58 |
-
prob: 0.2
|
59 |
-
args:
|
60 |
-
gray: [0, 64]
|
61 |
-
colorize: 1
|
62 |
-
|
63 |
-
effect:
|
64 |
-
args:
|
65 |
-
# elastic distortion
|
66 |
-
- prob: 1
|
67 |
-
args:
|
68 |
-
alpha: [0, 1]
|
69 |
-
sigma: [0, 0.5]
|
70 |
-
# gaussian noise
|
71 |
-
- prob: 1
|
72 |
-
args:
|
73 |
-
scale: [0, 8]
|
74 |
-
per_channel: 0
|
75 |
-
# perspective
|
76 |
-
- prob: 1
|
77 |
-
args:
|
78 |
-
weights: [750, 50, 50, 25, 25, 25, 25, 50]
|
79 |
-
args:
|
80 |
-
- percents: [[0.75, 1], [0.75, 1], [0.75, 1], [0.75, 1]]
|
81 |
-
- percents: [[0.75, 1], [1, 1], [0.75, 1], [1, 1]]
|
82 |
-
- percents: [[1, 1], [0.75, 1], [1, 1], [0.75, 1]]
|
83 |
-
- percents: [[0.75, 1], [1, 1], [1, 1], [1, 1]]
|
84 |
-
- percents: [[1, 1], [0.75, 1], [1, 1], [1, 1]]
|
85 |
-
- percents: [[1, 1], [1, 1], [0.75, 1], [1, 1]]
|
86 |
-
- percents: [[1, 1], [1, 1], [1, 1], [0.75, 1]]
|
87 |
-
- percents: [[1, 1], [1, 1], [1, 1], [1, 1]]
|
88 |
-
|
89 |
-
effect:
|
90 |
-
args:
|
91 |
-
# color
|
92 |
-
- prob: 0.2
|
93 |
-
args:
|
94 |
-
rgb: [[0, 255], [0, 255], [0, 255]]
|
95 |
-
alpha: [0, 0.2]
|
96 |
-
# shadow
|
97 |
-
- prob: 1
|
98 |
-
args:
|
99 |
-
intensity: [0, 160]
|
100 |
-
amount: [0, 1]
|
101 |
-
smoothing: [0.5, 1]
|
102 |
-
bidirectional: 0
|
103 |
-
# contrast
|
104 |
-
- prob: 1
|
105 |
-
args:
|
106 |
-
alpha: [1, 1.5]
|
107 |
-
# brightness
|
108 |
-
- prob: 1
|
109 |
-
args:
|
110 |
-
beta: [-48, 0]
|
111 |
-
# motion blur
|
112 |
-
- prob: 0.5
|
113 |
-
args:
|
114 |
-
k: [3, 5]
|
115 |
-
angle: [0, 360]
|
116 |
-
# gaussian blur
|
117 |
-
- prob: 1
|
118 |
-
args:
|
119 |
-
sigma: [0, 1.5]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synthdog/config_ja.yaml
DELETED
@@ -1,119 +0,0 @@
|
|
1 |
-
quality: [50, 95]
|
2 |
-
landscape: 0.5
|
3 |
-
short_size: [720, 1024]
|
4 |
-
aspect_ratio: [1, 2]
|
5 |
-
|
6 |
-
background:
|
7 |
-
image:
|
8 |
-
paths: [resources/background]
|
9 |
-
weights: [1]
|
10 |
-
|
11 |
-
effect:
|
12 |
-
args:
|
13 |
-
# gaussian blur
|
14 |
-
- prob: 1
|
15 |
-
args:
|
16 |
-
sigma: [0, 10]
|
17 |
-
|
18 |
-
document:
|
19 |
-
fullscreen: 0.5
|
20 |
-
landscape: 0.5
|
21 |
-
short_size: [480, 1024]
|
22 |
-
aspect_ratio: [1, 2]
|
23 |
-
|
24 |
-
paper:
|
25 |
-
image:
|
26 |
-
paths: [resources/paper]
|
27 |
-
weights: [1]
|
28 |
-
alpha: [0, 0.2]
|
29 |
-
grayscale: 1
|
30 |
-
crop: 1
|
31 |
-
|
32 |
-
content:
|
33 |
-
margin: [0, 0.1]
|
34 |
-
text:
|
35 |
-
path: resources/corpus/jawiki.txt
|
36 |
-
font:
|
37 |
-
paths: [resources/font/ja]
|
38 |
-
weights: [1]
|
39 |
-
bold: 0
|
40 |
-
layout:
|
41 |
-
text_scale: [0.0334, 0.1]
|
42 |
-
max_row: 10
|
43 |
-
max_col: 3
|
44 |
-
fill: [0.5, 1]
|
45 |
-
full: 0.1
|
46 |
-
align: [left, right, center]
|
47 |
-
stack_spacing: [0.0334, 0.0334]
|
48 |
-
stack_fill: [0.5, 1]
|
49 |
-
stack_full: 0.1
|
50 |
-
textbox:
|
51 |
-
fill: [0.5, 1]
|
52 |
-
textbox_color:
|
53 |
-
prob: 0.2
|
54 |
-
args:
|
55 |
-
gray: [0, 64]
|
56 |
-
colorize: 1
|
57 |
-
content_color:
|
58 |
-
prob: 0.2
|
59 |
-
args:
|
60 |
-
gray: [0, 64]
|
61 |
-
colorize: 1
|
62 |
-
|
63 |
-
effect:
|
64 |
-
args:
|
65 |
-
# elastic distortion
|
66 |
-
- prob: 1
|
67 |
-
args:
|
68 |
-
alpha: [0, 1]
|
69 |
-
sigma: [0, 0.5]
|
70 |
-
# gaussian noise
|
71 |
-
- prob: 1
|
72 |
-
args:
|
73 |
-
scale: [0, 8]
|
74 |
-
per_channel: 0
|
75 |
-
# perspective
|
76 |
-
- prob: 1
|
77 |
-
args:
|
78 |
-
weights: [750, 50, 50, 25, 25, 25, 25, 50]
|
79 |
-
args:
|
80 |
-
- percents: [[0.75, 1], [0.75, 1], [0.75, 1], [0.75, 1]]
|
81 |
-
- percents: [[0.75, 1], [1, 1], [0.75, 1], [1, 1]]
|
82 |
-
- percents: [[1, 1], [0.75, 1], [1, 1], [0.75, 1]]
|
83 |
-
- percents: [[0.75, 1], [1, 1], [1, 1], [1, 1]]
|
84 |
-
- percents: [[1, 1], [0.75, 1], [1, 1], [1, 1]]
|
85 |
-
- percents: [[1, 1], [1, 1], [0.75, 1], [1, 1]]
|
86 |
-
- percents: [[1, 1], [1, 1], [1, 1], [0.75, 1]]
|
87 |
-
- percents: [[1, 1], [1, 1], [1, 1], [1, 1]]
|
88 |
-
|
89 |
-
effect:
|
90 |
-
args:
|
91 |
-
# color
|
92 |
-
- prob: 0.2
|
93 |
-
args:
|
94 |
-
rgb: [[0, 255], [0, 255], [0, 255]]
|
95 |
-
alpha: [0, 0.2]
|
96 |
-
# shadow
|
97 |
-
- prob: 1
|
98 |
-
args:
|
99 |
-
intensity: [0, 160]
|
100 |
-
amount: [0, 1]
|
101 |
-
smoothing: [0.5, 1]
|
102 |
-
bidirectional: 0
|
103 |
-
# contrast
|
104 |
-
- prob: 1
|
105 |
-
args:
|
106 |
-
alpha: [1, 1.5]
|
107 |
-
# brightness
|
108 |
-
- prob: 1
|
109 |
-
args:
|
110 |
-
beta: [-48, 0]
|
111 |
-
# motion blur
|
112 |
-
- prob: 0.5
|
113 |
-
args:
|
114 |
-
k: [3, 5]
|
115 |
-
angle: [0, 360]
|
116 |
-
# gaussian blur
|
117 |
-
- prob: 1
|
118 |
-
args:
|
119 |
-
sigma: [0, 1.5]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synthdog/config_ko.yaml
DELETED
@@ -1,119 +0,0 @@
|
|
1 |
-
quality: [50, 95]
|
2 |
-
landscape: 0.5
|
3 |
-
short_size: [720, 1024]
|
4 |
-
aspect_ratio: [1, 2]
|
5 |
-
|
6 |
-
background:
|
7 |
-
image:
|
8 |
-
paths: [resources/background]
|
9 |
-
weights: [1]
|
10 |
-
|
11 |
-
effect:
|
12 |
-
args:
|
13 |
-
# gaussian blur
|
14 |
-
- prob: 1
|
15 |
-
args:
|
16 |
-
sigma: [0, 10]
|
17 |
-
|
18 |
-
document:
|
19 |
-
fullscreen: 0.5
|
20 |
-
landscape: 0.5
|
21 |
-
short_size: [480, 1024]
|
22 |
-
aspect_ratio: [1, 2]
|
23 |
-
|
24 |
-
paper:
|
25 |
-
image:
|
26 |
-
paths: [resources/paper]
|
27 |
-
weights: [1]
|
28 |
-
alpha: [0, 0.2]
|
29 |
-
grayscale: 1
|
30 |
-
crop: 1
|
31 |
-
|
32 |
-
content:
|
33 |
-
margin: [0, 0.1]
|
34 |
-
text:
|
35 |
-
path: resources/corpus/kowiki.txt
|
36 |
-
font:
|
37 |
-
paths: [resources/font/ko]
|
38 |
-
weights: [1]
|
39 |
-
bold: 0
|
40 |
-
layout:
|
41 |
-
text_scale: [0.0334, 0.1]
|
42 |
-
max_row: 10
|
43 |
-
max_col: 3
|
44 |
-
fill: [0.5, 1]
|
45 |
-
full: 0.1
|
46 |
-
align: [left, right, center]
|
47 |
-
stack_spacing: [0.0334, 0.0334]
|
48 |
-
stack_fill: [0.5, 1]
|
49 |
-
stack_full: 0.1
|
50 |
-
textbox:
|
51 |
-
fill: [0.5, 1]
|
52 |
-
textbox_color:
|
53 |
-
prob: 0.2
|
54 |
-
args:
|
55 |
-
gray: [0, 64]
|
56 |
-
colorize: 1
|
57 |
-
content_color:
|
58 |
-
prob: 0.2
|
59 |
-
args:
|
60 |
-
gray: [0, 64]
|
61 |
-
colorize: 1
|
62 |
-
|
63 |
-
effect:
|
64 |
-
args:
|
65 |
-
# elastic distortion
|
66 |
-
- prob: 1
|
67 |
-
args:
|
68 |
-
alpha: [0, 1]
|
69 |
-
sigma: [0, 0.5]
|
70 |
-
# gaussian noise
|
71 |
-
- prob: 1
|
72 |
-
args:
|
73 |
-
scale: [0, 8]
|
74 |
-
per_channel: 0
|
75 |
-
# perspective
|
76 |
-
- prob: 1
|
77 |
-
args:
|
78 |
-
weights: [750, 50, 50, 25, 25, 25, 25, 50]
|
79 |
-
args:
|
80 |
-
- percents: [[0.75, 1], [0.75, 1], [0.75, 1], [0.75, 1]]
|
81 |
-
- percents: [[0.75, 1], [1, 1], [0.75, 1], [1, 1]]
|
82 |
-
- percents: [[1, 1], [0.75, 1], [1, 1], [0.75, 1]]
|
83 |
-
- percents: [[0.75, 1], [1, 1], [1, 1], [1, 1]]
|
84 |
-
- percents: [[1, 1], [0.75, 1], [1, 1], [1, 1]]
|
85 |
-
- percents: [[1, 1], [1, 1], [0.75, 1], [1, 1]]
|
86 |
-
- percents: [[1, 1], [1, 1], [1, 1], [0.75, 1]]
|
87 |
-
- percents: [[1, 1], [1, 1], [1, 1], [1, 1]]
|
88 |
-
|
89 |
-
effect:
|
90 |
-
args:
|
91 |
-
# color
|
92 |
-
- prob: 0.2
|
93 |
-
args:
|
94 |
-
rgb: [[0, 255], [0, 255], [0, 255]]
|
95 |
-
alpha: [0, 0.2]
|
96 |
-
# shadow
|
97 |
-
- prob: 1
|
98 |
-
args:
|
99 |
-
intensity: [0, 160]
|
100 |
-
amount: [0, 1]
|
101 |
-
smoothing: [0.5, 1]
|
102 |
-
bidirectional: 0
|
103 |
-
# contrast
|
104 |
-
- prob: 1
|
105 |
-
args:
|
106 |
-
alpha: [1, 1.5]
|
107 |
-
# brightness
|
108 |
-
- prob: 1
|
109 |
-
args:
|
110 |
-
beta: [-48, 0]
|
111 |
-
# motion blur
|
112 |
-
- prob: 0.5
|
113 |
-
args:
|
114 |
-
k: [3, 5]
|
115 |
-
angle: [0, 360]
|
116 |
-
# gaussian blur
|
117 |
-
- prob: 1
|
118 |
-
args:
|
119 |
-
sigma: [0, 1.5]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synthdog/config_zh.yaml
DELETED
@@ -1,119 +0,0 @@
|
|
1 |
-
quality: [50, 95]
|
2 |
-
landscape: 0.5
|
3 |
-
short_size: [720, 1024]
|
4 |
-
aspect_ratio: [1, 2]
|
5 |
-
|
6 |
-
background:
|
7 |
-
image:
|
8 |
-
paths: [resources/background]
|
9 |
-
weights: [1]
|
10 |
-
|
11 |
-
effect:
|
12 |
-
args:
|
13 |
-
# gaussian blur
|
14 |
-
- prob: 1
|
15 |
-
args:
|
16 |
-
sigma: [0, 10]
|
17 |
-
|
18 |
-
document:
|
19 |
-
fullscreen: 0.5
|
20 |
-
landscape: 0.5
|
21 |
-
short_size: [480, 1024]
|
22 |
-
aspect_ratio: [1, 2]
|
23 |
-
|
24 |
-
paper:
|
25 |
-
image:
|
26 |
-
paths: [resources/paper]
|
27 |
-
weights: [1]
|
28 |
-
alpha: [0, 0.2]
|
29 |
-
grayscale: 1
|
30 |
-
crop: 1
|
31 |
-
|
32 |
-
content:
|
33 |
-
margin: [0, 0.1]
|
34 |
-
text:
|
35 |
-
path: resources/corpus/zhwiki.txt
|
36 |
-
font:
|
37 |
-
paths: [resources/font/zh]
|
38 |
-
weights: [1]
|
39 |
-
bold: 0
|
40 |
-
layout:
|
41 |
-
text_scale: [0.0334, 0.1]
|
42 |
-
max_row: 10
|
43 |
-
max_col: 3
|
44 |
-
fill: [0.5, 1]
|
45 |
-
full: 0.1
|
46 |
-
align: [left, right, center]
|
47 |
-
stack_spacing: [0.0334, 0.0334]
|
48 |
-
stack_fill: [0.5, 1]
|
49 |
-
stack_full: 0.1
|
50 |
-
textbox:
|
51 |
-
fill: [0.5, 1]
|
52 |
-
textbox_color:
|
53 |
-
prob: 0.2
|
54 |
-
args:
|
55 |
-
gray: [0, 64]
|
56 |
-
colorize: 1
|
57 |
-
content_color:
|
58 |
-
prob: 0.2
|
59 |
-
args:
|
60 |
-
gray: [0, 64]
|
61 |
-
colorize: 1
|
62 |
-
|
63 |
-
effect:
|
64 |
-
args:
|
65 |
-
# elastic distortion
|
66 |
-
- prob: 1
|
67 |
-
args:
|
68 |
-
alpha: [0, 1]
|
69 |
-
sigma: [0, 0.5]
|
70 |
-
# gaussian noise
|
71 |
-
- prob: 1
|
72 |
-
args:
|
73 |
-
scale: [0, 8]
|
74 |
-
per_channel: 0
|
75 |
-
# perspective
|
76 |
-
- prob: 1
|
77 |
-
args:
|
78 |
-
weights: [750, 50, 50, 25, 25, 25, 25, 50]
|
79 |
-
args:
|
80 |
-
- percents: [[0.75, 1], [0.75, 1], [0.75, 1], [0.75, 1]]
|
81 |
-
- percents: [[0.75, 1], [1, 1], [0.75, 1], [1, 1]]
|
82 |
-
- percents: [[1, 1], [0.75, 1], [1, 1], [0.75, 1]]
|
83 |
-
- percents: [[0.75, 1], [1, 1], [1, 1], [1, 1]]
|
84 |
-
- percents: [[1, 1], [0.75, 1], [1, 1], [1, 1]]
|
85 |
-
- percents: [[1, 1], [1, 1], [0.75, 1], [1, 1]]
|
86 |
-
- percents: [[1, 1], [1, 1], [1, 1], [0.75, 1]]
|
87 |
-
- percents: [[1, 1], [1, 1], [1, 1], [1, 1]]
|
88 |
-
|
89 |
-
effect:
|
90 |
-
args:
|
91 |
-
# color
|
92 |
-
- prob: 0.2
|
93 |
-
args:
|
94 |
-
rgb: [[0, 255], [0, 255], [0, 255]]
|
95 |
-
alpha: [0, 0.2]
|
96 |
-
# shadow
|
97 |
-
- prob: 1
|
98 |
-
args:
|
99 |
-
intensity: [0, 160]
|
100 |
-
amount: [0, 1]
|
101 |
-
smoothing: [0.5, 1]
|
102 |
-
bidirectional: 0
|
103 |
-
# contrast
|
104 |
-
- prob: 1
|
105 |
-
args:
|
106 |
-
alpha: [1, 1.5]
|
107 |
-
# brightness
|
108 |
-
- prob: 1
|
109 |
-
args:
|
110 |
-
beta: [-48, 0]
|
111 |
-
# motion blur
|
112 |
-
- prob: 0.5
|
113 |
-
args:
|
114 |
-
k: [3, 5]
|
115 |
-
angle: [0, 360]
|
116 |
-
# gaussian blur
|
117 |
-
- prob: 1
|
118 |
-
args:
|
119 |
-
sigma: [0, 1.5]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synthdog/elements/__init__.py
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Donut
|
3 |
-
Copyright (c) 2022-present NAVER Corp.
|
4 |
-
MIT License
|
5 |
-
"""
|
6 |
-
from elements.background import Background
|
7 |
-
from elements.content import Content
|
8 |
-
from elements.document import Document
|
9 |
-
from elements.paper import Paper
|
10 |
-
from elements.textbox import TextBox
|
11 |
-
|
12 |
-
__all__ = ["Background", "Content", "Document", "Paper", "TextBox"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synthdog/elements/background.py
DELETED
@@ -1,24 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Donut
|
3 |
-
Copyright (c) 2022-present NAVER Corp.
|
4 |
-
MIT License
|
5 |
-
"""
|
6 |
-
from synthtiger import components, layers
|
7 |
-
|
8 |
-
|
9 |
-
class Background:
|
10 |
-
def __init__(self, config):
|
11 |
-
self.image = components.BaseTexture(**config.get("image", {}))
|
12 |
-
self.effect = components.Iterator(
|
13 |
-
[
|
14 |
-
components.Switch(components.GaussianBlur()),
|
15 |
-
],
|
16 |
-
**config.get("effect", {})
|
17 |
-
)
|
18 |
-
|
19 |
-
def generate(self, size):
|
20 |
-
bg_layer = layers.RectLayer(size, (255, 255, 255, 255))
|
21 |
-
self.image.apply([bg_layer])
|
22 |
-
self.effect.apply([bg_layer])
|
23 |
-
|
24 |
-
return bg_layer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synthdog/elements/content.py
DELETED
@@ -1,118 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Donut
|
3 |
-
Copyright (c) 2022-present NAVER Corp.
|
4 |
-
MIT License
|
5 |
-
"""
|
6 |
-
from collections import OrderedDict
|
7 |
-
|
8 |
-
import numpy as np
|
9 |
-
from synthtiger import components
|
10 |
-
|
11 |
-
from elements.textbox import TextBox
|
12 |
-
from layouts import GridStack
|
13 |
-
|
14 |
-
|
15 |
-
class TextReader:
|
16 |
-
def __init__(self, path, cache_size=2 ** 28, block_size=2 ** 20):
|
17 |
-
self.fp = open(path, "r", encoding="utf-8")
|
18 |
-
self.length = 0
|
19 |
-
self.offsets = [0]
|
20 |
-
self.cache = OrderedDict()
|
21 |
-
self.cache_size = cache_size
|
22 |
-
self.block_size = block_size
|
23 |
-
self.bucket_size = cache_size // block_size
|
24 |
-
self.idx = 0
|
25 |
-
|
26 |
-
while True:
|
27 |
-
text = self.fp.read(self.block_size)
|
28 |
-
if not text:
|
29 |
-
break
|
30 |
-
self.length += len(text)
|
31 |
-
self.offsets.append(self.fp.tell())
|
32 |
-
|
33 |
-
def __len__(self):
|
34 |
-
return self.length
|
35 |
-
|
36 |
-
def __iter__(self):
|
37 |
-
return self
|
38 |
-
|
39 |
-
def __next__(self):
|
40 |
-
char = self.get()
|
41 |
-
self.next()
|
42 |
-
return char
|
43 |
-
|
44 |
-
def move(self, idx):
|
45 |
-
self.idx = idx
|
46 |
-
|
47 |
-
def next(self):
|
48 |
-
self.idx = (self.idx + 1) % self.length
|
49 |
-
|
50 |
-
def prev(self):
|
51 |
-
self.idx = (self.idx - 1) % self.length
|
52 |
-
|
53 |
-
def get(self):
|
54 |
-
key = self.idx // self.block_size
|
55 |
-
|
56 |
-
if key in self.cache:
|
57 |
-
text = self.cache[key]
|
58 |
-
else:
|
59 |
-
if len(self.cache) >= self.bucket_size:
|
60 |
-
self.cache.popitem(last=False)
|
61 |
-
|
62 |
-
offset = self.offsets[key]
|
63 |
-
self.fp.seek(offset, 0)
|
64 |
-
text = self.fp.read(self.block_size)
|
65 |
-
self.cache[key] = text
|
66 |
-
|
67 |
-
self.cache.move_to_end(key)
|
68 |
-
char = text[self.idx % self.block_size]
|
69 |
-
return char
|
70 |
-
|
71 |
-
|
72 |
-
class Content:
|
73 |
-
def __init__(self, config):
|
74 |
-
self.margin = config.get("margin", [0, 0.1])
|
75 |
-
self.reader = TextReader(**config.get("text", {}))
|
76 |
-
self.font = components.BaseFont(**config.get("font", {}))
|
77 |
-
self.layout = GridStack(config.get("layout", {}))
|
78 |
-
self.textbox = TextBox(config.get("textbox", {}))
|
79 |
-
self.textbox_color = components.Switch(components.Gray(), **config.get("textbox_color", {}))
|
80 |
-
self.content_color = components.Switch(components.Gray(), **config.get("content_color", {}))
|
81 |
-
|
82 |
-
def generate(self, size):
|
83 |
-
width, height = size
|
84 |
-
|
85 |
-
layout_left = width * np.random.uniform(self.margin[0], self.margin[1])
|
86 |
-
layout_top = height * np.random.uniform(self.margin[0], self.margin[1])
|
87 |
-
layout_width = max(width - layout_left * 2, 0)
|
88 |
-
layout_height = max(height - layout_top * 2, 0)
|
89 |
-
layout_bbox = [layout_left, layout_top, layout_width, layout_height]
|
90 |
-
|
91 |
-
text_layers, texts = [], []
|
92 |
-
layouts = self.layout.generate(layout_bbox)
|
93 |
-
self.reader.move(np.random.randint(len(self.reader)))
|
94 |
-
|
95 |
-
for layout in layouts:
|
96 |
-
font = self.font.sample()
|
97 |
-
|
98 |
-
for bbox, align in layout:
|
99 |
-
x, y, w, h = bbox
|
100 |
-
text_layer, text = self.textbox.generate((w, h), self.reader, font)
|
101 |
-
self.reader.prev()
|
102 |
-
|
103 |
-
if text_layer is None:
|
104 |
-
continue
|
105 |
-
|
106 |
-
text_layer.center = (x + w / 2, y + h / 2)
|
107 |
-
if align == "left":
|
108 |
-
text_layer.left = x
|
109 |
-
if align == "right":
|
110 |
-
text_layer.right = x + w
|
111 |
-
|
112 |
-
self.textbox_color.apply([text_layer])
|
113 |
-
text_layers.append(text_layer)
|
114 |
-
texts.append(text)
|
115 |
-
|
116 |
-
self.content_color.apply(text_layers)
|
117 |
-
|
118 |
-
return text_layers, texts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synthdog/elements/document.py
DELETED
@@ -1,65 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Donut
|
3 |
-
Copyright (c) 2022-present NAVER Corp.
|
4 |
-
MIT License
|
5 |
-
"""
|
6 |
-
import numpy as np
|
7 |
-
from synthtiger import components
|
8 |
-
|
9 |
-
from elements.content import Content
|
10 |
-
from elements.paper import Paper
|
11 |
-
|
12 |
-
|
13 |
-
class Document:
|
14 |
-
def __init__(self, config):
|
15 |
-
self.fullscreen = config.get("fullscreen", 0.5)
|
16 |
-
self.landscape = config.get("landscape", 0.5)
|
17 |
-
self.short_size = config.get("short_size", [480, 1024])
|
18 |
-
self.aspect_ratio = config.get("aspect_ratio", [1, 2])
|
19 |
-
self.paper = Paper(config.get("paper", {}))
|
20 |
-
self.content = Content(config.get("content", {}))
|
21 |
-
self.effect = components.Iterator(
|
22 |
-
[
|
23 |
-
components.Switch(components.ElasticDistortion()),
|
24 |
-
components.Switch(components.AdditiveGaussianNoise()),
|
25 |
-
components.Switch(
|
26 |
-
components.Selector(
|
27 |
-
[
|
28 |
-
components.Perspective(),
|
29 |
-
components.Perspective(),
|
30 |
-
components.Perspective(),
|
31 |
-
components.Perspective(),
|
32 |
-
components.Perspective(),
|
33 |
-
components.Perspective(),
|
34 |
-
components.Perspective(),
|
35 |
-
components.Perspective(),
|
36 |
-
]
|
37 |
-
)
|
38 |
-
),
|
39 |
-
],
|
40 |
-
**config.get("effect", {}),
|
41 |
-
)
|
42 |
-
|
43 |
-
def generate(self, size):
|
44 |
-
width, height = size
|
45 |
-
fullscreen = np.random.rand() < self.fullscreen
|
46 |
-
|
47 |
-
if not fullscreen:
|
48 |
-
landscape = np.random.rand() < self.landscape
|
49 |
-
max_size = width if landscape else height
|
50 |
-
short_size = np.random.randint(
|
51 |
-
min(width, height, self.short_size[0]),
|
52 |
-
min(width, height, self.short_size[1]) + 1,
|
53 |
-
)
|
54 |
-
aspect_ratio = np.random.uniform(
|
55 |
-
min(max_size / short_size, self.aspect_ratio[0]),
|
56 |
-
min(max_size / short_size, self.aspect_ratio[1]),
|
57 |
-
)
|
58 |
-
long_size = int(short_size * aspect_ratio)
|
59 |
-
size = (long_size, short_size) if landscape else (short_size, long_size)
|
60 |
-
|
61 |
-
text_layers, texts = self.content.generate(size)
|
62 |
-
paper_layer = self.paper.generate(size)
|
63 |
-
self.effect.apply([*text_layers, paper_layer])
|
64 |
-
|
65 |
-
return paper_layer, text_layers, texts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synthdog/elements/paper.py
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Donut
|
3 |
-
Copyright (c) 2022-present NAVER Corp.
|
4 |
-
MIT License
|
5 |
-
"""
|
6 |
-
from synthtiger import components, layers
|
7 |
-
|
8 |
-
|
9 |
-
class Paper:
|
10 |
-
def __init__(self, config):
|
11 |
-
self.image = components.BaseTexture(**config.get("image", {}))
|
12 |
-
|
13 |
-
def generate(self, size):
|
14 |
-
paper_layer = layers.RectLayer(size, (255, 255, 255, 255))
|
15 |
-
self.image.apply([paper_layer])
|
16 |
-
|
17 |
-
return paper_layer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synthdog/elements/textbox.py
DELETED
@@ -1,43 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Donut
|
3 |
-
Copyright (c) 2022-present NAVER Corp.
|
4 |
-
MIT License
|
5 |
-
"""
|
6 |
-
import numpy as np
|
7 |
-
from synthtiger import layers
|
8 |
-
|
9 |
-
|
10 |
-
class TextBox:
|
11 |
-
def __init__(self, config):
|
12 |
-
self.fill = config.get("fill", [1, 1])
|
13 |
-
|
14 |
-
def generate(self, size, text, font):
|
15 |
-
width, height = size
|
16 |
-
|
17 |
-
char_layers, chars = [], []
|
18 |
-
fill = np.random.uniform(self.fill[0], self.fill[1])
|
19 |
-
width = np.clip(width * fill, height, width)
|
20 |
-
font = {**font, "size": int(height)}
|
21 |
-
left, top = 0, 0
|
22 |
-
|
23 |
-
for char in text:
|
24 |
-
if char in "\r\n":
|
25 |
-
continue
|
26 |
-
|
27 |
-
char_layer = layers.TextLayer(char, **font)
|
28 |
-
char_scale = height / char_layer.height
|
29 |
-
char_layer.bbox = [left, top, *(char_layer.size * char_scale)]
|
30 |
-
if char_layer.right > width:
|
31 |
-
break
|
32 |
-
|
33 |
-
char_layers.append(char_layer)
|
34 |
-
chars.append(char)
|
35 |
-
left = char_layer.right
|
36 |
-
|
37 |
-
text = "".join(chars).strip()
|
38 |
-
if len(char_layers) == 0 or len(text) == 0:
|
39 |
-
return None, None
|
40 |
-
|
41 |
-
text_layer = layers.Group(char_layers).merge()
|
42 |
-
|
43 |
-
return text_layer, text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synthdog/layouts/__init__.py
DELETED
@@ -1,9 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Donut
|
3 |
-
Copyright (c) 2022-present NAVER Corp.
|
4 |
-
MIT License
|
5 |
-
"""
|
6 |
-
from layouts.grid import Grid
|
7 |
-
from layouts.grid_stack import GridStack
|
8 |
-
|
9 |
-
__all__ = ["Grid", "GridStack"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synthdog/layouts/grid.py
DELETED
@@ -1,68 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Donut
|
3 |
-
Copyright (c) 2022-present NAVER Corp.
|
4 |
-
MIT License
|
5 |
-
"""
|
6 |
-
import numpy as np
|
7 |
-
|
8 |
-
|
9 |
-
class Grid:
|
10 |
-
def __init__(self, config):
|
11 |
-
self.text_scale = config.get("text_scale", [0.05, 0.1])
|
12 |
-
self.max_row = config.get("max_row", 5)
|
13 |
-
self.max_col = config.get("max_col", 3)
|
14 |
-
self.fill = config.get("fill", [0, 1])
|
15 |
-
self.full = config.get("full", 0)
|
16 |
-
self.align = config.get("align", ["left", "right", "center"])
|
17 |
-
|
18 |
-
def generate(self, bbox):
|
19 |
-
left, top, width, height = bbox
|
20 |
-
|
21 |
-
text_scale = np.random.uniform(self.text_scale[0], self.text_scale[1])
|
22 |
-
text_size = min(width, height) * text_scale
|
23 |
-
grids = np.random.permutation(self.max_row * self.max_col)
|
24 |
-
|
25 |
-
for grid in grids:
|
26 |
-
row = grid // self.max_col + 1
|
27 |
-
col = grid % self.max_col + 1
|
28 |
-
if text_size * (col * 2 - 1) <= width and text_size * row <= height:
|
29 |
-
break
|
30 |
-
else:
|
31 |
-
return None
|
32 |
-
|
33 |
-
bound = max(1 - text_size / width * (col - 1), 0)
|
34 |
-
full = np.random.rand() < self.full
|
35 |
-
fill = np.random.uniform(self.fill[0], self.fill[1])
|
36 |
-
fill = 1 if full else fill
|
37 |
-
fill = np.clip(fill, 0, bound)
|
38 |
-
|
39 |
-
padding = np.random.randint(4) if col > 1 else np.random.randint(1, 4)
|
40 |
-
padding = (bool(padding // 2), bool(padding % 2))
|
41 |
-
|
42 |
-
weights = np.zeros(col * 2 + 1)
|
43 |
-
weights[1:-1] = text_size / width
|
44 |
-
probs = 1 - np.random.rand(col * 2 + 1)
|
45 |
-
probs[0] = 0 if not padding[0] else probs[0]
|
46 |
-
probs[-1] = 0 if not padding[-1] else probs[-1]
|
47 |
-
probs[1::2] *= max(fill - sum(weights[1::2]), 0) / sum(probs[1::2])
|
48 |
-
probs[::2] *= max(1 - fill - sum(weights[::2]), 0) / sum(probs[::2])
|
49 |
-
weights += probs
|
50 |
-
|
51 |
-
widths = [width * weights[c] for c in range(col * 2 + 1)]
|
52 |
-
heights = [text_size for _ in range(row)]
|
53 |
-
|
54 |
-
xs = np.cumsum([0] + widths)
|
55 |
-
ys = np.cumsum([0] + heights)
|
56 |
-
|
57 |
-
layout = []
|
58 |
-
|
59 |
-
for c in range(col):
|
60 |
-
align = self.align[np.random.randint(len(self.align))]
|
61 |
-
|
62 |
-
for r in range(row):
|
63 |
-
x, y = xs[c * 2 + 1], ys[r]
|
64 |
-
w, h = xs[c * 2 + 2] - x, ys[r + 1] - y
|
65 |
-
bbox = [left + x, top + y, w, h]
|
66 |
-
layout.append((bbox, align))
|
67 |
-
|
68 |
-
return layout
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synthdog/layouts/grid_stack.py
DELETED
@@ -1,74 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Donut
|
3 |
-
Copyright (c) 2022-present NAVER Corp.
|
4 |
-
MIT License
|
5 |
-
"""
|
6 |
-
import numpy as np
|
7 |
-
|
8 |
-
from layouts import Grid
|
9 |
-
|
10 |
-
|
11 |
-
class GridStack:
|
12 |
-
def __init__(self, config):
|
13 |
-
self.text_scale = config.get("text_scale", [0.05, 0.1])
|
14 |
-
self.max_row = config.get("max_row", 5)
|
15 |
-
self.max_col = config.get("max_col", 3)
|
16 |
-
self.fill = config.get("fill", [0, 1])
|
17 |
-
self.full = config.get("full", 0)
|
18 |
-
self.align = config.get("align", ["left", "right", "center"])
|
19 |
-
self.stack_spacing = config.get("stack_spacing", [0, 0.05])
|
20 |
-
self.stack_fill = config.get("stack_fill", [1, 1])
|
21 |
-
self.stack_full = config.get("stack_full", 0)
|
22 |
-
self._grid = Grid(
|
23 |
-
{
|
24 |
-
"text_scale": self.text_scale,
|
25 |
-
"max_row": self.max_row,
|
26 |
-
"max_col": self.max_col,
|
27 |
-
"align": self.align,
|
28 |
-
}
|
29 |
-
)
|
30 |
-
|
31 |
-
def generate(self, bbox):
|
32 |
-
left, top, width, height = bbox
|
33 |
-
|
34 |
-
stack_spacing = np.random.uniform(self.stack_spacing[0], self.stack_spacing[1])
|
35 |
-
stack_spacing *= min(width, height)
|
36 |
-
|
37 |
-
stack_full = np.random.rand() < self.stack_full
|
38 |
-
stack_fill = np.random.uniform(self.stack_fill[0], self.stack_fill[1])
|
39 |
-
stack_fill = 1 if stack_full else stack_fill
|
40 |
-
|
41 |
-
full = np.random.rand() < self.full
|
42 |
-
fill = np.random.uniform(self.fill[0], self.fill[1])
|
43 |
-
fill = 1 if full else fill
|
44 |
-
self._grid.fill = [fill, fill]
|
45 |
-
|
46 |
-
layouts = []
|
47 |
-
line = 0
|
48 |
-
|
49 |
-
while True:
|
50 |
-
grid_size = (width, height * stack_fill - line)
|
51 |
-
text_scale = np.random.uniform(self.text_scale[0], self.text_scale[1])
|
52 |
-
text_size = min(width, height) * text_scale
|
53 |
-
text_scale = text_size / min(grid_size)
|
54 |
-
self._grid.text_scale = [text_scale, text_scale]
|
55 |
-
|
56 |
-
layout = self._grid.generate([left, top + line, *grid_size])
|
57 |
-
if layout is None:
|
58 |
-
break
|
59 |
-
|
60 |
-
line = max(y + h - top for (_, y, _, h), _ in layout) + stack_spacing
|
61 |
-
layouts.append(layout)
|
62 |
-
|
63 |
-
line = max(line - stack_spacing, 0)
|
64 |
-
space = max(height - line, 0)
|
65 |
-
spaces = np.random.rand(len(layouts) + 1)
|
66 |
-
spaces *= space / sum(spaces) if sum(spaces) > 0 else 0
|
67 |
-
spaces = np.cumsum(spaces)
|
68 |
-
|
69 |
-
for layout, space in zip(layouts, spaces):
|
70 |
-
for bbox, _ in layout:
|
71 |
-
x, y, w, h = bbox
|
72 |
-
bbox[:] = [x, y + space, w, h]
|
73 |
-
|
74 |
-
return layouts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synthdog/resources/background/bedroom_83.jpg
DELETED
Binary file (71.6 kB)
|
|
synthdog/resources/background/bob+dylan_83.jpg
DELETED
Binary file (418 kB)
|
|
synthdog/resources/background/coffee_122.jpg
DELETED
Binary file (58.3 kB)
|
|
synthdog/resources/background/coffee_18.jpeg
DELETED
Git LFS Details
|
synthdog/resources/background/crater_141.jpg
DELETED
Git LFS Details
|
synthdog/resources/background/cream_124.jpg
DELETED
Git LFS Details
|
synthdog/resources/background/eagle_110.jpg
DELETED
Binary file (221 kB)
|
|
synthdog/resources/background/farm_25.jpg
DELETED
Binary file (704 kB)
|
|
synthdog/resources/background/hiking_18.jpg
DELETED
Binary file (515 kB)
|
|
synthdog/resources/corpus/enwiki.txt
DELETED
The diff for this file is too large to render.
See raw diff
|
|
synthdog/resources/corpus/jawiki.txt
DELETED
The diff for this file is too large to render.
See raw diff
|
|
synthdog/resources/corpus/kowiki.txt
DELETED
The diff for this file is too large to render.
See raw diff
|
|
synthdog/resources/corpus/zhwiki.txt
DELETED
The diff for this file is too large to render.
See raw diff
|
|
synthdog/resources/font/en/NotoSans-Regular.ttf
DELETED
Binary file (399 kB)
|
|
synthdog/resources/font/en/NotoSerif-Regular.ttf
DELETED
Binary file (375 kB)
|
|
synthdog/resources/font/ja/NotoSansJP-Regular.otf
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:47c29251c03bd7731461efd9aff279d04058025c24fc08ed49552aeec20adc6d
|
3 |
-
size 4548148
|
|
|
|
|
|
|
|
synthdog/resources/font/ja/NotoSerifJP-Regular.otf
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:9a0f0ab1c97dc9b1bb857f3259f5de23c6caa224c14d12878575b0a84676db8f
|
3 |
-
size 6169384
|
|
|
|
|
|
|
|
synthdog/resources/font/ko/NotoSansKR-Regular.otf
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:2f62e282b5ff3694c09af182d0dfc29d46ce6b85303c0da74f159c098e75991b
|
3 |
-
size 4744644
|
|
|
|
|
|
|
|
synthdog/resources/font/ko/NotoSerifKR-Regular.otf
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:13196f84ee798b18eddd80077051e5d88ff869696c43200dc54c66807884f74e
|
3 |
-
size 7437596
|
|
|
|
|
|
|
|
synthdog/resources/font/zh/NotoSansSC-Regular.otf
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:63fdadb47c21197170f3cda6c60e98e481b8a1eb28e5f44102da51bec17d123b
|
3 |
-
size 8481960
|
|
|
|
|
|
|
|
synthdog/resources/font/zh/NotoSerifSC-Regular.otf
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:66080541a111a7a31179700496013aac4b64a53cc41f570bd21c2628c75e4628
|
3 |
-
size 11214568
|
|
|
|
|
|
|
|
synthdog/resources/paper/paper_1.jpg
DELETED
Git LFS Details
|
synthdog/resources/paper/paper_2.jpg
DELETED
Git LFS Details
|
synthdog/resources/paper/paper_3.jpg
DELETED
Git LFS Details
|
synthdog/resources/paper/paper_4.jpg
DELETED
Git LFS Details
|
synthdog/resources/paper/paper_5.jpg
DELETED
Git LFS Details
|
synthdog/resources/paper/paper_6.jpg
DELETED
Git LFS Details
|
synthdog/template.py
DELETED
@@ -1,130 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Donut
|
3 |
-
Copyright (c) 2022-present NAVER Corp.
|
4 |
-
MIT License
|
5 |
-
"""
|
6 |
-
import json
|
7 |
-
import os
|
8 |
-
import re
|
9 |
-
from typing import Any, List
|
10 |
-
|
11 |
-
import numpy as np
|
12 |
-
from elements import Background, Document
|
13 |
-
from PIL import Image
|
14 |
-
from synthtiger import components, layers, templates
|
15 |
-
|
16 |
-
|
17 |
-
class SynthDoG(templates.Template):
|
18 |
-
def __init__(self, config=None, split_ratio: List[float] = [0.8, 0.1, 0.1]):
|
19 |
-
super().__init__(config)
|
20 |
-
if config is None:
|
21 |
-
config = {}
|
22 |
-
|
23 |
-
self.quality = config.get("quality", [50, 95])
|
24 |
-
self.landscape = config.get("landscape", 0.5)
|
25 |
-
self.short_size = config.get("short_size", [720, 1024])
|
26 |
-
self.aspect_ratio = config.get("aspect_ratio", [1, 2])
|
27 |
-
self.background = Background(config.get("background", {}))
|
28 |
-
self.document = Document(config.get("document", {}))
|
29 |
-
self.effect = components.Iterator(
|
30 |
-
[
|
31 |
-
components.Switch(components.RGB()),
|
32 |
-
components.Switch(components.Shadow()),
|
33 |
-
components.Switch(components.Contrast()),
|
34 |
-
components.Switch(components.Brightness()),
|
35 |
-
components.Switch(components.MotionBlur()),
|
36 |
-
components.Switch(components.GaussianBlur()),
|
37 |
-
],
|
38 |
-
**config.get("effect", {}),
|
39 |
-
)
|
40 |
-
|
41 |
-
# config for splits
|
42 |
-
self.splits = ["train", "validation", "test"]
|
43 |
-
self.split_ratio = split_ratio
|
44 |
-
self.split_indexes = np.random.choice(3, size=10000, p=split_ratio)
|
45 |
-
|
46 |
-
def generate(self):
|
47 |
-
landscape = np.random.rand() < self.landscape
|
48 |
-
short_size = np.random.randint(self.short_size[0], self.short_size[1] + 1)
|
49 |
-
aspect_ratio = np.random.uniform(self.aspect_ratio[0], self.aspect_ratio[1])
|
50 |
-
long_size = int(short_size * aspect_ratio)
|
51 |
-
size = (long_size, short_size) if landscape else (short_size, long_size)
|
52 |
-
|
53 |
-
bg_layer = self.background.generate(size)
|
54 |
-
paper_layer, text_layers, texts = self.document.generate(size)
|
55 |
-
|
56 |
-
document_group = layers.Group([*text_layers, paper_layer])
|
57 |
-
document_space = np.clip(size - document_group.size, 0, None)
|
58 |
-
document_group.left = np.random.randint(document_space[0] + 1)
|
59 |
-
document_group.top = np.random.randint(document_space[1] + 1)
|
60 |
-
roi = np.array(paper_layer.quad, dtype=int)
|
61 |
-
|
62 |
-
layer = layers.Group([*document_group.layers, bg_layer]).merge()
|
63 |
-
self.effect.apply([layer])
|
64 |
-
|
65 |
-
image = layer.output(bbox=[0, 0, *size])
|
66 |
-
label = " ".join(texts)
|
67 |
-
label = label.strip()
|
68 |
-
label = re.sub(r"\s+", " ", label)
|
69 |
-
quality = np.random.randint(self.quality[0], self.quality[1] + 1)
|
70 |
-
|
71 |
-
data = {
|
72 |
-
"image": image,
|
73 |
-
"label": label,
|
74 |
-
"quality": quality,
|
75 |
-
"roi": roi,
|
76 |
-
}
|
77 |
-
|
78 |
-
return data
|
79 |
-
|
80 |
-
def init_save(self, root):
|
81 |
-
if not os.path.exists(root):
|
82 |
-
os.makedirs(root, exist_ok=True)
|
83 |
-
|
84 |
-
def save(self, root, data, idx):
|
85 |
-
image = data["image"]
|
86 |
-
label = data["label"]
|
87 |
-
quality = data["quality"]
|
88 |
-
roi = data["roi"]
|
89 |
-
|
90 |
-
# split
|
91 |
-
split_idx = self.split_indexes[idx % len(self.split_indexes)]
|
92 |
-
output_dirpath = os.path.join(root, self.splits[split_idx])
|
93 |
-
|
94 |
-
# save image
|
95 |
-
image_filename = f"image_{idx}.jpg"
|
96 |
-
image_filepath = os.path.join(output_dirpath, image_filename)
|
97 |
-
os.makedirs(os.path.dirname(image_filepath), exist_ok=True)
|
98 |
-
image = Image.fromarray(image[..., :3].astype(np.uint8))
|
99 |
-
image.save(image_filepath, quality=quality)
|
100 |
-
|
101 |
-
# save metadata (gt_json)
|
102 |
-
metadata_filename = "metadata.jsonl"
|
103 |
-
metadata_filepath = os.path.join(output_dirpath, metadata_filename)
|
104 |
-
os.makedirs(os.path.dirname(metadata_filepath), exist_ok=True)
|
105 |
-
|
106 |
-
metadata = self.format_metadata(image_filename=image_filename, keys=["text_sequence"], values=[label])
|
107 |
-
with open(metadata_filepath, "a") as fp:
|
108 |
-
json.dump(metadata, fp, ensure_ascii=False)
|
109 |
-
fp.write("\n")
|
110 |
-
|
111 |
-
def end_save(self, root):
|
112 |
-
pass
|
113 |
-
|
114 |
-
def format_metadata(self, image_filename: str, keys: List[str], values: List[Any]):
|
115 |
-
"""
|
116 |
-
Fit gt_parse contents to huggingface dataset's format
|
117 |
-
keys and values, whose lengths are equal, are used to constrcut 'gt_parse' field in 'ground_truth' field
|
118 |
-
Args:
|
119 |
-
keys: List of task_name
|
120 |
-
values: List of actual gt data corresponding to each task_name
|
121 |
-
"""
|
122 |
-
assert len(keys) == len(values), "Length does not match: keys({}), values({})".format(len(keys), len(values))
|
123 |
-
|
124 |
-
_gt_parse_v = dict()
|
125 |
-
for k, v in zip(keys, values):
|
126 |
-
_gt_parse_v[k] = v
|
127 |
-
gt_parse = {"gt_parse": _gt_parse_v}
|
128 |
-
gt_parse_str = json.dumps(gt_parse, ensure_ascii=False)
|
129 |
-
metadata = {"file_name": image_filename, "ground_truth": gt_parse_str}
|
130 |
-
return metadata
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|