Downloads · 30 days
4
0% of all-time downloads
0llheaven/detr-finetuned
detr-finetuned is a object detection model from 0llheaven. Use it when you need objects located in an image. It is set up for transformers.
detr-finetuned This model is a fine-tuned version of facebook/detr-resnet-50 on the 0llheaven/detr-finetuned dataset. This dataset contains images of chapbooks with bounding boxes for the illustrations contained on so…
Downloads · 30 days
4
0% of all-time downloads
All-time downloads
1.1K
Public
Parameters
41.6M
333 MB on disk
Likes
0
Public
Click a slice to open those files.
.bin167 MB · 50%
From the Hugging Face model README
detr-finetuned This model is a fine-tuned version of facebook/detr-resnet-50 on the 0llheaven/detr-finetuned dataset. This dataset contains images of chapbooks with bounding boxes for the illustrations contained on some of the pages.
from transformers import AutoImageProcessor, AutoModelForObjectDetection
import torch
from PIL import Image, ImageDraw
import matplotlib.pyplot as plt
# เปิดรูปภาพจากพาธในเครื่อง
url = "../pic/0fda72a2-f383-4f69-af8e-e16a0fbac621.jpg"
image = Image.open(url)
# แปลงรูปภาพเป็น RGB หากเป็น grayscale
if image.mode != "RGB":
image = image.convert("RGB")
processor = AutoImageProcessor.from_pretrained("0llheaven/detr-finetuned")
model = AutoModelForObjectDetection.from_pretrained("0llheaven/detr-finetuned")
inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
# กรองการทำนายที่มีความแม่นยำมากกว่า 0.9
target_sizes = torch.tensor([image.size[::-1]])
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes)
print(results)
# # วาดกรอบรอบวัตถุที่ตรวจพบในภาพ
draw = ImageDraw.Draw(image)
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
box = [round(i, 2) for i in box.tolist()]
draw.rectangle(box, outline="red", width=3)
draw.text((box[0], box[1]), f"{model.config.id2label[label.item()]}: {round(score.item(), 3)}", fill="red")
# แสดงผลภาพ
plt.figure(figsize=(10, 10))
plt.imshow(image)
plt.axis('off')
plt.show()