chun
commited on
Commit
·
89c67a6
1
Parent(s):
1b8bbd7
Upload 11 files
Browse files- app.py +56 -0
- best.pt +3 -0
- photo/a.jpg +0 -0
- photo/b.jpg +0 -0
- photo/c.jpg +0 -0
- photo/d.jpg +0 -0
- photo/e.jpg +0 -0
- photo/f.jpg +0 -0
- photo/g.jpg +0 -0
- photo/h.jpg +0 -0
- requirements.txt +45 -0
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from ultralytics import YOLO
|
3 |
+
import cv2
|
4 |
+
|
5 |
+
examples=[["photo/a.jpg","Image1"],["photo/b.jpg","Image2"],
|
6 |
+
["photo/c.jpg","Image3"],["photo/d.jpg","Image4"],
|
7 |
+
["photo/e.jpg","Image5"],["photo/f.jpg","Image6"],
|
8 |
+
["photo/g.jpg","Image7"],["photo/h.jpg","Image8"]]
|
9 |
+
|
10 |
+
|
11 |
+
def detect_objects_on_image(image_path):
|
12 |
+
image = cv2.imread(image_path)
|
13 |
+
model = YOLO("best.pt")
|
14 |
+
results = model.predict(image_path)
|
15 |
+
result = results[0]
|
16 |
+
output = []
|
17 |
+
for box in result.boxes:
|
18 |
+
x1, y1, x2, y2 = [
|
19 |
+
round(x) for x in box.xyxy[0].tolist()
|
20 |
+
|
21 |
+
]
|
22 |
+
class_id = box.cls[0].item()
|
23 |
+
prob = round(box.conf[0].item(), 2)
|
24 |
+
output.append([
|
25 |
+
x1, y1, x2, y2, result.names[class_id], prob
|
26 |
+
])
|
27 |
+
cv2.rectangle(
|
28 |
+
image,
|
29 |
+
(x1, y1),
|
30 |
+
(x2, y2),
|
31 |
+
color=(0, 0, 255),
|
32 |
+
thickness=2,
|
33 |
+
lineType=cv2.LINE_AA
|
34 |
+
)
|
35 |
+
|
36 |
+
cv2.putText(image,result.names[class_id], (x1, y1), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (36,255,12), 2)
|
37 |
+
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
38 |
+
|
39 |
+
|
40 |
+
inputs_image = [
|
41 |
+
gr.components.Image(type="filepath", label="Input Image"),
|
42 |
+
]
|
43 |
+
outputs_image = [
|
44 |
+
gr.components.Image(type="numpy", label="Output Image"),
|
45 |
+
]
|
46 |
+
demo = gr.Interface(
|
47 |
+
fn=detect_objects_on_image,
|
48 |
+
inputs=inputs_image,
|
49 |
+
outputs=outputs_image,
|
50 |
+
title="Yolov8 Custom Object Detection",
|
51 |
+
examples=examples,
|
52 |
+
cache_examples=False,
|
53 |
+
)
|
54 |
+
|
55 |
+
if __name__ == "__main__":
|
56 |
+
demo.launch()
|
best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c3f2d3fdeac6306a116b2eca70c7824ddaf952d4d6e94c66bbd0d051909cb630
|
3 |
+
size 22511726
|
photo/a.jpg
ADDED
![]() |
photo/b.jpg
ADDED
![]() |
photo/c.jpg
ADDED
![]() |
photo/d.jpg
ADDED
![]() |
photo/e.jpg
ADDED
![]() |
photo/f.jpg
ADDED
![]() |
photo/g.jpg
ADDED
![]() |
photo/h.jpg
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Ultralytics requirements
|
2 |
+
# Example: pip install -r requirements.txt
|
3 |
+
|
4 |
+
# Base ----------------------------------------
|
5 |
+
matplotlib>=3.3.0
|
6 |
+
numpy>=1.22.2 # pinned by Snyk to avoid a vulnerability
|
7 |
+
opencv-python>=4.6.0
|
8 |
+
pillow>=7.1.2
|
9 |
+
pyyaml>=5.3.1
|
10 |
+
requests>=2.23.0
|
11 |
+
scipy>=1.4.1
|
12 |
+
torch>=1.8.0
|
13 |
+
torchvision>=0.9.0
|
14 |
+
tqdm>=4.64.0
|
15 |
+
ultralytics
|
16 |
+
# Logging -------------------------------------
|
17 |
+
# tensorboard>=2.13.0
|
18 |
+
# dvclive>=2.12.0
|
19 |
+
# clearml
|
20 |
+
# comet
|
21 |
+
|
22 |
+
# Plotting ------------------------------------
|
23 |
+
pandas>=1.1.4
|
24 |
+
seaborn>=0.11.0
|
25 |
+
|
26 |
+
# Export --------------------------------------
|
27 |
+
# coremltools>=7.0.b1 # CoreML export
|
28 |
+
# onnx>=1.12.0 # ONNX export
|
29 |
+
# onnxsim>=0.4.1 # ONNX simplifier
|
30 |
+
# nvidia-pyindex # TensorRT export
|
31 |
+
# nvidia-tensorrt # TensorRT export
|
32 |
+
# scikit-learn==0.19.2 # CoreML quantization
|
33 |
+
# tensorflow>=2.4.1 # TF exports (-cpu, -aarch64, -macos)
|
34 |
+
# tflite-support
|
35 |
+
# tensorflowjs>=3.9.0 # TF.js export
|
36 |
+
# openvino-dev>=2023.0 # OpenVINO export
|
37 |
+
|
38 |
+
# Extras --------------------------------------
|
39 |
+
psutil # system utilization
|
40 |
+
py-cpuinfo # display CPU info
|
41 |
+
# thop>=0.1.1 # FLOPs computation
|
42 |
+
# ipython # interactive notebook
|
43 |
+
# albumentations>=1.0.3 # training augmentations
|
44 |
+
# pycocotools>=2.0.6 # COCO mAP
|
45 |
+
# roboflow
|