aijack commited on
Commit
0302f6d
·
1 Parent(s): 5b89720

Upload 4 files

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. app.py +71 -0
  3. requirements.txt +5 -0
  4. test1.jpg +3 -0
  5. test2.jpeg +0 -0
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ test1.jpg filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from sahi.prediction import ObjectPrediction
4
+ from sahi.utils.cv import visualize_object_predictions, read_image
5
+ from ultralyticsplus import YOLO
6
+
7
+
8
+
9
+ def yolov8_inference(
10
+ image: gr.inputs.Image = None,
11
+ model_path: gr.inputs.Dropdown = None,
12
+ image_size: gr.inputs.Slider = 640,
13
+ conf_threshold: gr.inputs.Slider = 0.25,
14
+ iou_threshold: gr.inputs.Slider = 0.45,
15
+ ):
16
+
17
+ model = YOLO(model_path)
18
+ model.conf = conf_threshold
19
+ model.iou = iou_threshold
20
+ results = model.predict(image, imgsz=image_size, return_outputs=True)
21
+ object_prediction_list = []
22
+ for _, image_results in enumerate(results):
23
+ if len(image_results)!=0:
24
+ image_predictions_in_xyxy_format = image_results['det']
25
+ for pred in image_predictions_in_xyxy_format:
26
+ x1, y1, x2, y2 = (
27
+ int(pred[0]),
28
+ int(pred[1]),
29
+ int(pred[2]),
30
+ int(pred[3]),
31
+ )
32
+ bbox = [x1, y1, x2, y2]
33
+ score = pred[4]
34
+ category_name = model.model.names[int(pred[5])]
35
+ category_id = pred[5]
36
+ object_prediction = ObjectPrediction(
37
+ bbox=bbox,
38
+ category_id=int(category_id),
39
+ score=score,
40
+ category_name=category_name,
41
+ )
42
+ object_prediction_list.append(object_prediction)
43
+
44
+ image = read_image(image)
45
+ output_image = visualize_object_predictions(image=image, object_prediction_list=object_prediction_list)
46
+ return output_image['image']
47
+
48
+
49
+ inputs = [
50
+ gr.inputs.Image(type="filepath", label="Input Image"),
51
+ gr.inputs.Dropdown(["aijack/yv8/yv8n", "aijack/yv8/yv8m","aijack/yv8x"],
52
+ default="aijack/yv8m", label="Model"),
53
+ gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"),
54
+ gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.05, label="Confidence Threshold"),
55
+ gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.05, label="IOU Threshold"),
56
+ ]
57
+
58
+ outputs = gr.outputs.Image(type="filepath", label="Output Image")
59
+ title = "Ultralytics YOLOv8: State-of-the-Art YOLO Models"
60
+
61
+ examples = [['test1.jpg', 'aijack/yv8m', 640, 0.25, 0.45], ['test2', 'aijack/yv8x', 1280, 0.25, 0.45]]
62
+ demo_app = gr.Interface(
63
+ fn=yolov8_inference,
64
+ inputs=inputs,
65
+ outputs=outputs,
66
+ title=title,
67
+ examples=examples,
68
+ cache_examples=True,
69
+ theme='huggingface',
70
+ )
71
+ demo_app.launch(debug=True, enable_queue=True)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ opencv_python
2
+ sahi
3
+ torch
4
+ ultralytics==8.0.4
5
+ ultralyticsplus==0.0.3
test1.jpg ADDED

Git LFS Details

  • SHA256: 999908925eb7f291412094edb690e8e03c588c8ede57dcf4d78d6156e5846cdb
  • Pointer size: 132 Bytes
  • Size of remote file: 1.35 MB
test2.jpeg ADDED