Spaces:
Runtime error
Runtime error
Upload 5 files
Browse filestrash app files
Files changed (6)
- .gitattributes+2
- IMG_1315.JPGAdded
- IMG_1348.JPGAdded
- app.pyAdded+51
- requirements.txtAdded+3
- trashbest.ptAdded+3
31 unmodified lines32333431 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text31 unmodified lines323334353631 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textIMG_1315.JPG filter=lfs diff=lfs merge=lfs -textIMG_1348.JPG filter=lfs diff=lfs merge=lfs -text
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051import gradio as grfrom ultralytics import YOLOfrom collections import Counterimport torchimport cv2
def yolov8_predictor(img: gr.inputs.Image = None, model_path: gr.inputs.Dropdown = None, image_size= 640, conf= 0.4, iou= 0.7 ):
model= YOLO(model= model_path) res= model.predict(source= img, imgsz=image_size, conf= conf, iou= iou)
cls_names= res[0].names dets_cls= res[0].boxes.cls.cpu().numpy().astype(int)
dets= [cls_names[i] for i in dets_cls] dets= dict(Counter(dets)) res_plotted = res[0].plot() res_plotted= cv2.cvtColor(res_plotted, cv2.COLOR_BGR2RGB)
return res_plotted, str(dets)
inputs = [ gr.inputs.Image(type="filepath", label="Input Image"), gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"), gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.4, step=0.05, label="Confidence Threshold"), gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.7, step=0.05, label="IOU Threshold"),]
outputs = [gr.outputs.Image(type="filepath", label="Output Image"), "text"]title = "Trash Detection"
examples = [['IMG_1315.JPG', 'trashbest.pt', 640, 0.4, 0.7], ['IMG_1348.jpg', 'trashbest.pt', 640, 0.4, 0.7]]
demo_app = gr.Interface( fn=yolov8_predictor, inputs=inputs, outputs=outputs, title=title, examples=examples, cache_examples=True, theme='huggingface',)
demo_app.launch(debug=True, enable_queue=True)123opencv_pythontorchultralytics==8.0.113123version https://git-lfs.github.com/spec/v1oid sha256:a07db9bfc7b54874cb60e2437e5441003e7a8a855a6178421557717cb1953f6dsize 23849400.gitattributes+2
IMG_1315.JPGAdded
Large File Pointer Details
- SHA256: d57a92ad86845d546fa6a47916d06794ec0e02abe1e3bf085f428c448944cbaa
- Pointer size: 132 Bytes
- Size of remote file: 4.84 MB
IMG_1348.JPGAdded
Large File Pointer Details
- SHA256: 6cf8e0b9561315c8b9970458a871b69416ddfa705eea085e0b7362b121ae02a8
- Pointer size: 132 Bytes
- Size of remote file: 3.45 MB
app.pyAdded+51
requirements.txtAdded+3
trashbest.ptAdded+3