Update cvdataset-layoutlmv3.py
Browse files- cvdataset-layoutlmv3.py +16 -10
cvdataset-layoutlmv3.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 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},
|
|
@@ -30,14 +31,15 @@ def normalize_bbox(bbox, size):
|
|
| 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 |
]
|
|
@@ -50,9 +52,8 @@ class DatasetConfig(datasets.BuilderConfig):
|
|
| 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 |
]
|
|
@@ -67,7 +68,12 @@ class WildReceipt(datasets.GeneratorBasedBuilder):
|
|
| 67 |
"bboxes": datasets.Sequence(datasets.Sequence(datasets.Value("int64"))),
|
| 68 |
"ner_tags": datasets.Sequence(
|
| 69 |
datasets.features.ClassLabel(
|
| 70 |
-
names=['person_name', '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
)
|
| 72 |
),
|
| 73 |
"image_path": datasets.Value("string"),
|
|
@@ -86,16 +92,16 @@ class WildReceipt(datasets.GeneratorBasedBuilder):
|
|
| 86 |
|
| 87 |
return [
|
| 88 |
datasets.SplitGenerator(
|
| 89 |
-
name=datasets.Split.TRAIN, gen_kwargs={"filepath": dest/"
|
| 90 |
),
|
| 91 |
datasets.SplitGenerator(
|
| 92 |
-
name=datasets.Split.TEST, gen_kwargs={"filepath": dest/"
|
| 93 |
),
|
| 94 |
]
|
| 95 |
|
| 96 |
def _generate_examples(self, filepath, dest):
|
| 97 |
|
| 98 |
-
df = pd.read_csv(dest/'
|
| 99 |
id2labels = dict(zip(df[0].tolist(), df[1].tolist()))
|
| 100 |
|
| 101 |
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
from pathlib import Path
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import pandas as pd
|
| 6 |
+
import datasets
|
| 7 |
|
| 8 |
logger = datasets.logging.get_logger(__name__)
|
| 9 |
+
|
| 10 |
_CITATION = """\
|
| 11 |
@article{LayoutLmv3 for CV extractions,
|
| 12 |
title={LayoutLmv3for Key Information Extraction},
|
|
|
|
| 31 |
int(1000 * bbox[2] / size[0]),
|
| 32 |
int(1000 * bbox[3] / size[1]),
|
| 33 |
]
|
| 34 |
+
|
| 35 |
def _get_drive_url(url):
|
| 36 |
base_url = 'https://drive.google.com/uc?id='
|
| 37 |
split_url = url.split('/')
|
| 38 |
|
| 39 |
return base_url + split_url[5]
|
| 40 |
+
|
| 41 |
_URLS = [
|
| 42 |
+
_get_drive_url("https://drive.google.com/file/d/1sC6ZlC3wMg6NtvAVhQHzKKq7nvT7Msb6/"),
|
| 43 |
_get_drive_url("https://drive.google.com/file/d/11SRDeRKUr8XacB7tauiGjkw1PXDGFKUx/"),
|
| 44 |
_get_drive_url("https://drive.google.com/file/d/1KdDBmGP96lFc7jv2Bf4eqrO121ST-TCh/"),
|
| 45 |
]
|
|
|
|
| 52 |
**kwargs: keyword arguments forwarded to super.
|
| 53 |
"""
|
| 54 |
super(DatasetConfig, self).__init__(**kwargs)
|
| 55 |
+
|
| 56 |
+
class CVDataset(datasets.GeneratorBasedBuilder):
|
|
|
|
| 57 |
BUILDER_CONFIGS = [
|
| 58 |
DatasetConfig(name="CV Extractions", version=datasets.Version("1.0.0"), description="CV dataset"),
|
| 59 |
]
|
|
|
|
| 68 |
"bboxes": datasets.Sequence(datasets.Sequence(datasets.Value("int64"))),
|
| 69 |
"ner_tags": datasets.Sequence(
|
| 70 |
datasets.features.ClassLabel(
|
| 71 |
+
names=['person_name', 'dob_field', 'gender_field', \
|
| 72 |
+
'phonenumber_field', 'email_field', \
|
| 73 |
+
'address_field', 'socical_address_field', \
|
| 74 |
+
'education', 'education_name', 'education_time', \
|
| 75 |
+
'experience', 'experience_name', 'experience_time', \
|
| 76 |
+
'information', 'undefined']
|
| 77 |
)
|
| 78 |
),
|
| 79 |
"image_path": datasets.Value("string"),
|
|
|
|
| 92 |
|
| 93 |
return [
|
| 94 |
datasets.SplitGenerator(
|
| 95 |
+
name=datasets.Split.TRAIN, gen_kwargs={"filepath": dest/"update_train.txt", "dest": dest}
|
| 96 |
),
|
| 97 |
datasets.SplitGenerator(
|
| 98 |
+
name=datasets.Split.TEST, gen_kwargs={"filepath": dest/"update_test.txt", "dest": dest}
|
| 99 |
),
|
| 100 |
]
|
| 101 |
|
| 102 |
def _generate_examples(self, filepath, dest):
|
| 103 |
|
| 104 |
+
df = pd.read_csv(dest/'update_class_list.txt', delimiter='\s', header=None)
|
| 105 |
id2labels = dict(zip(df[0].tolist(), df[1].tolist()))
|
| 106 |
|
| 107 |
|