Update README.md
Browse files
README.md
CHANGED
|
@@ -17,10 +17,15 @@ image_processor = RTDetrImageProcessor.from_pretrained("HuggingPanda/docling-lay
|
|
| 17 |
model = RTDetrForObjectDetection.from_pretrained("HuggingPanda/docling-layout")
|
| 18 |
|
| 19 |
# Load an image
|
| 20 |
-
image = Image.open("
|
| 21 |
|
| 22 |
# Preprocess the image
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Perform inference
|
| 26 |
with torch.no_grad():
|
|
@@ -29,7 +34,7 @@ with torch.no_grad():
|
|
| 29 |
# Post-process results
|
| 30 |
results = image_processor.post_process_object_detection(
|
| 31 |
outputs,
|
| 32 |
-
target_sizes=torch.tensor([
|
| 33 |
threshold=0.3
|
| 34 |
)
|
| 35 |
|
|
@@ -38,7 +43,8 @@ for result in results:
|
|
| 38 |
for score, label_id, box in zip(result["scores"], result["labels"], result["boxes"]):
|
| 39 |
score, label = score.item(), label_id.item()
|
| 40 |
box = [round(i, 2) for i in box.tolist()]
|
| 41 |
-
print(f"{model.config.id2label[label]}: {score:.2f} {box}")
|
|
|
|
| 42 |
```
|
| 43 |
|
| 44 |
|
|
|
|
| 17 |
model = RTDetrForObjectDetection.from_pretrained("HuggingPanda/docling-layout")
|
| 18 |
|
| 19 |
# Load an image
|
| 20 |
+
image = Image.open("hocr_output_page-0001.jpg")
|
| 21 |
|
| 22 |
# Preprocess the image
|
| 23 |
+
resize = {"height":640, "width":640}
|
| 24 |
+
inputs = image_processor(
|
| 25 |
+
images=image,
|
| 26 |
+
return_tensors="pt",
|
| 27 |
+
size=resize,
|
| 28 |
+
)
|
| 29 |
|
| 30 |
# Perform inference
|
| 31 |
with torch.no_grad():
|
|
|
|
| 34 |
# Post-process results
|
| 35 |
results = image_processor.post_process_object_detection(
|
| 36 |
outputs,
|
| 37 |
+
target_sizes=torch.tensor([image.size[::-1]]),
|
| 38 |
threshold=0.3
|
| 39 |
)
|
| 40 |
|
|
|
|
| 43 |
for score, label_id, box in zip(result["scores"], result["labels"], result["boxes"]):
|
| 44 |
score, label = score.item(), label_id.item()
|
| 45 |
box = [round(i, 2) for i in box.tolist()]
|
| 46 |
+
print(f"{model.config.id2label[label+1]}: {score:.2f} {box}")
|
| 47 |
+
|
| 48 |
```
|
| 49 |
|
| 50 |
|