Update FCD_lmv2.py
Browse files- FCD_lmv2.py +12 -9
FCD_lmv2.py
CHANGED
|
@@ -110,23 +110,26 @@ class FCD(datasets.GeneratorBasedBuilder):
|
|
| 110 |
image_path = image_path.replace("json", "jpg")
|
| 111 |
image, size = load_image(image_path)
|
| 112 |
for item in data:
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
| 116 |
continue
|
| 117 |
-
|
| 118 |
# for w in words:
|
| 119 |
# tokens.append(w["text"])
|
| 120 |
# ner_tags.append("O")
|
| 121 |
# bboxes.append(normalize_bbox(w["box"], size))
|
| 122 |
# else:
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
tokens.append(w["text"])
|
| 128 |
ner_tags.append("I-" + label.upper())
|
| 129 |
-
bboxes.append(normalize_bbox(w["box"], size))
|
|
|
|
|
|
|
| 130 |
|
| 131 |
|
| 132 |
yield guid, {"id": str(guid), "tokens": tokens, "bboxes": bboxes, "ner_tags": ner_tags, "image": image}
|
|
|
|
| 110 |
image_path = image_path.replace("json", "jpg")
|
| 111 |
image, size = load_image(image_path)
|
| 112 |
for item in data:
|
| 113 |
+
words, label = item["transcription"], item["label"]
|
| 114 |
+
words = [w for w in words if w["text"].strip() != ""]
|
| 115 |
+
|
| 116 |
+
if len(words) == 0:
|
| 117 |
continue
|
| 118 |
+
#if label == "other":
|
| 119 |
# for w in words:
|
| 120 |
# tokens.append(w["text"])
|
| 121 |
# ner_tags.append("O")
|
| 122 |
# bboxes.append(normalize_bbox(w["box"], size))
|
| 123 |
# else:
|
| 124 |
+
tokens.append(words[0]["text"])
|
| 125 |
+
ner_tags.append("B-" + label.upper())
|
| 126 |
+
bboxes.append(normalize_bbox(words[0]["box"], size))
|
| 127 |
+
for w in words[1:]:
|
| 128 |
tokens.append(w["text"])
|
| 129 |
ner_tags.append("I-" + label.upper())
|
| 130 |
+
bboxes.append(normalize_bbox(w["box"], size))
|
| 131 |
+
|
| 132 |
+
|
| 133 |
|
| 134 |
|
| 135 |
yield guid, {"id": str(guid), "tokens": tokens, "bboxes": bboxes, "ner_tags": ner_tags, "image": image}
|