by Anonymous » 05 Mar 2025, 12:16
Ich habe ein LayoutLMV3 -Modell trainiert, das mit Label Studio einen Etikettendatensatz erstellt hat. Ich konnte die Ausgabe des Modells mit dem folgenden Code < /p>
testen
Code: Select all
encoding = processor(image, words, boxes=boxes, word_labels=word_labels, return_tensors="pt")
for k,v in encoding.items():
print(k,v.shape)
< /code>
und zeichnen Sie die Felder im PDF mit dem folgenden Code < /p>
zurückimport torch
with torch.no_grad():
outputs = model(**encoding)
logits = outputs.logits
logits.shape
print (outputs)
predictions = logits.argmax(-1).squeeze().tolist()
print(predictions)
labels = encoding.labels.squeeze().tolist()
print(labels)
def unnormalize_box(bbox, width, height):
return [
width * (bbox[0] / 1000),
height * (bbox[1] / 1000),
width * (bbox[2] / 1000),
height * (bbox[3] / 1000),
]
token_boxes = encoding.bbox.squeeze().tolist()
width, height = image.size
true_predictions = [model.config.id2label[pred] for pred, label in zip(predictions, labels) if label != - 100]
true_labels = [model.config.id2label[label] for prediction, label in zip(predictions, labels) if label != -100]
true_boxes = [unnormalize_box(box, width, height) for box, label in zip(token_boxes, labels) if label != -100]
print(encoding.values)
Was ich zu verstehen versuche, ist, ob die Vorhersagen, die das Modell gibt>
Ich habe ein LayoutLMV3 -Modell trainiert, das mit Label Studio einen Etikettendatensatz erstellt hat. Ich konnte die Ausgabe des Modells mit dem folgenden Code < /p>
testen[code]encoding = processor(image, words, boxes=boxes, word_labels=word_labels, return_tensors="pt")
for k,v in encoding.items():
print(k,v.shape)
< /code>
und zeichnen Sie die Felder im PDF mit dem folgenden Code < /p>
zurückimport torch
with torch.no_grad():
outputs = model(**encoding)
logits = outputs.logits
logits.shape
print (outputs)
predictions = logits.argmax(-1).squeeze().tolist()
print(predictions)
labels = encoding.labels.squeeze().tolist()
print(labels)
def unnormalize_box(bbox, width, height):
return [
width * (bbox[0] / 1000),
height * (bbox[1] / 1000),
width * (bbox[2] / 1000),
height * (bbox[3] / 1000),
]
token_boxes = encoding.bbox.squeeze().tolist()
width, height = image.size
true_predictions = [model.config.id2label[pred] for pred, label in zip(predictions, labels) if label != - 100]
true_labels = [model.config.id2label[label] for prediction, label in zip(predictions, labels) if label != -100]
true_boxes = [unnormalize_box(box, width, height) for box, label in zip(token_boxes, labels) if label != -100]
print(encoding.values)
[/code]
Was ich zu verstehen versuche, ist, ob die Vorhersagen, die das Modell gibt>