Skip to content

Commit c1ef09a

Browse files
committed
Add yolov3-tiny example
1 parent 00825c1 commit c1ef09a

File tree

768 files changed

+968
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

768 files changed

+968
-0
lines changed

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ add_subdirectory(replit)
2828
add_subdirectory(mpt)
2929
add_subdirectory(starcoder)
3030
add_subdirectory(sam)
31+
add_subdirectory(yolo)

examples/yolo/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# yolov3-tiny
3+
4+
set(TEST_TARGET yolov3-tiny)
5+
add_executable(${TEST_TARGET} yolov3-tiny.cpp yolo_image.cpp)
6+
target_link_libraries(${TEST_TARGET} PRIVATE ggml common)

examples/yolo/README.md

Lines changed: 52 additions & 0 deletions
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import gguf
4+
import numpy as np
5+
6+
def save_conv2d_layer(f, gguf_writer, prefix, inp_c, filters, size, batch_normalize=True):
7+
biases = np.fromfile(f, dtype=np.float32, count=filters)
8+
gguf_writer.add_tensor(prefix + "_biases", biases, raw_shape=(1, filters, 1, 1))
9+
10+
if batch_normalize:
11+
scales = np.fromfile(f, dtype=np.float32, count=filters)
12+
gguf_writer.add_tensor(prefix + "_scales", scales, raw_shape=(1, filters, 1, 1))
13+
rolling_mean = np.fromfile(f, dtype=np.float32, count=filters)
14+
gguf_writer.add_tensor(prefix + "_rolling_mean", rolling_mean, raw_shape=(1, filters, 1, 1))
15+
rolling_variance = np.fromfile(f, dtype=np.float32, count=filters)
16+
gguf_writer.add_tensor(prefix + "_rolling_variance", rolling_variance, raw_shape=(1, filters, 1, 1))
17+
18+
weights_count = filters * inp_c * size * size
19+
l0_weights = np.fromfile(f, dtype=np.float32, count=weights_count)
20+
## ggml doesn't support f32 convolution yet, use f16 instead
21+
l0_weights = l0_weights.astype(np.float16)
22+
gguf_writer.add_tensor(prefix + "_weights", l0_weights, raw_shape=(filters, inp_c, size, size))
23+
24+
25+
if __name__ == '__main__':
26+
if len(sys.argv) != 2:
27+
print("Usage: %s <yolov3-tiny.weights>" % sys.argv[0])
28+
sys.exit(1)
29+
outfile = 'yolov3-tiny.gguf'
30+
gguf_writer = gguf.GGUFWriter(outfile, 'yolov3-tiny')
31+
32+
f = open(sys.argv[1], 'rb')
33+
f.read(20) # skip header
34+
save_conv2d_layer(f, gguf_writer, "l0", 3, 16, 3)
35+
save_conv2d_layer(f, gguf_writer, "l1", 16, 32, 3)
36+
save_conv2d_layer(f, gguf_writer, "l2", 32, 64, 3)
37+
save_conv2d_layer(f, gguf_writer, "l3", 64, 128, 3)
38+
save_conv2d_layer(f, gguf_writer, "l4", 128, 256, 3)
39+
save_conv2d_layer(f, gguf_writer, "l5", 256, 512, 3)
40+
save_conv2d_layer(f, gguf_writer, "l6", 512, 1024, 3)
41+
save_conv2d_layer(f, gguf_writer, "l7", 1024, 256, 1)
42+
save_conv2d_layer(f, gguf_writer, "l8", 256, 512, 3)
43+
save_conv2d_layer(f, gguf_writer, "l9", 512, 255, 1, batch_normalize=False)
44+
save_conv2d_layer(f, gguf_writer, "l10", 256, 128, 1)
45+
save_conv2d_layer(f, gguf_writer, "l11", 384, 256, 3)
46+
save_conv2d_layer(f, gguf_writer, "l12", 256, 255, 1, batch_normalize=False)
47+
f.close()
48+
49+
gguf_writer.write_header_to_file()
50+
gguf_writer.write_kv_data_to_file()
51+
gguf_writer.write_tensors_to_file()
52+
gguf_writer.close()
53+
print("{} converted to {}".format(sys.argv[1], outfile))

examples/yolo/data/coco.names

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
person
2+
bicycle
3+
car
4+
motorbike
5+
aeroplane
6+
bus
7+
train
8+
truck
9+
boat
10+
traffic light
11+
fire hydrant
12+
stop sign
13+
parking meter
14+
bench
15+
bird
16+
cat
17+
dog
18+
horse
19+
sheep
20+
cow
21+
elephant
22+
bear
23+
zebra
24+
giraffe
25+
backpack
26+
umbrella
27+
handbag
28+
tie
29+
suitcase
30+
frisbee
31+
skis
32+
snowboard
33+
sports ball
34+
kite
35+
baseball bat
36+
baseball glove
37+
skateboard
38+
surfboard
39+
tennis racket
40+
bottle
41+
wine glass
42+
cup
43+
fork
44+
knife
45+
spoon
46+
bowl
47+
banana
48+
apple
49+
sandwich
50+
orange
51+
broccoli
52+
carrot
53+
hot dog
54+
pizza
55+
donut
56+
cake
57+
chair
58+
sofa
59+
pottedplant
60+
bed
61+
diningtable
62+
toilet
63+
tvmonitor
64+
laptop
65+
mouse
66+
remote
67+
keyboard
68+
cell phone
69+
microwave
70+
oven
71+
toaster
72+
sink
73+
refrigerator
74+
book
75+
clock
76+
vase
77+
scissors
78+
teddy bear
79+
hair drier
80+
toothbrush
320 Bytes
377 Bytes
451 Bytes
508 Bytes
577 Bytes

0 commit comments

Comments
 (0)