Update layoutlmv3.py
Browse files- layoutlmv3.py +26 -20
layoutlmv3.py
CHANGED
|
@@ -116,25 +116,31 @@ class Funsd(datasets.GeneratorBasedBuilder):
|
|
| 116 |
image, size = load_image(image_path)
|
| 117 |
for state in data:
|
| 118 |
for item in state["form"]:
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
yield guid, {"id": str(guid), "tokens": tokens, "bboxes": bboxes, "ner_tags": ner_tags,
|
| 140 |
"image": image}
|
|
|
|
| 116 |
image, size = load_image(image_path)
|
| 117 |
for state in data:
|
| 118 |
for item in state["form"]:
|
| 119 |
+
labels=item['label']
|
| 120 |
+
word=item['text']
|
| 121 |
+
ner_tags.append(labels)
|
| 122 |
+
tokens.append(word)
|
| 123 |
+
bboxes.append(normalize_bbox(item['box'],size))
|
| 124 |
+
|
| 125 |
+
#cur_line_bboxes = []
|
| 126 |
+
#words, label = item["words"], item["label"]
|
| 127 |
+
#words = [w for w in words if w["text"].strip() != ""]
|
| 128 |
+
#if len(words) == 0:
|
| 129 |
+
#continue
|
| 130 |
+
#if label == "other":
|
| 131 |
+
#for w in words:
|
| 132 |
+
# tokens.append(w["text"])
|
| 133 |
+
# ner_tags.append("O")
|
| 134 |
+
#cur_line_bboxes.append(normalize_bbox(w["box"], size))
|
| 135 |
+
# else:
|
| 136 |
+
#tokens.append(words[0]["text"])
|
| 137 |
+
#ner_tags.append("B-" + label.upper())
|
| 138 |
+
#cur_line_bboxes.append(normalize_bbox(words[0]["box"], size))
|
| 139 |
+
#for w in words[1:]:
|
| 140 |
+
#tokens.append(w["text"])
|
| 141 |
+
# ner_tags.append("I-" + label.upper())
|
| 142 |
+
#cur_line_bboxes.append(normalize_bbox(w["box"], size))
|
| 143 |
+
#cur_line_bboxes = self.get_line_bbox(cur_line_bboxes)
|
| 144 |
+
#bboxes.extend(cur_line_bboxes)
|
| 145 |
yield guid, {"id": str(guid), "tokens": tokens, "bboxes": bboxes, "ner_tags": ner_tags,
|
| 146 |
"image": image}
|