sheikh commited on
Commit
e718065
·
1 Parent(s): e043789

Update layoutlmv3.py

Browse files
Files changed (1) hide show
  1. 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
- cur_line_bboxes = []
120
- words, label = item["words"], item["label"]
121
- words = [w for w in words if w["text"].strip() != ""]
122
- if len(words) == 0:
123
- continue
124
- if label == "other":
125
- for w in words:
126
- tokens.append(w["text"])
127
- ner_tags.append("O")
128
- cur_line_bboxes.append(normalize_bbox(w["box"], size))
129
- else:
130
- tokens.append(words[0]["text"])
131
- ner_tags.append("B-" + label.upper())
132
- cur_line_bboxes.append(normalize_bbox(words[0]["box"], size))
133
- for w in words[1:]:
134
- tokens.append(w["text"])
135
- ner_tags.append("I-" + label.upper())
136
- cur_line_bboxes.append(normalize_bbox(w["box"], size))
137
- cur_line_bboxes = self.get_line_bbox(cur_line_bboxes)
138
- bboxes.extend(cur_line_bboxes)
 
 
 
 
 
 
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}