Jaime García Villena
commited on
Commit
·
48730f0
1
Parent(s):
7cd0692
get the script to export
Browse files- yolo_export.py +6 -0
- yolo_run.py +76 -0
- yolov8n.onnx +3 -0
- yolov8n.pt +3 -0
- yolov8n_saved_model/fingerprint.pb +3 -0
- yolov8n_saved_model/metadata.yaml +92 -0
- yolov8n_saved_model/saved_model.pb +3 -0
- yolov8n_saved_model/variables/variables.data-00000-of-00001 +0 -0
- yolov8n_saved_model/variables/variables.index +0 -0
- yolov8n_saved_model/yolov8n_float16.tflite +3 -0
- yolov8n_saved_model/yolov8n_float32.tflite +3 -0
yolo_export.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ultralytics import YOLO
|
| 2 |
+
|
| 3 |
+
if __name__ == '__main__':
|
| 4 |
+
model = YOLO('yolov8n.pt')
|
| 5 |
+
model.export(format = 'saved_model', keras = True)
|
| 6 |
+
model.export(format = 'tflite')
|
yolo_run.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ultralytics import YOLO
|
| 2 |
+
"""
|
| 3 |
+
Created on Wed Oct 4 16:44:12 2023
|
| 4 |
+
|
| 5 |
+
@author: lin
|
| 6 |
+
"""
|
| 7 |
+
import glob
|
| 8 |
+
import sys
|
| 9 |
+
sys.path.append('../../..')
|
| 10 |
+
import os
|
| 11 |
+
import cv2
|
| 12 |
+
import json
|
| 13 |
+
import tensorflow as tf
|
| 14 |
+
import numpy as np
|
| 15 |
+
import matplotlib.pyplot as plt
|
| 16 |
+
# from utils.bbox_op import non_max_supression
|
| 17 |
+
|
| 18 |
+
def plot_prediction(image_np, bboxes, classes, scores, label_map):
|
| 19 |
+
color=(255,0,0)
|
| 20 |
+
thickness=5
|
| 21 |
+
font_scale=3
|
| 22 |
+
|
| 23 |
+
for i, box in enumerate(bboxes):
|
| 24 |
+
box = bboxes[i, :]
|
| 25 |
+
|
| 26 |
+
x0, y0, x1, y1 = box
|
| 27 |
+
|
| 28 |
+
xmin = int(x0)
|
| 29 |
+
ymin = int(y0)
|
| 30 |
+
xmax = int(x1)
|
| 31 |
+
ymax = int(y1)
|
| 32 |
+
|
| 33 |
+
print(xmin, ymin, xmax, ymax)
|
| 34 |
+
|
| 35 |
+
image_np = cv2.rectangle(image_np, (xmin, ymin), (xmax, ymax), color=color, thickness=thickness)
|
| 36 |
+
text_x = xmin - 10 if xmin > 20 else xmin + 10
|
| 37 |
+
text_y = ymin - 10 if ymin > 20 else ymin + 10
|
| 38 |
+
display_str = label_map[str(int(classes))]
|
| 39 |
+
|
| 40 |
+
cv2.putText(
|
| 41 |
+
image_np,
|
| 42 |
+
display_str,
|
| 43 |
+
(text_x, text_y),
|
| 44 |
+
cv2.FONT_HERSHEY_SIMPLEX,
|
| 45 |
+
font_scale,
|
| 46 |
+
color,
|
| 47 |
+
thickness,
|
| 48 |
+
)
|
| 49 |
+
plt.imshow(image_np)
|
| 50 |
+
plt.show()
|
| 51 |
+
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
min_th = 0.1
|
| 54 |
+
labels_json = "coco_labels.json"
|
| 55 |
+
with open(labels_json) as f:
|
| 56 |
+
label_map = json.load(f)
|
| 57 |
+
img_path = "test_images"
|
| 58 |
+
saved_tflite = "tflite_model.tflite"
|
| 59 |
+
# load model
|
| 60 |
+
|
| 61 |
+
model = YOLO("yolov8n.pt")
|
| 62 |
+
images = glob.glob(os.path.join(img_path, "*"))
|
| 63 |
+
for img in images:
|
| 64 |
+
|
| 65 |
+
image_np = cv2.imread(img) # gpreprocess(img)
|
| 66 |
+
image_np = cv2.cvtColor(image_np, cv2.COLOR_BGR2RGB)
|
| 67 |
+
# print(image_np.shape)
|
| 68 |
+
|
| 69 |
+
# image_np = np.array(Image.open(image_path))
|
| 70 |
+
results = model(img)
|
| 71 |
+
boxes = results[0].boxes
|
| 72 |
+
|
| 73 |
+
print(boxes.xyxy)
|
| 74 |
+
print(boxes.cls)
|
| 75 |
+
print(boxes.conf)
|
| 76 |
+
plot_prediction(image_np, boxes.xyxy.numpy(), boxes.cls.numpy(), boxes.conf.numpy(), label_map)
|
yolov8n.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dd48a79dd7fec8ca25fde4eca742ff7bca23b27e2e903eb23bc1d9f83a459bd2
|
| 3 |
+
size 12769720
|
yolov8n.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:31e20dde3def09e2cf938c7be6fe23d9150bbbe503982af13345706515f2ef95
|
| 3 |
+
size 6534387
|
yolov8n_saved_model/fingerprint.pb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3b3492909f2891a54e9151b18733a1d42d514bea74240f213228f33eac6a017a
|
| 3 |
+
size 56
|
yolov8n_saved_model/metadata.yaml
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
description: Ultralytics YOLOv8n model trained on coco.yaml
|
| 2 |
+
author: Ultralytics
|
| 3 |
+
license: AGPL-3.0 https://ultralytics.com/license
|
| 4 |
+
date: '2023-10-06T15:50:35.220556'
|
| 5 |
+
version: 8.0.192
|
| 6 |
+
stride: 32
|
| 7 |
+
task: detect
|
| 8 |
+
batch: 1
|
| 9 |
+
imgsz:
|
| 10 |
+
- 640
|
| 11 |
+
- 640
|
| 12 |
+
names:
|
| 13 |
+
0: person
|
| 14 |
+
1: bicycle
|
| 15 |
+
2: car
|
| 16 |
+
3: motorcycle
|
| 17 |
+
4: airplane
|
| 18 |
+
5: bus
|
| 19 |
+
6: train
|
| 20 |
+
7: truck
|
| 21 |
+
8: boat
|
| 22 |
+
9: traffic light
|
| 23 |
+
10: fire hydrant
|
| 24 |
+
11: stop sign
|
| 25 |
+
12: parking meter
|
| 26 |
+
13: bench
|
| 27 |
+
14: bird
|
| 28 |
+
15: cat
|
| 29 |
+
16: dog
|
| 30 |
+
17: horse
|
| 31 |
+
18: sheep
|
| 32 |
+
19: cow
|
| 33 |
+
20: elephant
|
| 34 |
+
21: bear
|
| 35 |
+
22: zebra
|
| 36 |
+
23: giraffe
|
| 37 |
+
24: backpack
|
| 38 |
+
25: umbrella
|
| 39 |
+
26: handbag
|
| 40 |
+
27: tie
|
| 41 |
+
28: suitcase
|
| 42 |
+
29: frisbee
|
| 43 |
+
30: skis
|
| 44 |
+
31: snowboard
|
| 45 |
+
32: sports ball
|
| 46 |
+
33: kite
|
| 47 |
+
34: baseball bat
|
| 48 |
+
35: baseball glove
|
| 49 |
+
36: skateboard
|
| 50 |
+
37: surfboard
|
| 51 |
+
38: tennis racket
|
| 52 |
+
39: bottle
|
| 53 |
+
40: wine glass
|
| 54 |
+
41: cup
|
| 55 |
+
42: fork
|
| 56 |
+
43: knife
|
| 57 |
+
44: spoon
|
| 58 |
+
45: bowl
|
| 59 |
+
46: banana
|
| 60 |
+
47: apple
|
| 61 |
+
48: sandwich
|
| 62 |
+
49: orange
|
| 63 |
+
50: broccoli
|
| 64 |
+
51: carrot
|
| 65 |
+
52: hot dog
|
| 66 |
+
53: pizza
|
| 67 |
+
54: donut
|
| 68 |
+
55: cake
|
| 69 |
+
56: chair
|
| 70 |
+
57: couch
|
| 71 |
+
58: potted plant
|
| 72 |
+
59: bed
|
| 73 |
+
60: dining table
|
| 74 |
+
61: toilet
|
| 75 |
+
62: tv
|
| 76 |
+
63: laptop
|
| 77 |
+
64: mouse
|
| 78 |
+
65: remote
|
| 79 |
+
66: keyboard
|
| 80 |
+
67: cell phone
|
| 81 |
+
68: microwave
|
| 82 |
+
69: oven
|
| 83 |
+
70: toaster
|
| 84 |
+
71: sink
|
| 85 |
+
72: refrigerator
|
| 86 |
+
73: book
|
| 87 |
+
74: clock
|
| 88 |
+
75: vase
|
| 89 |
+
76: scissors
|
| 90 |
+
77: teddy bear
|
| 91 |
+
78: hair drier
|
| 92 |
+
79: toothbrush
|
yolov8n_saved_model/saved_model.pb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f23f3eda89025c6d1da3916c7fed1a50179bb9182aedca2d6a74ba0f39fb2a23
|
| 3 |
+
size 12913757
|
yolov8n_saved_model/variables/variables.data-00000-of-00001
ADDED
|
Binary file (3.69 kB). View file
|
|
|
yolov8n_saved_model/variables/variables.index
ADDED
|
Binary file (145 Bytes). View file
|
|
|
yolov8n_saved_model/yolov8n_float16.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:72e4cbf64265e974923d6b723a2be1d1deeacbdc74aa770e5e82a9f0b753c645
|
| 3 |
+
size 6434532
|
yolov8n_saved_model/yolov8n_float32.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:435e0b6375a32b862ed30cb630256d5dbefb9597c53c87125a66e44ab26cfd68
|
| 3 |
+
size 12771680
|