fix issue dataset split failed
#14
by
nvm472001
- opened
- cvdataset-layoutlmv3.py +17 -27
cvdataset-layoutlmv3.py
CHANGED
@@ -1,16 +1,15 @@
|
|
1 |
import json
|
2 |
-
import
|
3 |
-
import datasets
|
4 |
from pathlib import Path
|
|
|
5 |
from PIL import Image
|
6 |
-
|
7 |
|
8 |
logger = datasets.logging.get_logger(__name__)
|
9 |
-
|
10 |
_CITATION = """\
|
11 |
@article{LayoutLmv3 for CV extractions,
|
12 |
title={LayoutLmv3for Key Information Extraction},
|
13 |
-
author={
|
14 |
year={2022},
|
15 |
}
|
16 |
"""
|
@@ -19,12 +18,10 @@ CV is a collection of receipts. It contains, for each photo about cv personal, a
|
|
19 |
https://arxiv.org/abs/2103.14470
|
20 |
"""
|
21 |
|
22 |
-
|
23 |
def load_image(image_path):
|
24 |
-
image = Image.open(image_path)
|
25 |
w, h = image.size
|
26 |
-
|
27 |
-
return image, (w, h)
|
28 |
|
29 |
def normalize_bbox(bbox, size):
|
30 |
return [
|
@@ -33,34 +30,31 @@ def normalize_bbox(bbox, size):
|
|
33 |
int(1000 * bbox[2] / size[0]),
|
34 |
int(1000 * bbox[3] / size[1]),
|
35 |
]
|
36 |
-
|
37 |
-
|
38 |
def _get_drive_url(url):
|
39 |
base_url = 'https://drive.google.com/uc?id='
|
40 |
split_url = url.split('/')
|
41 |
|
42 |
return base_url + split_url[5]
|
43 |
-
|
44 |
_URLS = [
|
45 |
-
_get_drive_url("https://drive.google.com/file/d/11SRDeRKUr8XacB7tauiGjkw1PXDGFKUx/")
|
46 |
-
_get_drive_url("https://drive.google.com/file/d/14oyIAdWyTNEfDEDOJ0-sYDy1hVeAD5Tt/"),
|
47 |
-
_get_drive_url("https://drive.google.com/file/d/1YoOr-A55hnjjH96QMFKwHFi26yPYmln9/"),
|
48 |
-
_get_drive_url("https://drive.google.com/file/d/1bqESdP3UhQ5H9ZEnn5NsH44FZmiQa0G_/"),
|
49 |
_get_drive_url("https://drive.google.com/file/d/1KdDBmGP96lFc7jv2Bf4eqrO121ST-TCh/"),
|
50 |
]
|
51 |
|
52 |
-
class
|
53 |
"""BuilderConfig for WildReceipt Dataset"""
|
54 |
def __init__(self, **kwargs):
|
55 |
"""BuilderConfig for WildReceipt Dataset.
|
56 |
Args:
|
57 |
**kwargs: keyword arguments forwarded to super.
|
58 |
"""
|
59 |
-
super(
|
60 |
-
|
61 |
-
|
|
|
62 |
BUILDER_CONFIGS = [
|
63 |
-
|
64 |
]
|
65 |
|
66 |
def _info(self):
|
@@ -73,12 +67,7 @@ class CVDataset(datasets.GeneratorBasedBuilder):
|
|
73 |
"bboxes": datasets.Sequence(datasets.Sequence(datasets.Value("int64"))),
|
74 |
"ner_tags": datasets.Sequence(
|
75 |
datasets.features.ClassLabel(
|
76 |
-
names=['person_name', '
|
77 |
-
'phonenumber_field', 'email_field', \
|
78 |
-
'address_field', 'socical_address_field', \
|
79 |
-
'education', 'education_name', 'education_time', \
|
80 |
-
'experience', 'experience_name', 'experience_time', \
|
81 |
-
'information', 'undefined']
|
82 |
)
|
83 |
),
|
84 |
"image_path": datasets.Value("string"),
|
@@ -109,6 +98,7 @@ class CVDataset(datasets.GeneratorBasedBuilder):
|
|
109 |
df = pd.read_csv(dest/'class_list.txt', delimiter='\s', header=None)
|
110 |
id2labels = dict(zip(df[0].tolist(), df[1].tolist()))
|
111 |
|
|
|
112 |
logger.info("⏳ Generating examples from = %s", filepath)
|
113 |
|
114 |
item_list = []
|
|
|
1 |
import json
|
2 |
+
import os
|
|
|
3 |
from pathlib import Path
|
4 |
+
import datasets
|
5 |
from PIL import Image
|
6 |
+
import pandas as pd
|
7 |
|
8 |
logger = datasets.logging.get_logger(__name__)
|
|
|
9 |
_CITATION = """\
|
10 |
@article{LayoutLmv3 for CV extractions,
|
11 |
title={LayoutLmv3for Key Information Extraction},
|
12 |
+
author={MisaR&D Team},
|
13 |
year={2022},
|
14 |
}
|
15 |
"""
|
|
|
18 |
https://arxiv.org/abs/2103.14470
|
19 |
"""
|
20 |
|
|
|
21 |
def load_image(image_path):
|
22 |
+
image = Image.open(image_path)
|
23 |
w, h = image.size
|
24 |
+
return image, (w,h)
|
|
|
25 |
|
26 |
def normalize_bbox(bbox, size):
|
27 |
return [
|
|
|
30 |
int(1000 * bbox[2] / size[0]),
|
31 |
int(1000 * bbox[3] / size[1]),
|
32 |
]
|
33 |
+
|
|
|
34 |
def _get_drive_url(url):
|
35 |
base_url = 'https://drive.google.com/uc?id='
|
36 |
split_url = url.split('/')
|
37 |
|
38 |
return base_url + split_url[5]
|
39 |
+
|
40 |
_URLS = [
|
41 |
+
_get_drive_url("https://drive.google.com/file/d/11SRDeRKUr8XacB7tauiGjkw1PXDGFKUx/")
|
|
|
|
|
|
|
42 |
_get_drive_url("https://drive.google.com/file/d/1KdDBmGP96lFc7jv2Bf4eqrO121ST-TCh/"),
|
43 |
]
|
44 |
|
45 |
+
class DatasetConfig(datasets.BuilderConfig):
|
46 |
"""BuilderConfig for WildReceipt Dataset"""
|
47 |
def __init__(self, **kwargs):
|
48 |
"""BuilderConfig for WildReceipt Dataset.
|
49 |
Args:
|
50 |
**kwargs: keyword arguments forwarded to super.
|
51 |
"""
|
52 |
+
super(DatasetConfig, self).__init__(**kwargs)
|
53 |
+
|
54 |
+
|
55 |
+
class WildReceipt(datasets.GeneratorBasedBuilder):
|
56 |
BUILDER_CONFIGS = [
|
57 |
+
DatasetConfig(name="CV Extractions", version=datasets.Version("1.0.0"), description="CV dataset"),
|
58 |
]
|
59 |
|
60 |
def _info(self):
|
|
|
67 |
"bboxes": datasets.Sequence(datasets.Sequence(datasets.Value("int64"))),
|
68 |
"ner_tags": datasets.Sequence(
|
69 |
datasets.features.ClassLabel(
|
70 |
+
names=['person_name', 'dob_key', 'dob_value', 'gender_key', 'gender_value', 'phonenumber_key', 'phonenumber_value', 'email_key', 'email_value', 'address_key', 'address_value', 'socical_address_value', 'education', 'education_name', 'education_time', 'experience', 'experience_name', 'experience_time', 'information', 'undefined']
|
|
|
|
|
|
|
|
|
|
|
71 |
)
|
72 |
),
|
73 |
"image_path": datasets.Value("string"),
|
|
|
98 |
df = pd.read_csv(dest/'class_list.txt', delimiter='\s', header=None)
|
99 |
id2labels = dict(zip(df[0].tolist(), df[1].tolist()))
|
100 |
|
101 |
+
|
102 |
logger.info("⏳ Generating examples from = %s", filepath)
|
103 |
|
104 |
item_list = []
|