Edit model card

Model Card for Model ID

detr-finetuned

Model Description

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.

Uses

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()
Downloads last month
0
Safetensors
Model size
41.6M params
Tensor type
F32
·
Inference Examples
This model does not have enough activity to be deployed to Inference API (serverless) yet. Increase its social visibility and check back later, or deploy to Inference Endpoints (dedicated) instead.