Spaces:
Sleeping
Sleeping
calmdowngirl
commited on
Commit
·
279a2eb
1
Parent(s):
560a669
hustvl/yolos-base obj detection
Browse files- __pycache__/ppl_detector.cpython-312.pyc +0 -0
- app.py +11 -0
- ppl_detector.py +40 -0
__pycache__/ppl_detector.cpython-312.pyc
ADDED
|
Binary file (1.88 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
from ppl_detector import detect
|
| 4 |
+
|
| 5 |
+
with gr.Blocks() as demo:
|
| 6 |
+
img_input = gr.Image(type="filepath", label="Input Image")
|
| 7 |
+
img_output = gr.Image(label="Output Image with Detections")
|
| 8 |
+
|
| 9 |
+
img_input.change(fn=detect, inputs=img_input, outputs=img_output)
|
| 10 |
+
|
| 11 |
+
demo.launch()
|
ppl_detector.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
|
| 3 |
+
from PIL import Image, ImageDraw
|
| 4 |
+
from pprint import pprint
|
| 5 |
+
|
| 6 |
+
detector = pipeline("object-detection", model="hustvl/yolos-base")
|
| 7 |
+
source = None
|
| 8 |
+
|
| 9 |
+
def draw_bbox(bboxes):
|
| 10 |
+
global source
|
| 11 |
+
if source is None:
|
| 12 |
+
return
|
| 13 |
+
draw = ImageDraw.Draw(source)
|
| 14 |
+
for bb in bboxes:
|
| 15 |
+
draw.rectangle(bb, outline='yellow', width=2)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def detect(img):
|
| 19 |
+
global source
|
| 20 |
+
if source is None and img is not None:
|
| 21 |
+
source = Image.open(img)
|
| 22 |
+
else:
|
| 23 |
+
return None
|
| 24 |
+
|
| 25 |
+
objects = detector(source)
|
| 26 |
+
persons = [
|
| 27 |
+
o for o in objects
|
| 28 |
+
if o['label'] == 'person' and o['score'] > 0.83]
|
| 29 |
+
bboxes = list(map(lambda p: (p['box']['xmin'], p['box']['ymin'], p['box']['xmax'], p['box']['ymax']), persons))
|
| 30 |
+
n = len(persons)
|
| 31 |
+
|
| 32 |
+
print(f"it's got {n} {'ppl' if n > 1 else 'person'} in the image")
|
| 33 |
+
|
| 34 |
+
draw_bbox(bboxes)
|
| 35 |
+
return source
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|