Initial YOLOv8 sitting posture upload
Browse files- README.md +15 -0
- app.py +22 -0
- inference.py +21 -0
- model.pt +3 -0
- requirements.txt +6 -0
README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# YOLOv8 Sitting Posture Detection
|
| 3 |
+
|
| 4 |
+
This repository contains a YOLOv8 model trained to detect sitting postures.
|
| 5 |
+
|
| 6 |
+
## How to Use
|
| 7 |
+
|
| 8 |
+
### Locally
|
| 9 |
+
1. Install dependencies:
|
| 10 |
+
```bash
|
| 11 |
+
pip install -r requirements.txt
|
| 12 |
+
|
| 13 |
+
2. Run the Gradio app
|
| 14 |
+
```bash
|
| 15 |
+
python app.py
|
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from inference import predict
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import io
|
| 6 |
+
|
| 7 |
+
def predict_image(img: Image.Image):
|
| 8 |
+
with io.BytesIO() as buffer:
|
| 9 |
+
img.save(buffer, format="JPEG")
|
| 10 |
+
img_bytes = buffer.getvalue()
|
| 11 |
+
return predict(img_bytes)
|
| 12 |
+
|
| 13 |
+
iface = gr.Interface(
|
| 14 |
+
fn=predict_image,
|
| 15 |
+
inputs=gr.Image(type="pil"),
|
| 16 |
+
outputs=gr.JSON(),
|
| 17 |
+
title="Sitting Posture Detection",
|
| 18 |
+
description="Upload an image to detect sitting postures using YOLOv8"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
if __name__ == "__main__":
|
| 22 |
+
iface.launch()
|
inference.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import torch
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import io
|
| 6 |
+
|
| 7 |
+
# Load YOLOv8 model
|
| 8 |
+
model = YOLO("model.pt")
|
| 9 |
+
|
| 10 |
+
def predict(image_bytes):
|
| 11 |
+
img = Image.open(io.BytesIO(image_bytes))
|
| 12 |
+
results = model.predict(img)
|
| 13 |
+
output = []
|
| 14 |
+
for result in results:
|
| 15 |
+
for i in range(len(result.boxes)):
|
| 16 |
+
output.append({
|
| 17 |
+
"bbox": result.boxes.xyxy[i].tolist(),
|
| 18 |
+
"class": int(result.boxes.cls[i].item()),
|
| 19 |
+
"confidence": float(result.boxes.conf[i].item())
|
| 20 |
+
})
|
| 21 |
+
return output
|
model.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:65d11808479be328cbad89a7a8a46114886a45b1e57782de8e115673ab05a453
|
| 3 |
+
size 23121944
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
ultralytics>=8.0
|
| 3 |
+
torch>=2.0
|
| 4 |
+
Pillow
|
| 5 |
+
gradio
|
| 6 |
+
huggingface_hub
|