gyrojeff commited on
Commit
7ab5a96
1 Parent(s): 5c3dbf6

doc: add dataset generation clarification

Browse files
Files changed (1) hide show
  1. README.md +133 -0
README.md ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # YuzuMarker.FontDetection
2
+
3
+ ## Scene Text Font Dataset Generation
4
+
5
+ This repository also contains data for automatically generating a dataset of scene text images with different fonts. The dataset is generated using the [CJK font pack by VCB-Studio](https://vcb-s.com/archives/1114) and thousands of background image from [pixiv.net](https://pixiv.net).
6
+
7
+ The pixiv data will not be shared since it is just randomly scraped. You may prepare your own background dataset that would fit your data distribution as you like.
8
+
9
+ For the text corpus,
10
+
11
+ * Chinese is randomly generated from [3500 common Chinese characters](https://gist.github.com/simongfxu/13accd501f6c91e7a423ddc43e674c0f).
12
+ * Japanese is randomly generated from a list of lyrics from https://www.uta-net.com.
13
+ * Korean is randomly generated from its alphabet.
14
+
15
+ All text are also mixed with English text to simulate real-world data.
16
+
17
+ ### Data Preparation Walkthrough
18
+
19
+ 1. Download the CJK font pack and extract it to the `dataset/fonts` directory.
20
+ 2. Prepare the background data and put them in the `dataset/pixivimages` directory.
21
+ 3. Run following script to clean the file names
22
+ ```bash
23
+ python dataset_filename_preprocess.py
24
+ ```
25
+
26
+ ### Generation Script Walkthrough
27
+
28
+ Now the preparation is complete. The following command can be used to generate the dataset:
29
+
30
+ ```bash
31
+ python font_ds_generate_script.py 1 1
32
+ ```
33
+
34
+ Note that the command is followed by two parameters. The second one is to split the task into multiple partitions, and the first one is the index of the partitioned task to run. For example, if you want to run the task in 4 partitions, you can run the following commands in parallel to speed up the process:
35
+
36
+ ```bash
37
+ python font_ds_generate_script.py 1 4
38
+ python font_ds_generate_script.py 2 4
39
+ python font_ds_generate_script.py 3 4
40
+ python font_ds_generate_script.py 4 4
41
+ ```
42
+
43
+ The generated dataset will be saved in the `dataset/font_img` directory.
44
+
45
+ Note that `batch_generate_script_cmd_32.bat` and `batch_generate_script_cmd_64.bat` are batch scripts for Windows that can be used to generate the dataset in parallel with 32 partitions and 64 partitions.
46
+
47
+ ### (Optional) Linux Cluster Generation Walkthrough
48
+
49
+ If you would like to run the generation script on linux clusters, we also provides the environment setup script `linux_venv_setup.sh`.
50
+
51
+ The prerequisite is that you have a linux cluster with `python3-venv` installed and `python3` is available in the path.
52
+
53
+ To setup the environment, run the following command:
54
+
55
+ ```bash
56
+ ./linux_venv_setup.sh
57
+ ```
58
+
59
+ The script will create a virtual environment in the `venv` directory and install all the required packages. The script is required in most cases since the script will also install `libraqm` which is required for the text rendering of PIL and is often not installed by default in most linux server distributions.
60
+
61
+ After the environment is setup, you might compile a task scheduler to deploy generation task in parallel.
62
+
63
+ The main idea is similar to the direct usage of the script, except that here we accept three parameters,
64
+
65
+ * `TOTAL_MISSION`: the total number of partitions of the task
66
+ * `MIN_MISSION`: the minimum partition index of the task to run
67
+ * `MAX_MISSION`: the maximum partition index of the task to run
68
+
69
+ and the compilation command is as following:
70
+
71
+ ```bash
72
+ gcc -D MIN_MISSION=<MIN_MISSION> \
73
+ -D MAX_MISSION=<MAX_MISSION> \
74
+ -D TOTAL_MISSION=<TOTAL_MISSION> \
75
+ batch_generate_script_linux.c \
76
+ -o <object-file-name>.out
77
+ ```
78
+
79
+ For example if you want to run the task in 64 partitions, and want to spilit the work on 4 machines, you can compile the following command on each machine:
80
+
81
+ ```bash
82
+ # Machine 1
83
+ gcc -D MIN_MISSION=1 \
84
+ -D MAX_MISSION=16 \
85
+ -D TOTAL_MISSION=64 \
86
+ batch_generate_script_linux.c \
87
+ -o mission-1-16.out
88
+ # Machine 2
89
+ gcc -D MIN_MISSION=17 \
90
+ -D MAX_MISSION=32 \
91
+ -D TOTAL_MISSION=64 \
92
+ batch_generate_script_linux.c \
93
+ -o mission-17-32.out
94
+ # Machine 3
95
+ gcc -D MIN_MISSION=33 \
96
+ -D MAX_MISSION=48 \
97
+ -D TOTAL_MISSION=64 \
98
+ batch_generate_script_linux.c \
99
+ -o mission-33-48.out
100
+ # Machine 4
101
+ gcc -D MIN_MISSION=49 \
102
+ -D MAX_MISSION=64 \
103
+ -D TOTAL_MISSION=64 \
104
+ batch_generate_script_linux.c \
105
+ -o mission-49-64.out
106
+ ```
107
+
108
+ Then you can run the compiled object file on each machine to start the generation task.
109
+
110
+ ```bash
111
+ ./mission-1-16.out # Machine 1
112
+ ./mission-17-32.out # Machine 2
113
+ ./mission-33-48.out # Machine 3
114
+ ./mission-49-64.out # Machine 4
115
+ ```
116
+
117
+ There is also another helper script to check the progress of the generation task. It can be used as following:
118
+
119
+ ```bash
120
+ python font_ds_stat.py
121
+ ```
122
+
123
+ ### MISC Info of the Dataset
124
+
125
+ The generation is CPU bound, and the generation speed is highly dependent on the CPU performance. Indeed the work itself is an engineering problem.
126
+
127
+ Some fonts are problematic during the generation process. The script has an manual exclusion list in `config/fonts.yml` and also support unqualified font detection on the fly. The script will automatically skip the problematic fonts and log them for future model training.
128
+
129
+ ## Related works and Resources
130
+
131
+ * Font Identification and Recommendations: https://mangahelpers.com/forum/threads/font-identification-and-recommendations.35672/
132
+ * Unconstrained Text Detection in Manga: a New Dataset and Baseline: https://arxiv.org/pdf/2009.04042.pdf
133
+ * SwordNet: Chinese Character Font Style Recognition Network: https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=9682683