shifted to binary, do to images map later
Browse files- rvl_cdip_multi.py +10 -8
- test_loader.py +1 -1
rvl_cdip_multi.py
CHANGED
@@ -4,10 +4,11 @@ from typing import List
|
|
4 |
import datasets
|
5 |
import pdf2image
|
6 |
from tqdm import tqdm
|
|
|
7 |
|
8 |
datasets.logging.set_verbosity_info()
|
9 |
logger = datasets.logging.get_logger(__name__)
|
10 |
-
|
11 |
|
12 |
_CITATION = """\
|
13 |
@inproceedings{jordyvlRVLmulti,
|
@@ -23,8 +24,6 @@ _DESCRIPTION = """\
|
|
23 |
blabla
|
24 |
"""
|
25 |
|
26 |
-
_VERSION = "1.0.0"
|
27 |
-
|
28 |
_HOMEPAGE = "TBD"
|
29 |
|
30 |
|
@@ -74,10 +73,11 @@ def batched_conversion(pdf_file):
|
|
74 |
)
|
75 |
return images
|
76 |
|
|
|
|
|
|
|
77 |
|
78 |
class RvlCdipMulti(datasets.GeneratorBasedBuilder):
|
79 |
-
VERSION = datasets.Version("1.0.0")
|
80 |
-
|
81 |
BUILDER_CONFIGS = [
|
82 |
datasets.BuilderConfig(
|
83 |
name="default",
|
@@ -123,7 +123,7 @@ class RvlCdipMulti(datasets.GeneratorBasedBuilder):
|
|
123 |
description=_DESCRIPTION,
|
124 |
features=datasets.Features(
|
125 |
{
|
126 |
-
"file": datasets.Sequence(datasets.Image()),
|
127 |
"labels": datasets.features.ClassLabel(names=_CLASSES),
|
128 |
}
|
129 |
),
|
@@ -166,12 +166,14 @@ class RvlCdipMulti(datasets.GeneratorBasedBuilder):
|
|
166 |
|
167 |
for i, path in tqdm(enumerate(Path(archive_path).glob("**/*/*")), desc=f"{archive_path}"):
|
168 |
if path.suffix in extensions:
|
169 |
-
|
170 |
try:
|
171 |
-
images =
|
|
|
172 |
yield path.name, {
|
173 |
"file": images,
|
174 |
"labels": labels.encode_example(path.parent.name.lower()),
|
175 |
}
|
176 |
except Exception as e:
|
177 |
logger.warning(f"{e} failed to parse {i}")
|
|
|
|
|
|
4 |
import datasets
|
5 |
import pdf2image
|
6 |
from tqdm import tqdm
|
7 |
+
import io
|
8 |
|
9 |
datasets.logging.set_verbosity_info()
|
10 |
logger = datasets.logging.get_logger(__name__)
|
11 |
+
MODE="binary"
|
12 |
|
13 |
_CITATION = """\
|
14 |
@inproceedings{jordyvlRVLmulti,
|
|
|
24 |
blabla
|
25 |
"""
|
26 |
|
|
|
|
|
27 |
_HOMEPAGE = "TBD"
|
28 |
|
29 |
|
|
|
73 |
)
|
74 |
return images
|
75 |
|
76 |
+
def open_pdf_binary(pdf_file):
|
77 |
+
with open(pdf_file, "rb") as f:
|
78 |
+
return f.read()
|
79 |
|
80 |
class RvlCdipMulti(datasets.GeneratorBasedBuilder):
|
|
|
|
|
81 |
BUILDER_CONFIGS = [
|
82 |
datasets.BuilderConfig(
|
83 |
name="default",
|
|
|
123 |
description=_DESCRIPTION,
|
124 |
features=datasets.Features(
|
125 |
{
|
126 |
+
"file": datasets.Value("binary"), #datasets.Sequence(datasets.Image()),
|
127 |
"labels": datasets.features.ClassLabel(names=_CLASSES),
|
128 |
}
|
129 |
),
|
|
|
166 |
|
167 |
for i, path in tqdm(enumerate(Path(archive_path).glob("**/*/*")), desc=f"{archive_path}"):
|
168 |
if path.suffix in extensions:
|
|
|
169 |
try:
|
170 |
+
images = open_pdf_binary(path)
|
171 |
+
#images = batched_conversion(path)
|
172 |
yield path.name, {
|
173 |
"file": images,
|
174 |
"labels": labels.encode_example(path.parent.name.lower()),
|
175 |
}
|
176 |
except Exception as e:
|
177 |
logger.warning(f"{e} failed to parse {i}")
|
178 |
+
|
179 |
+
# can do a map afterwards
|
test_loader.py
CHANGED
@@ -12,7 +12,7 @@ else:
|
|
12 |
|
13 |
|
14 |
if stepwise:
|
15 |
-
ds = load_dataset(
|
16 |
import pdb; pdb.set_trace() # breakpoint 1898e7e0 //
|
17 |
|
18 |
builder = load_dataset_builder(DATASET)
|
|
|
12 |
|
13 |
|
14 |
if stepwise:
|
15 |
+
ds = load_dataset(DATASET, cache_dir="/mnt/lerna/data/HFcache")
|
16 |
import pdb; pdb.set_trace() # breakpoint 1898e7e0 //
|
17 |
|
18 |
builder = load_dataset_builder(DATASET)
|