lopesdri commited on
Commit
339d133
·
1 Parent(s): 585a022

new file: app.py

Browse files

new file: requirements.txt
new file: yolov5s.pt

Files changed (3) hide show
  1. app.py +39 -0
  2. requirements.txt +4 -0
  3. yolov5s.pt +3 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import cv2
3
+ import numpy as np
4
+ import gradio as gr
5
+
6
+ # load model
7
+ model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
8
+
9
+ # set model parameters
10
+ model.conf = 0.25 # NMS confidence threshold
11
+ model.iou = 0.45 # NMS IoU threshold
12
+ model.agnostic = False # NMS class-agnostic
13
+ model.multi_label = False # NMS multiple labels per box
14
+ model.max_det = 1000 # maximum number of detections per image
15
+
16
+ # set image
17
+ img = '/content/apple_img.jpg'
18
+
19
+ def detect(img):
20
+
21
+ # perform inference
22
+ results = model(img, size=640)
23
+
24
+ # inference with test time augmentation
25
+ results = model(img, augment=True)
26
+ # parse results
27
+ predictions = results.pred[0]
28
+ boxes = predictions[:, :4] # x1, y1, x2, y2
29
+ scores = predictions[:, 4]
30
+ categories = predictions[:, 5]
31
+ return results
32
+ # show detection bounding boxes on image
33
+
34
+ image = gr.inputs.Image(shape=(192, 192))
35
+ label = gr.outputs.Label()
36
+ examples = ['dog.jpg']
37
+
38
+ intf = gr.Interface(fn=detect, inputs=image, outputs=image, examples=examples)
39
+ intf.launch(inline=False)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ opencv_python
2
+ torch
3
+ ultralytics==8.0.4
4
+ ultralyticsplus==0.0.3
yolov5s.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8b3b748c1e592ddd8868022e8732fde20025197328490623cc16c6f24d0782ee
3
+ size 14808437