should be ready | dunno about metadata jsonlines
Browse files- unit-test_PDFfolder.py +21 -11
unit-test_PDFfolder.py
CHANGED
@@ -51,26 +51,26 @@ class PdfFolder(datasets.GeneratorBasedBuilder):
|
|
51 |
|
52 |
archive_path = dl_manager.download(_URL)
|
53 |
|
54 |
-
import pdb; pdb.set_trace() # breakpoint aef4d417 //
|
55 |
-
|
56 |
-
|
57 |
return [
|
58 |
datasets.SplitGenerator(
|
59 |
name=datasets.Split.TRAIN,
|
60 |
gen_kwargs={
|
61 |
"archive_iterator": dl_manager.iter_archive(archive_path),
|
|
|
62 |
},
|
63 |
),
|
64 |
datasets.SplitGenerator(
|
65 |
name=datasets.Split.TEST,
|
66 |
gen_kwargs={
|
67 |
"archive_iterator": dl_manager.iter_archive(archive_path),
|
|
|
68 |
},
|
69 |
),
|
70 |
datasets.SplitGenerator(
|
71 |
name=datasets.Split.VALIDATION,
|
72 |
gen_kwargs={
|
73 |
"archive_iterator": dl_manager.iter_archive(archive_path),
|
|
|
74 |
},
|
75 |
),
|
76 |
]
|
@@ -91,14 +91,24 @@ class PdfFolder(datasets.GeneratorBasedBuilder):
|
|
91 |
|
92 |
# return splits
|
93 |
|
94 |
-
def _generate_examples(self, archive_path):
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
if path.suffix in extensions:
|
|
|
100 |
|
101 |
-
images = pdf2image.
|
|
|
102 |
|
103 |
-
|
104 |
-
|
|
|
51 |
|
52 |
archive_path = dl_manager.download(_URL)
|
53 |
|
|
|
|
|
|
|
54 |
return [
|
55 |
datasets.SplitGenerator(
|
56 |
name=datasets.Split.TRAIN,
|
57 |
gen_kwargs={
|
58 |
"archive_iterator": dl_manager.iter_archive(archive_path),
|
59 |
+
"supposed_labelset": "train"
|
60 |
},
|
61 |
),
|
62 |
datasets.SplitGenerator(
|
63 |
name=datasets.Split.TEST,
|
64 |
gen_kwargs={
|
65 |
"archive_iterator": dl_manager.iter_archive(archive_path),
|
66 |
+
"supposed_labelset": "test"
|
67 |
},
|
68 |
),
|
69 |
datasets.SplitGenerator(
|
70 |
name=datasets.Split.VALIDATION,
|
71 |
gen_kwargs={
|
72 |
"archive_iterator": dl_manager.iter_archive(archive_path),
|
73 |
+
"supposed_labelset": "val"
|
74 |
},
|
75 |
),
|
76 |
]
|
|
|
91 |
|
92 |
# return splits
|
93 |
|
94 |
+
def _generate_examples(self, archive_path, supposed_labelset):
|
95 |
+
|
96 |
+
#could also get the label from somewhere else
|
97 |
+
|
98 |
+
#data/train/categoryB/581261-brown-invoice-10-29-11-04-12-2-13530037073412-pdf.pdf
|
99 |
+
#folder/labelset/label/filename
|
100 |
+
|
101 |
+
extensions = {".pdf", ".PDF"}
|
102 |
+
for file_path, file_obj in archive_iterator:
|
103 |
+
folder, labelset, label, filename = file_path.split("/")
|
104 |
+
if labelset != supposed_labelset:
|
105 |
+
continue
|
106 |
+
path = Path(filename)
|
107 |
if path.suffix in extensions:
|
108 |
+
import pdb; pdb.set_trace() # breakpoint a2febfcf //
|
109 |
|
110 |
+
images = pdf2image.convert_from_path(path.posix())
|
111 |
+
yield file_path, {"file": images, "labels": label}
|
112 |
|
113 |
+
#labels = self.info.features["labels"]
|
114 |
+
#labels.encode_example(path.parent.name.lower())
|