mirror of https://github.com/open-mmlab/mmocr.git
[Tools] Update tools dir structure
parent
2b3a4fe6b5
commit
20e999e3b9
|
@ -86,7 +86,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step2: Generate `instances_training.json` and `instances_test.json` with following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/ctw1500_converter.py /path/to/ctw1500 -o /path/to/ctw1500 --split-list training test
|
||||
python tools/dataset_converters/textdet/ctw1500_converter.py /path/to/ctw1500 -o /path/to/ctw1500 --split-list training test
|
||||
```
|
||||
|
||||
- The resulting directory structure looks like the following:
|
||||
|
@ -126,7 +126,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step 2: Generate `instances_training.json` and `instances_test.json` with the following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/ic11_converter.py PATH/TO/icdar2011 --nproc 4
|
||||
python tools/dataset_converters/textdet/ic11_converter.py PATH/TO/icdar2011 --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -165,7 +165,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step 2: Generate `instances_training.json` and `instances_test.json` with the following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/ic13_converter.py PATH/TO/icdar2013 --nproc 4
|
||||
python tools/dataset_converters/textdet/ic13_converter.py PATH/TO/icdar2013 --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -198,7 +198,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Or, generate `instances_training.json` and `instances_test.json` with the following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/icdar_converter.py /path/to/icdar2015 -o /path/to/icdar2015 -d icdar2015 --split-list training test
|
||||
python tools/dataset_converters/textdet/icdar_converter.py /path/to/icdar2015 -o /path/to/icdar2015 -d icdar2015 --split-list training test
|
||||
```
|
||||
|
||||
- The resulting directory structure looks like the following:
|
||||
|
@ -260,7 +260,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step2: Generate `instances_training.json` and `instances_val.json` with the following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/textocr_converter.py /path/to/textocr
|
||||
python tools/dataset_converters/textdet/textocr_converter.py /path/to/textocr
|
||||
```
|
||||
|
||||
- The resulting directory structure looks like the following:
|
||||
|
@ -301,7 +301,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step2: Generate `instances_training.json` and `instances_test.json` with the following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/totaltext_converter.py /path/to/totaltext
|
||||
python tools/dataset_converters/textdet/totaltext_converter.py /path/to/totaltext
|
||||
```
|
||||
|
||||
- The resulting directory structure looks like the following:
|
||||
|
@ -335,7 +335,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Or, generate `instances_training.json` with following command:
|
||||
|
||||
```bash
|
||||
python tools/data/common/curvedsyntext_converter.py PATH/TO/CurvedSynText150k --nproc 4
|
||||
python tools/dataset_converters/common/curvedsyntext_converter.py PATH/TO/CurvedSynText150k --nproc 4
|
||||
```
|
||||
|
||||
- The resulting directory structure looks like the following:
|
||||
|
@ -371,7 +371,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step2: Generate `instances_training.json` and `instances_test.json` with following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/funsd_converter.py PATH/TO/funsd --nproc 4
|
||||
python tools/dataset_converters/textdet/funsd_converter.py PATH/TO/funsd --nproc 4
|
||||
```
|
||||
|
||||
- The resulting directory structure looks like the following:
|
||||
|
@ -408,7 +408,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step2: Generate `instances_training.json` and `instances_val.json` with following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/detext_converter.py PATH/TO/detext --nproc 4
|
||||
python tools/dataset_converters/textdet/detext_converter.py PATH/TO/detext --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -445,7 +445,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step2: Generate `instances_training.json`, `instances_val.json`, and `instances_test.json` with following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/naf_converter.py PATH/TO/naf --nproc 4
|
||||
python tools/dataset_converters/textdet/naf_converter.py PATH/TO/naf --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -486,7 +486,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step3: Generate `instances_training.json` and `instances_test.json` with the following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/sroie_converter.py PATH/TO/sroie --nproc 4
|
||||
python tools/dataset_converters/textdet/sroie_converter.py PATH/TO/sroie --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -518,7 +518,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step2: Generate `instances_training.json`, `instances_val.json`, and `instances_test.json` with following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/lv_converter.py PATH/TO/lv --nproc 4
|
||||
python tools/dataset_converters/textdet/lv_converter.py PATH/TO/lv --nproc 4
|
||||
```
|
||||
|
||||
- The resulting directory structure looks like the following:
|
||||
|
@ -556,7 +556,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
```bash
|
||||
# Annotations of LSVT test split is not publicly available, split a validation
|
||||
# set by adding --val-ratio 0.2
|
||||
python tools/data/textdet/lsvt_converter.py PATH/TO/lsvt
|
||||
python tools/dataset_converters/textdet/lsvt_converter.py PATH/TO/lsvt
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -590,7 +590,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step2: Generate `instances_train.json`, `instance_val.json` and `instances_test.json` with the following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/imgur_converter.py PATH/TO/imgur
|
||||
python tools/dataset_converters/textdet/imgur_converter.py PATH/TO/imgur
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -622,14 +622,14 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step2: Extract zips:
|
||||
|
||||
```bash
|
||||
python tools/data/common/extract_kaist.py PATH/TO/kaist
|
||||
python tools/dataset_converters/common/extract_kaist.py PATH/TO/kaist
|
||||
```
|
||||
|
||||
- Step3: Generate `instances_training.json` and `instances_val.json` (optional) with following command:
|
||||
|
||||
```bash
|
||||
# Since KAIST does not provide an official split, you can split the dataset by adding --val-ratio 0.2
|
||||
python tools/data/textdet/kaist_converter.py PATH/TO/kaist --nproc 4
|
||||
python tools/dataset_converters/textdet/kaist_converter.py PATH/TO/kaist --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -660,7 +660,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
```bash
|
||||
# Annotations of MTWI test split is not publicly available, split a validation
|
||||
# set by adding --val-ratio 0.2
|
||||
python tools/data/textdet/mtwi_converter.py PATH/TO/mtwi --nproc 4
|
||||
python tools/dataset_converters/textdet/mtwi_converter.py PATH/TO/mtwi --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -694,7 +694,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step2: Generate `instances_training.json` and `instances_val.json` with the following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/cocotext_converter.py PATH/TO/coco_textv2
|
||||
python tools/dataset_converters/textdet/cocotext_converter.py PATH/TO/coco_textv2
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -729,7 +729,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
```bash
|
||||
# Annotations of ReCTS test split is not publicly available, split a validation
|
||||
# set by adding --val-ratio 0.2
|
||||
python tools/data/textdet/rects_converter.py PATH/TO/rects --nproc 4 --val-ratio 0.2
|
||||
python tools/dataset_converters/textdet/rects_converter.py PATH/TO/rects --nproc 4 --val-ratio 0.2
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -770,7 +770,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step3: Generate `instances_training.json` and `instances_val.json` (optional). Since the original dataset doesn't have a validation set, you may specify `--val-ratio` to split the dataset. E.g., if val-ratio is 0.2, then 20% of the data are left out as the validation set in this example.
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/ilst_converter.py PATH/TO/IIIT-ILST --nproc 4
|
||||
python tools/dataset_converters/textdet/ilst_converter.py PATH/TO/IIIT-ILST --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -807,7 +807,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step2: Generate `instances_training.json`, `instances_test.json` and `instances_unseen_test.json`
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/vintext_converter.py PATH/TO/vintext --nproc 4
|
||||
python tools/dataset_converters/textdet/vintext_converter.py PATH/TO/vintext --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -858,7 +858,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
- Step3: - Step3: Generate `instances_training.json` and `instances_val.json` (optional). Since the original dataset doesn't have a validation set, you may specify `--val-ratio` to split the dataset. E.g., if val-ratio is 0.2, then 20% of the data are left out as the validation set in this example.
|
||||
|
||||
```bash
|
||||
python tools/data/textdet/bid_converter.py PATH/TO/BID --nproc 4
|
||||
python tools/dataset_converters/textdet/bid_converter.py PATH/TO/BID --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -879,7 +879,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
|
||||
```bash
|
||||
# Annotations of RCTW test split is not publicly available, split a validation set by adding --val-ratio 0.2
|
||||
python tools/data/textdet/rctw_converter.py PATH/TO/rctw --nproc 4
|
||||
python tools/dataset_converters/textdet/rctw_converter.py PATH/TO/rctw --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -930,7 +930,7 @@ inconsistency results in false examples in the training set. Therefore, users sh
|
|||
|
||||
```bash
|
||||
# Collect word annotation from HierText --level word
|
||||
python tools/data/textdet/hiertext_converter.py PATH/TO/HierText --level word --nproc 4
|
||||
python tools/dataset_converters/textdet/hiertext_converter.py PATH/TO/HierText --level word --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
# Named Entity Recognition
|
||||
|
||||
## Overview
|
||||
|
||||
The structure of the named entity recognition dataset directory is organized as follows.
|
||||
|
||||
```text
|
||||
└── cluener2020
|
||||
├── cluener_predict.json
|
||||
├── dev.json
|
||||
├── README.md
|
||||
├── test.json
|
||||
├── train.json
|
||||
└── vocab.txt
|
||||
```
|
||||
|
||||
## Preparation Steps
|
||||
|
||||
### CLUENER2020
|
||||
|
||||
- Download and extract [cluener_public.zip](https://storage.googleapis.com/cluebenchmark/tasks/cluener_public.zip) to `cluener2020/`
|
||||
- Download [vocab.txt](https://download.openmmlab.com/mmocr/data/cluener_public/vocab.txt) and move `vocab.txt` to `cluener2020/`
|
|
@ -82,7 +82,7 @@
|
|||
- Step2: Convert original annotations to `Train_label.jsonl` and `Test_label.jsonl` with the following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textrecog/ic11_converter.py PATH/TO/icdar2011
|
||||
python tools/dataset_converters/textrecog/ic11_converter.py PATH/TO/icdar2011
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -120,7 +120,7 @@
|
|||
- Step 2: Generate `Train_label.jsonl` and `Test_label.jsonl` with the following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textrecog/ic13_converter.py PATH/TO/icdar2013
|
||||
python tools/dataset_converters/textrecog/ic13_converter.py PATH/TO/icdar2013
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -185,7 +185,7 @@ should be as follows:
|
|||
- Step3:
|
||||
|
||||
```bash
|
||||
python tools/data/textrecog/svt_converter.py <download_svt_dir_path>
|
||||
python tools/dataset_converters/textrecog/svt_converter.py <download_svt_dir_path>
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure
|
||||
|
@ -277,7 +277,7 @@ Please make sure you're using the right annotation to train the model by checkin
|
|||
|
||||
# Convert 'txt' format annos to 'lmdb' (optional)
|
||||
cd /path/to/mmocr
|
||||
python tools/data/utils/lmdb_converter.py data/mixture/Syn90k/label.txt data/mixture/Syn90k/label.lmdb --label-only
|
||||
python tools/dataset_converters/utils/txt2lmdb.py -i data/mixture/Syn90k/label.txt -o data/mixture/Syn90k/label.lmdb
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure
|
||||
|
@ -324,11 +324,11 @@ Please make sure you're using the right annotation to train the model by checkin
|
|||
```bash
|
||||
cd /path/to/mmocr
|
||||
|
||||
python tools/data/textrecog/synthtext_converter.py data/mixture/SynthText/gt.mat data/mixture/SynthText/ data/mixture/SynthText/synthtext/SynthText_patch_horizontal --n_proc 8
|
||||
python tools/dataset_converters/textrecog/synthtext_converter.py data/mixture/SynthText/gt.mat data/mixture/SynthText/ data/mixture/SynthText/synthtext/SynthText_patch_horizontal --n_proc 8
|
||||
|
||||
# Convert 'txt' format annos to 'lmdb' (optional)
|
||||
cd /path/to/mmocr
|
||||
python tools/data/utils/lmdb_converter.py data/mixture/SynthText/label.txt data/mixture/SynthText/label.lmdb --label-only
|
||||
python tools/dataset_converters/utils/txt2lmdb.py -i data/mixture/SynthText/label.txt -o data/mixture/SynthText/label.lmdb
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure
|
||||
|
@ -366,7 +366,7 @@ should be as follows:
|
|||
|
||||
# Convert 'txt' format annos to 'lmdb' (optional)
|
||||
cd /path/to/mmocr
|
||||
python tools/data/utils/lmdb_converter.py data/mixture/SynthAdd/label.txt data/mixture/SynthAdd/label.lmdb --label-only
|
||||
python tools/dataset_converters/utils/txt2lmdb.py -i data/mixture/SynthAdd/label.txt -o data/mixture/SynthAdd/label.lmdb
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure
|
||||
|
@ -383,13 +383,13 @@ should be as follows:
|
|||
To convert label file from `txt` format to `lmdb` format,
|
||||
|
||||
```bash
|
||||
python tools/data/utils/lmdb_converter.py <txt_label_path> <lmdb_label_path> --label-only
|
||||
python tools/dataset_converters/utils/txt2lmdb.py -i <txt_label_path> -o <lmdb_label_path>
|
||||
```
|
||||
|
||||
For example,
|
||||
|
||||
```bash
|
||||
python tools/data/utils/lmdb_converter.py data/mixture/Syn90k/label.txt data/mixture/Syn90k/label.lmdb --label-only
|
||||
python tools/dataset_converters/utils/txt2lmdb.py -i data/mixture/Syn90k/label.txt -o data/mixture/Syn90k/label.lmdb
|
||||
```
|
||||
|
||||
````
|
||||
|
@ -414,7 +414,7 @@ python tools/data/utils/lmdb_converter.py data/mixture/Syn90k/label.txt data/mix
|
|||
- Step2: Generate `train_label.txt`, `val_label.txt` and crop images using 4 processes with the following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textrecog/textocr_converter.py /path/to/textocr 4
|
||||
python tools/dataset_converters/textrecog/textocr_converter.py /path/to/textocr 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure
|
||||
|
@ -455,7 +455,7 @@ should be as follows:
|
|||
- Step2: Generate cropped images, `train_label.txt` and `test_label.txt` with the following command (the cropped images will be saved to `data/totaltext/dst_imgs/`):
|
||||
|
||||
```bash
|
||||
python tools/data/textrecog/totaltext_converter.py /path/to/totaltext
|
||||
python tools/dataset_converters/textrecog/totaltext_converter.py /path/to/totaltext
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -498,7 +498,7 @@ should be as follows:
|
|||
- Step3: Generate `train_{1,2,5,f}_label.txt`, `val_label.txt` and crop images using 4 processes with the following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textrecog/openvino_converter.py /path/to/openvino 4
|
||||
python tools/dataset_converters/textrecog/openvino_converter.py /path/to/openvino 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure
|
||||
|
@ -544,7 +544,7 @@ should be as follows:
|
|||
```bash
|
||||
# Add --preserve-vertical to preserve vertical texts for training, otherwise
|
||||
# vertical images will be filtered and stored in PATH/TO/detext/ignores
|
||||
python tools/data/textrecog/detext_converter.py PATH/TO/detext --nproc 4
|
||||
python tools/dataset_converters/textrecog/detext_converter.py PATH/TO/detext --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -583,7 +583,7 @@ should be as follows:
|
|||
```bash
|
||||
# Add --preserve-vertical to preserve vertical texts for training, otherwise
|
||||
# vertical images will be filtered and stored in PATH/TO/naf/ignores
|
||||
python tools/data/textrecog/naf_converter.py PATH/TO/naf --nproc 4
|
||||
python tools/dataset_converters/textrecog/naf_converter.py PATH/TO/naf --nproc 4
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
||||
|
@ -622,7 +622,7 @@ should be as follows:
|
|||
- Step3: Generate `train_label.jsonl` and `test_label.jsonl` and crop images using 4 processes with the following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textrecog/sroie_converter.py PATH/TO/sroie --nproc 4
|
||||
python tools/dataset_converters/textrecog/sroie_converter.py PATH/TO/sroie --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -661,7 +661,7 @@ The LV dataset has already provided cropped images and the corresponding annotat
|
|||
- Step2: Generate `train_label.jsonl`, `val.jsonl`, and `test.jsonl` with following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textdreog/lv_converter.py PATH/TO/lv
|
||||
python tools/dataset_converters/textdreog/lv_converter.py PATH/TO/lv
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -700,7 +700,7 @@ The LV dataset has already provided cropped images and the corresponding annotat
|
|||
# set by adding --val-ratio 0.2
|
||||
# Add --preserve-vertical to preserve vertical texts for training, otherwise
|
||||
# vertical images will be filtered and stored in PATH/TO/lsvt/ignores
|
||||
python tools/data/textdrecog/lsvt_converter.py PATH/TO/lsvt --nproc 4
|
||||
python tools/dataset_converters/textdrecog/lsvt_converter.py PATH/TO/lsvt --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -737,7 +737,7 @@ The LV dataset has already provided cropped images and the corresponding annotat
|
|||
- Step2: Generate `train_label.txt` and `test_label.txt` and crop images using 4 processes with following command (add `--preserve-vertical` if you wish to preserve the images containing vertical texts):
|
||||
|
||||
```bash
|
||||
python tools/data/textrecog/funsd_converter.py PATH/TO/funsd --nproc 4
|
||||
python tools/dataset_converters/textrecog/funsd_converter.py PATH/TO/funsd --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure
|
||||
|
@ -774,7 +774,7 @@ should be as follows:
|
|||
- Step2: Generate `train_label.txt`, `val_label.txt` and `test_label.txt` and crop images with the following command:
|
||||
|
||||
```bash
|
||||
python tools/data/textrecog/imgur_converter.py PATH/TO/imgur
|
||||
python tools/dataset_converters/textrecog/imgur_converter.py PATH/TO/imgur
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -805,7 +805,7 @@ should be as follows:
|
|||
- Step2: Extract zips:
|
||||
|
||||
```bash
|
||||
python tools/data/common/extract_kaist.py PATH/TO/kaist
|
||||
python tools/dataset_converters/common/extract_kaist.py PATH/TO/kaist
|
||||
```
|
||||
|
||||
- Step3: Generate `train_label.jsonl` and `val_label.jsonl` (optional) with following command:
|
||||
|
@ -814,7 +814,7 @@ should be as follows:
|
|||
# Since KAIST does not provide an official split, you can split the dataset by adding --val-ratio 0.2
|
||||
# Add --preserve-vertical to preserve vertical texts for training, otherwise
|
||||
# vertical images will be filtered and stored in PATH/TO/kaist/ignores
|
||||
python tools/data/textrecog/kaist_converter.py PATH/TO/kaist --nproc 4
|
||||
python tools/dataset_converters/textrecog/kaist_converter.py PATH/TO/kaist --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -847,7 +847,7 @@ should be as follows:
|
|||
# set by adding --val-ratio 0.2
|
||||
# Add --preserve-vertical to preserve vertical texts for training, otherwise
|
||||
# vertical images will be filtered and stored in PATH/TO/mtwi/ignores
|
||||
python tools/data/textrecog/mtwi_converter.py PATH/TO/mtwi --nproc 4
|
||||
python tools/dataset_converters/textrecog/mtwi_converter.py PATH/TO/mtwi --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -882,7 +882,7 @@ should be as follows:
|
|||
```bash
|
||||
# Add --preserve-vertical to preserve vertical texts for training, otherwise
|
||||
# vertical images will be filtered and stored in PATH/TO/mtwi/ignores
|
||||
python tools/data/textrecog/cocotext_converter.py PATH/TO/coco_textv2 --nproc 4
|
||||
python tools/dataset_converters/textrecog/cocotext_converter.py PATH/TO/coco_textv2 --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -919,7 +919,7 @@ should be as follows:
|
|||
# set by adding --val-ratio 0.2
|
||||
# Add --preserve-vertical to preserve vertical texts for training, otherwise
|
||||
# vertical images will be filtered and stored in PATH/TO/rects/ignores
|
||||
python tools/data/textrecog/rects_converter.py PATH/TO/rects --nproc 4
|
||||
python tools/dataset_converters/textrecog/rects_converter.py PATH/TO/rects --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -960,7 +960,7 @@ should be as follows:
|
|||
- Step3: Generate `train_label.jsonl` and `val_label.jsonl` (optional) and crop images using 4 processes with the following command (add `--preserve-vertical` if you wish to preserve the images containing vertical texts). Since the original dataset doesn't have a validation set, you may specify `--val-ratio` to split the dataset. E.g., if val-ratio is 0.2, then 20% of the data are left out as the validation set in this example.
|
||||
|
||||
```bash
|
||||
python tools/data/textrecog/ilst_converter.py PATH/TO/IIIT-ILST --nproc 4
|
||||
python tools/dataset_converters/textrecog/ilst_converter.py PATH/TO/IIIT-ILST --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -997,7 +997,7 @@ should be as follows:
|
|||
- Step2: Generate `train_label.jsonl`, `test_label.jsonl`, `unseen_test_label.jsonl`, and crop images using 4 processes with the following command (add `--preserve-vertical` if you wish to preserve the images containing vertical texts).
|
||||
|
||||
```bash
|
||||
python tools/data/textrecog/vintext_converter.py PATH/TO/vietnamese --nproc 4
|
||||
python tools/dataset_converters/textrecog/vintext_converter.py PATH/TO/vietnamese --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -1048,7 +1048,7 @@ should be as follows:
|
|||
- Step3: Generate `train_label.jsonl` and `val_label.jsonl` (optional) and crop images using 4 processes with the following command (add `--preserve-vertical` if you wish to preserve the images containing vertical texts). Since the original dataset doesn't have a validation set, you may specify `--val-ratio` to split the dataset. E.g., if test-ratio is 0.2, then 20% of the data are left out as the validation set in this example.
|
||||
|
||||
```bash
|
||||
python tools/data/textrecog/bid_converter.py dPATH/TO/BID --nproc 4
|
||||
python tools/dataset_converters/textrecog/bid_converter.py dPATH/TO/BID --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -1070,7 +1070,7 @@ should be as follows:
|
|||
```bash
|
||||
# Annotations of RCTW test split is not publicly available, split a validation set by adding --val-ratio 0.2
|
||||
# Add --preserve-vertical to preserve vertical texts for training, otherwise vertical images will be filtered and stored in PATH/TO/rctw/ignores
|
||||
python tools/data/textrecog/rctw_converter.py PATH/TO/rctw --nproc 4
|
||||
python tools/dataset_converters/textrecog/rctw_converter.py PATH/TO/rctw --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
@ -1122,7 +1122,7 @@ should be as follows:
|
|||
```bash
|
||||
# Collect word annotation from HierText --level word
|
||||
# Add --preserve-vertical to preserve vertical texts for training, otherwise vertical images will be filtered and stored in PATH/TO/HierText/ignores
|
||||
python tools/data/textrecog/hiertext_converter.py PATH/TO/HierText --level word --nproc 4
|
||||
python tools/dataset_converters/textrecog/hiertext_converter.py PATH/TO/HierText --level word --nproc 4
|
||||
```
|
||||
|
||||
- After running the above codes, the directory structure should be as follows:
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
"""This file is for benchmark data loading process. It can also be used to
|
||||
refresh the memcached cache. The command line to run this file is:
|
||||
|
||||
$ python -m cProfile -o program.prof tools/analysis/benchmark_processing.py
|
||||
configs/task/method/[config filename]
|
||||
|
||||
Note: When debugging, the `workers_per_gpu` in the config should be set to 0
|
||||
during benchmark.
|
||||
|
||||
It use cProfile to record cpu running time and output to program.prof
|
||||
To visualize cProfile output program.prof, use Snakeviz and run:
|
||||
$ snakeviz program.prof
|
||||
"""
|
||||
import argparse
|
||||
|
||||
import mmcv
|
||||
from mmcv import Config
|
||||
from mmdet.datasets import build_dataloader
|
||||
|
||||
from mmocr.registry import DATASETS
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Benchmark data loading')
|
||||
parser.add_argument('config', help='Train config file path.')
|
||||
args = parser.parse_args()
|
||||
cfg = Config.fromfile(args.config)
|
||||
|
||||
dataset = DATASETS.build(cfg.data.train)
|
||||
|
||||
# prepare data loaders
|
||||
if 'imgs_per_gpu' in cfg.data:
|
||||
cfg.data.samples_per_gpu = cfg.data.imgs_per_gpu
|
||||
|
||||
data_loader = build_dataloader(
|
||||
dataset,
|
||||
cfg.data.samples_per_gpu,
|
||||
cfg.data.workers_per_gpu,
|
||||
1,
|
||||
dist=False,
|
||||
seed=None)
|
||||
|
||||
# Start progress bar after first 5 batches
|
||||
prog_bar = mmcv.ProgressBar(
|
||||
len(dataset) - 5 * cfg.data.samples_per_gpu, start=False)
|
||||
for i, data in enumerate(data_loader):
|
||||
if i == 5:
|
||||
prog_bar.start()
|
||||
for _ in range(len(data['img'])):
|
||||
if i < 5:
|
||||
continue
|
||||
prog_bar.update()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -1,111 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import os.path as osp
|
||||
from argparse import ArgumentParser
|
||||
|
||||
import mmcv
|
||||
from mmcv.utils import ProgressBar
|
||||
|
||||
from mmocr.apis import init_detector, model_inference
|
||||
from mmocr.models import build_detector # noqa: F401
|
||||
from mmocr.utils import list_from_file, list_to_file
|
||||
|
||||
|
||||
def gen_target_path(target_root_path, src_name, suffix):
|
||||
"""Gen target file path.
|
||||
|
||||
Args:
|
||||
target_root_path (str): The target root path.
|
||||
src_name (str): The source file name.
|
||||
suffix (str): The suffix of target file.
|
||||
"""
|
||||
assert isinstance(target_root_path, str)
|
||||
assert isinstance(src_name, str)
|
||||
assert isinstance(suffix, str)
|
||||
|
||||
file_name = osp.split(src_name)[-1]
|
||||
name = osp.splitext(file_name)[0]
|
||||
return osp.join(target_root_path, name + suffix)
|
||||
|
||||
|
||||
def save_results(result, out_dir, img_name, score_thr=0.3):
|
||||
"""Save result of detected bounding boxes (quadrangle or polygon) to txt
|
||||
file.
|
||||
|
||||
Args:
|
||||
result (dict): Text Detection result for one image.
|
||||
img_name (str): Image file name.
|
||||
out_dir (str): Dir of txt files to save detected results.
|
||||
score_thr (float, optional): Score threshold to filter bboxes.
|
||||
"""
|
||||
assert 'boundary_result' in result
|
||||
assert score_thr > 0 and score_thr < 1
|
||||
|
||||
txt_file = gen_target_path(out_dir, img_name, '.txt')
|
||||
valid_boundary_res = [
|
||||
res for res in result['boundary_result'] if res[-1] > score_thr
|
||||
]
|
||||
lines = [
|
||||
','.join([str(round(x)) for x in row]) for row in valid_boundary_res
|
||||
]
|
||||
list_to_file(txt_file, lines)
|
||||
|
||||
|
||||
def main():
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument('img_root', type=str, help='Image root path')
|
||||
parser.add_argument('img_list', type=str, help='Image path list file')
|
||||
parser.add_argument('config', type=str, help='Config file')
|
||||
parser.add_argument('checkpoint', type=str, help='Checkpoint file')
|
||||
parser.add_argument(
|
||||
'--score-thr', type=float, default=0.5, help='Bbox score threshold')
|
||||
parser.add_argument(
|
||||
'--out-dir',
|
||||
type=str,
|
||||
default='./results',
|
||||
help='Dir to save '
|
||||
'visualize images '
|
||||
'and bbox')
|
||||
parser.add_argument(
|
||||
'--device', default='cuda:0', help='Device used for inference.')
|
||||
args = parser.parse_args()
|
||||
|
||||
assert 0 < args.score_thr < 1
|
||||
|
||||
# build the model from a config file and a checkpoint file
|
||||
model = init_detector(args.config, args.checkpoint, device=args.device)
|
||||
if hasattr(model, 'module'):
|
||||
model = model.module
|
||||
|
||||
# Start Inference
|
||||
out_vis_dir = osp.join(args.out_dir, 'out_vis_dir')
|
||||
mmcv.mkdir_or_exist(out_vis_dir)
|
||||
out_txt_dir = osp.join(args.out_dir, 'out_txt_dir')
|
||||
mmcv.mkdir_or_exist(out_txt_dir)
|
||||
|
||||
lines = list_from_file(args.img_list)
|
||||
progressbar = ProgressBar(task_num=len(lines))
|
||||
for line in lines:
|
||||
progressbar.update()
|
||||
img_path = osp.join(args.img_root, line.strip())
|
||||
if not osp.exists(img_path):
|
||||
raise FileNotFoundError(img_path)
|
||||
# Test a single image
|
||||
result = model_inference(model, img_path)
|
||||
img_name = osp.basename(img_path)
|
||||
# save result
|
||||
save_results(result, out_txt_dir, img_name, score_thr=args.score_thr)
|
||||
# show result
|
||||
out_file = osp.join(out_vis_dir, img_name)
|
||||
kwargs_dict = {
|
||||
'score_thr': args.score_thr,
|
||||
'show': False,
|
||||
'out_file': out_file
|
||||
}
|
||||
model.show_result(img_path, result, **kwargs_dict)
|
||||
|
||||
print(f'\nInference done, and results saved in {args.out_dir}\n')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -1,162 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import argparse
|
||||
import ast
|
||||
import os
|
||||
import os.path as osp
|
||||
|
||||
import mmcv
|
||||
import numpy as np
|
||||
import torch
|
||||
from mmcv import Config
|
||||
from mmcv.image import tensor2imgs
|
||||
from mmcv.parallel import MMDataParallel
|
||||
from mmcv.runner import load_checkpoint
|
||||
|
||||
from mmocr.datasets import build_dataloader
|
||||
from mmocr.models import build_detector
|
||||
from mmocr.registry import DATASETS
|
||||
|
||||
|
||||
def save_results(model, img_meta, gt_bboxes, result, out_dir):
|
||||
assert 'filename' in img_meta, ('Please add "filename" '
|
||||
'to "meta_keys" in config.')
|
||||
assert 'ori_texts' in img_meta, ('Please add "ori_texts" '
|
||||
'to "meta_keys" in config.')
|
||||
|
||||
out_json_file = osp.join(out_dir,
|
||||
osp.basename(img_meta['filename']) + '.json')
|
||||
|
||||
idx_to_cls = {}
|
||||
if model.module.class_list is not None:
|
||||
for line in mmcv.list_from_file(model.module.class_list):
|
||||
class_idx, class_label = line.strip().split()
|
||||
idx_to_cls[int(class_idx)] = class_label
|
||||
|
||||
json_result = [{
|
||||
'text':
|
||||
text,
|
||||
'box':
|
||||
box,
|
||||
'pred':
|
||||
idx_to_cls.get(
|
||||
pred.argmax(-1).cpu().item(),
|
||||
pred.argmax(-1).cpu().item()),
|
||||
'conf':
|
||||
pred.max(-1)[0].cpu().item()
|
||||
} for text, box, pred in zip(img_meta['ori_texts'], gt_bboxes,
|
||||
result['nodes'])]
|
||||
|
||||
mmcv.dump(json_result, out_json_file)
|
||||
|
||||
|
||||
def test(model, data_loader, show=False, out_dir=None):
|
||||
model.eval()
|
||||
results = []
|
||||
dataset = data_loader.dataset
|
||||
prog_bar = mmcv.ProgressBar(len(dataset))
|
||||
for i, data in enumerate(data_loader):
|
||||
with torch.no_grad():
|
||||
result = model(return_loss=False, rescale=True, **data)
|
||||
|
||||
batch_size = len(result)
|
||||
if show or out_dir:
|
||||
img_tensor = data['img'].data[0]
|
||||
img_metas = data['img_metas'].data[0]
|
||||
if np.prod(img_tensor.shape) == 0:
|
||||
imgs = [mmcv.imread(m['filename']) for m in img_metas]
|
||||
else:
|
||||
imgs = tensor2imgs(img_tensor, **img_metas[0]['img_norm_cfg'])
|
||||
assert len(imgs) == len(img_metas)
|
||||
gt_bboxes = [data['gt_bboxes'].data[0][0].numpy().tolist()]
|
||||
|
||||
for i, (img, img_meta) in enumerate(zip(imgs, img_metas)):
|
||||
if 'img_shape' in img_meta:
|
||||
h, w, _ = img_meta['img_shape']
|
||||
img_show = img[:h, :w, :]
|
||||
else:
|
||||
img_show = img
|
||||
|
||||
if out_dir:
|
||||
out_file = osp.join(out_dir,
|
||||
osp.basename(img_meta['filename']))
|
||||
else:
|
||||
out_file = None
|
||||
|
||||
model.module.show_result(
|
||||
img_show,
|
||||
result[i],
|
||||
gt_bboxes[i],
|
||||
show=show,
|
||||
out_file=out_file)
|
||||
|
||||
if out_dir:
|
||||
save_results(model, img_meta, gt_bboxes[i], result[i],
|
||||
out_dir)
|
||||
|
||||
for _ in range(batch_size):
|
||||
prog_bar.update()
|
||||
return results
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='MMOCR visualize for kie model.')
|
||||
parser.add_argument('config', help='Test config file path.')
|
||||
parser.add_argument('checkpoint', help='Checkpoint file.')
|
||||
parser.add_argument('--show', action='store_true', help='Show results.')
|
||||
parser.add_argument(
|
||||
'--out-dir',
|
||||
help='Directory where the output images and results will be saved.')
|
||||
parser.add_argument('--local_rank', type=int, default=0)
|
||||
parser.add_argument(
|
||||
'--device',
|
||||
help='Use int or int list for gpu. Default is cpu',
|
||||
default=None)
|
||||
args = parser.parse_args()
|
||||
if 'LOCAL_RANK' not in os.environ:
|
||||
os.environ['LOCAL_RANK'] = str(args.local_rank)
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
assert args.show or args.out_dir, ('Please specify at least one '
|
||||
'operation (show the results / save )'
|
||||
'the results with the argument '
|
||||
'"--show" or "--out-dir".')
|
||||
device = args.device
|
||||
if device is not None:
|
||||
device = ast.literal_eval(f'[{device}]')
|
||||
cfg = Config.fromfile(args.config)
|
||||
# import modules from string list.
|
||||
if cfg.get('custom_imports', None):
|
||||
from mmcv.utils import import_modules_from_strings
|
||||
import_modules_from_strings(**cfg['custom_imports'])
|
||||
# set cudnn_benchmark
|
||||
if cfg.get('cudnn_benchmark', False):
|
||||
torch.backends.cudnn.benchmark = True
|
||||
|
||||
distributed = False
|
||||
|
||||
# build the dataloader
|
||||
dataset = DATASETS.build(cfg.data.test)
|
||||
data_loader = build_dataloader(
|
||||
dataset,
|
||||
samples_per_gpu=1,
|
||||
workers_per_gpu=cfg.data.workers_per_gpu,
|
||||
dist=distributed,
|
||||
shuffle=False)
|
||||
|
||||
# build the model and load checkpoint
|
||||
cfg.model.train_cfg = None
|
||||
model = build_detector(cfg.model, test_cfg=cfg.get('test_cfg'))
|
||||
load_checkpoint(model, args.checkpoint, map_location='cpu')
|
||||
|
||||
model = MMDataParallel(model, device_ids=device)
|
||||
test(model, data_loader, args.show, args.out_dir)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -1,55 +0,0 @@
|
|||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import argparse
|
||||
import warnings
|
||||
|
||||
from mmcv import Config, DictAction
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description='Print the whole config')
|
||||
parser.add_argument('config', help='config file path')
|
||||
parser.add_argument(
|
||||
'--options',
|
||||
nargs='+',
|
||||
action=DictAction,
|
||||
help='override some settings in the used config, the key-value pair '
|
||||
'in xxx=yyy format will be merged into config file (deprecate), '
|
||||
'change to --cfg-options instead.')
|
||||
parser.add_argument(
|
||||
'--cfg-options',
|
||||
nargs='+',
|
||||
action=DictAction,
|
||||
help='override some settings in the used config, the key-value pair '
|
||||
'in xxx=yyy format will be merged into config file. If the value to '
|
||||
'be overwritten is a list, it should be like key="[a,b]" or key=a,b '
|
||||
'It also allows nested list/tuple values, e.g. key="[(a,b),(c,d)]" '
|
||||
'Note that the quotation marks are necessary and that no white space '
|
||||
'is allowed.')
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.options and args.cfg_options:
|
||||
raise ValueError(
|
||||
'--options and --cfg-options cannot be both '
|
||||
'specified, --options is deprecated in favor of --cfg-options')
|
||||
if args.options:
|
||||
warnings.warn('--options is deprecated in favor of --cfg-options')
|
||||
args.cfg_options = args.options
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
|
||||
cfg = Config.fromfile(args.config)
|
||||
if args.cfg_options is not None:
|
||||
cfg.merge_from_dict(args.cfg_options)
|
||||
# import modules from string list.
|
||||
if cfg.get('custom_imports', None):
|
||||
from mmcv.utils import import_modules_from_strings
|
||||
import_modules_from_strings(**cfg['custom_imports'])
|
||||
print(f'Config:\n{cfg.pretty_text}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -1,125 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import os.path as osp
|
||||
import shutil
|
||||
import time
|
||||
from argparse import ArgumentParser
|
||||
from itertools import compress
|
||||
|
||||
import mmcv
|
||||
from mmcv.utils import ProgressBar
|
||||
|
||||
from mmocr.apis import init_detector, model_inference
|
||||
from mmocr.core.evaluation.ocr_metric import eval_ocr_metric
|
||||
from mmocr.models import build_detector # noqa: F401
|
||||
from mmocr.registry import DATASETS # noqa: F401
|
||||
from mmocr.utils import get_root_logger, list_from_file, list_to_file
|
||||
|
||||
|
||||
def save_results(img_paths, pred_labels, gt_labels, res_dir):
|
||||
"""Save predicted results to txt file.
|
||||
|
||||
Args:
|
||||
img_paths (list[str])
|
||||
pred_labels (list[str])
|
||||
gt_labels (list[str])
|
||||
res_dir (str)
|
||||
"""
|
||||
assert len(img_paths) == len(pred_labels) == len(gt_labels)
|
||||
corrects = [pred == gt for pred, gt in zip(pred_labels, gt_labels)]
|
||||
wrongs = [not c for c in corrects]
|
||||
lines = [
|
||||
f'{img} {pred} {gt}'
|
||||
for img, pred, gt in zip(img_paths, pred_labels, gt_labels)
|
||||
]
|
||||
list_to_file(osp.join(res_dir, 'results.txt'), lines)
|
||||
list_to_file(osp.join(res_dir, 'correct.txt'), compress(lines, corrects))
|
||||
list_to_file(osp.join(res_dir, 'wrong.txt'), compress(lines, wrongs))
|
||||
|
||||
|
||||
def main():
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument('img_root_path', type=str, help='Image root path')
|
||||
parser.add_argument('img_list', type=str, help='Image path list file')
|
||||
parser.add_argument('config', type=str, help='Config file')
|
||||
parser.add_argument('checkpoint', type=str, help='Checkpoint file')
|
||||
parser.add_argument(
|
||||
'--out-dir', type=str, default='./results', help='Dir to save results')
|
||||
parser.add_argument(
|
||||
'--show', action='store_true', help='show image or save')
|
||||
parser.add_argument(
|
||||
'--device', default='cuda:0', help='Device used for inference.')
|
||||
args = parser.parse_args()
|
||||
|
||||
# init the logger before other steps
|
||||
timestamp = time.strftime('%Y%m%d_%H%M%S', time.localtime())
|
||||
log_file = osp.join(args.out_dir, f'{timestamp}.log')
|
||||
logger = get_root_logger(log_file=log_file, log_level='INFO')
|
||||
|
||||
# build the model from a config file and a checkpoint file
|
||||
model = init_detector(args.config, args.checkpoint, device=args.device)
|
||||
if hasattr(model, 'module'):
|
||||
model = model.module
|
||||
|
||||
# Start Inference
|
||||
out_vis_dir = osp.join(args.out_dir, 'out_vis_dir')
|
||||
mmcv.mkdir_or_exist(out_vis_dir)
|
||||
correct_vis_dir = osp.join(args.out_dir, 'correct')
|
||||
mmcv.mkdir_or_exist(correct_vis_dir)
|
||||
wrong_vis_dir = osp.join(args.out_dir, 'wrong')
|
||||
mmcv.mkdir_or_exist(wrong_vis_dir)
|
||||
img_paths, pred_labels, gt_labels = [], [], []
|
||||
|
||||
lines = list_from_file(args.img_list)
|
||||
progressbar = ProgressBar(task_num=len(lines))
|
||||
num_gt_label = 0
|
||||
for line in lines:
|
||||
progressbar.update()
|
||||
item_list = line.strip().split()
|
||||
img_file = item_list[0]
|
||||
gt_label = ''
|
||||
if len(item_list) >= 2:
|
||||
gt_label = item_list[1]
|
||||
num_gt_label += 1
|
||||
img_path = osp.join(args.img_root_path, img_file)
|
||||
if not osp.exists(img_path):
|
||||
raise FileNotFoundError(img_path)
|
||||
# Test a single image
|
||||
result = model_inference(model, img_path)
|
||||
pred_label = result['text']
|
||||
|
||||
out_img_name = '_'.join(img_file.split('/'))
|
||||
out_file = osp.join(out_vis_dir, out_img_name)
|
||||
kwargs_dict = {
|
||||
'gt_label': gt_label,
|
||||
'show': args.show,
|
||||
'out_file': '' if args.show else out_file
|
||||
}
|
||||
model.show_result(img_path, result, **kwargs_dict)
|
||||
if gt_label != '':
|
||||
if gt_label == pred_label:
|
||||
dst_file = osp.join(correct_vis_dir, out_img_name)
|
||||
else:
|
||||
dst_file = osp.join(wrong_vis_dir, out_img_name)
|
||||
shutil.copy(out_file, dst_file)
|
||||
img_paths.append(img_path)
|
||||
gt_labels.append(gt_label)
|
||||
pred_labels.append(pred_label)
|
||||
|
||||
# Save results
|
||||
save_results(img_paths, pred_labels, gt_labels, args.out_dir)
|
||||
|
||||
if num_gt_label == len(pred_labels):
|
||||
# eval
|
||||
eval_results = eval_ocr_metric(pred_labels, gt_labels)
|
||||
logger.info('\n' + '-' * 100)
|
||||
info = ('eval on testset with img_root_path '
|
||||
f'{args.img_root_path} and img_list {args.img_list}\n')
|
||||
logger.info(info)
|
||||
logger.info(eval_results)
|
||||
|
||||
print(f'\nInference done, and results saved in {args.out_dir}\n')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue