initial release
@@ -0,0 +1,6 @@
|
||||
#
|
||||
# yolov3-tiny
|
||||
|
||||
set(TEST_TARGET yolov3-tiny)
|
||||
add_executable(${TEST_TARGET} yolov3-tiny.cpp yolo-image.cpp)
|
||||
target_link_libraries(${TEST_TARGET} PRIVATE ggml common)
|
||||
@@ -0,0 +1,59 @@
|
||||
This example shows how to implement YOLO object detection with ggml using pretrained model.
|
||||
|
||||
# YOLOv3-tiny
|
||||
|
||||
Download the model weights:
|
||||
|
||||
```bash
|
||||
$ wget https://pjreddie.com/media/files/yolov3-tiny.weights
|
||||
$ sha1sum yolov3-tiny.weights
|
||||
40f3c11883bef62fd850213bc14266632ed4414f yolov3-tiny.weights
|
||||
```
|
||||
|
||||
Convert the weights to GGUF format:
|
||||
|
||||
```bash
|
||||
$ ./convert-yolov3-tiny.py yolov3-tiny.weights
|
||||
yolov3-tiny.weights converted to yolov3-tiny.gguf
|
||||
```
|
||||
|
||||
Alternatively, you can download the converted model from [HuggingFace](https://huggingface.co/rgerganov/yolo-gguf/resolve/main/yolov3-tiny.gguf)
|
||||
|
||||
Object detection:
|
||||
|
||||
```bash
|
||||
$ wget https://raw.githubusercontent.com/pjreddie/darknet/master/data/dog.jpg
|
||||
$ ./yolov3-tiny -m yolov3-tiny.gguf -i dog.jpg
|
||||
load_model: using CUDA backend
|
||||
ggml_cuda_init: GGML_CUDA_FORCE_MMQ: no
|
||||
ggml_cuda_init: GGML_CUDA_FORCE_CUBLAS: no
|
||||
ggml_cuda_init: found 1 CUDA devices:
|
||||
Device 0: NVIDIA T1200 Laptop GPU, compute capability 7.5, VMM: yes
|
||||
Layer 0 output shape: 416 x 416 x 16 x 1
|
||||
Layer 1 output shape: 208 x 208 x 16 x 1
|
||||
Layer 2 output shape: 208 x 208 x 32 x 1
|
||||
Layer 3 output shape: 104 x 104 x 32 x 1
|
||||
Layer 4 output shape: 104 x 104 x 64 x 1
|
||||
Layer 5 output shape: 52 x 52 x 64 x 1
|
||||
Layer 6 output shape: 52 x 52 x 128 x 1
|
||||
Layer 7 output shape: 26 x 26 x 128 x 1
|
||||
Layer 8 output shape: 26 x 26 x 256 x 1
|
||||
Layer 9 output shape: 13 x 13 x 256 x 1
|
||||
Layer 10 output shape: 13 x 13 x 512 x 1
|
||||
Layer 11 output shape: 13 x 13 x 512 x 1
|
||||
Layer 12 output shape: 13 x 13 x 1024 x 1
|
||||
Layer 13 output shape: 13 x 13 x 256 x 1
|
||||
Layer 14 output shape: 13 x 13 x 512 x 1
|
||||
Layer 15 output shape: 13 x 13 x 255 x 1
|
||||
Layer 18 output shape: 13 x 13 x 128 x 1
|
||||
Layer 19 output shape: 26 x 26 x 128 x 1
|
||||
Layer 20 output shape: 26 x 26 x 384 x 1
|
||||
Layer 21 output shape: 26 x 26 x 256 x 1
|
||||
Layer 22 output shape: 26 x 26 x 255 x 1
|
||||
dog: 57%
|
||||
car: 52%
|
||||
truck: 56%
|
||||
car: 62%
|
||||
bicycle: 59%
|
||||
Detected objects saved in 'predictions.jpg' (time: 0.057000 sec.)
|
||||
```
|
||||
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import gguf
|
||||
import numpy as np
|
||||
|
||||
def save_conv2d_layer(f, gguf_writer, prefix, inp_c, filters, size, batch_normalize=True):
|
||||
biases = np.fromfile(f, dtype=np.float32, count=filters)
|
||||
gguf_writer.add_tensor(prefix + "_biases", biases, raw_shape=(1, filters, 1, 1))
|
||||
|
||||
if batch_normalize:
|
||||
scales = np.fromfile(f, dtype=np.float32, count=filters)
|
||||
gguf_writer.add_tensor(prefix + "_scales", scales, raw_shape=(1, filters, 1, 1))
|
||||
rolling_mean = np.fromfile(f, dtype=np.float32, count=filters)
|
||||
gguf_writer.add_tensor(prefix + "_rolling_mean", rolling_mean, raw_shape=(1, filters, 1, 1))
|
||||
rolling_variance = np.fromfile(f, dtype=np.float32, count=filters)
|
||||
gguf_writer.add_tensor(prefix + "_rolling_variance", rolling_variance, raw_shape=(1, filters, 1, 1))
|
||||
|
||||
weights_count = filters * inp_c * size * size
|
||||
l0_weights = np.fromfile(f, dtype=np.float32, count=weights_count)
|
||||
## ggml doesn't support f32 convolution yet, use f16 instead
|
||||
l0_weights = l0_weights.astype(np.float16)
|
||||
gguf_writer.add_tensor(prefix + "_weights", l0_weights, raw_shape=(filters, inp_c, size, size))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s <yolov3-tiny.weights>" % sys.argv[0])
|
||||
sys.exit(1)
|
||||
outfile = 'yolov3-tiny.gguf'
|
||||
gguf_writer = gguf.GGUFWriter(outfile, 'yolov3-tiny')
|
||||
|
||||
f = open(sys.argv[1], 'rb')
|
||||
f.read(20) # skip header
|
||||
save_conv2d_layer(f, gguf_writer, "l0", 3, 16, 3)
|
||||
save_conv2d_layer(f, gguf_writer, "l1", 16, 32, 3)
|
||||
save_conv2d_layer(f, gguf_writer, "l2", 32, 64, 3)
|
||||
save_conv2d_layer(f, gguf_writer, "l3", 64, 128, 3)
|
||||
save_conv2d_layer(f, gguf_writer, "l4", 128, 256, 3)
|
||||
save_conv2d_layer(f, gguf_writer, "l5", 256, 512, 3)
|
||||
save_conv2d_layer(f, gguf_writer, "l6", 512, 1024, 3)
|
||||
save_conv2d_layer(f, gguf_writer, "l7", 1024, 256, 1)
|
||||
save_conv2d_layer(f, gguf_writer, "l8", 256, 512, 3)
|
||||
save_conv2d_layer(f, gguf_writer, "l9", 512, 255, 1, batch_normalize=False)
|
||||
save_conv2d_layer(f, gguf_writer, "l10", 256, 128, 1)
|
||||
save_conv2d_layer(f, gguf_writer, "l11", 384, 256, 3)
|
||||
save_conv2d_layer(f, gguf_writer, "l12", 256, 255, 1, batch_normalize=False)
|
||||
f.close()
|
||||
|
||||
gguf_writer.write_header_to_file()
|
||||
gguf_writer.write_kv_data_to_file()
|
||||
gguf_writer.write_tensors_to_file()
|
||||
gguf_writer.close()
|
||||
print("{} converted to {}".format(sys.argv[1], outfile))
|
||||
@@ -0,0 +1,80 @@
|
||||
person
|
||||
bicycle
|
||||
car
|
||||
motorbike
|
||||
aeroplane
|
||||
bus
|
||||
train
|
||||
truck
|
||||
boat
|
||||
traffic light
|
||||
fire hydrant
|
||||
stop sign
|
||||
parking meter
|
||||
bench
|
||||
bird
|
||||
cat
|
||||
dog
|
||||
horse
|
||||
sheep
|
||||
cow
|
||||
elephant
|
||||
bear
|
||||
zebra
|
||||
giraffe
|
||||
backpack
|
||||
umbrella
|
||||
handbag
|
||||
tie
|
||||
suitcase
|
||||
frisbee
|
||||
skis
|
||||
snowboard
|
||||
sports ball
|
||||
kite
|
||||
baseball bat
|
||||
baseball glove
|
||||
skateboard
|
||||
surfboard
|
||||
tennis racket
|
||||
bottle
|
||||
wine glass
|
||||
cup
|
||||
fork
|
||||
knife
|
||||
spoon
|
||||
bowl
|
||||
banana
|
||||
apple
|
||||
sandwich
|
||||
orange
|
||||
broccoli
|
||||
carrot
|
||||
hot dog
|
||||
pizza
|
||||
donut
|
||||
cake
|
||||
chair
|
||||
sofa
|
||||
pottedplant
|
||||
bed
|
||||
diningtable
|
||||
toilet
|
||||
tvmonitor
|
||||
laptop
|
||||
mouse
|
||||
remote
|
||||
keyboard
|
||||
cell phone
|
||||
microwave
|
||||
oven
|
||||
toaster
|
||||
sink
|
||||
refrigerator
|
||||
book
|
||||
clock
|
||||
vase
|
||||
scissors
|
||||
teddy bear
|
||||
hair drier
|
||||
toothbrush
|
||||
|
After Width: | Height: | Size: 320 B |
|
After Width: | Height: | Size: 377 B |
|
After Width: | Height: | Size: 451 B |
|
After Width: | Height: | Size: 508 B |
|
After Width: | Height: | Size: 577 B |
|
After Width: | Height: | Size: 631 B |
|
After Width: | Height: | Size: 697 B |
|
After Width: | Height: | Size: 753 B |
|
After Width: | Height: | Size: 321 B |
|
After Width: | Height: | Size: 388 B |
|
After Width: | Height: | Size: 458 B |
|
After Width: | Height: | Size: 514 B |
|
After Width: | Height: | Size: 581 B |
|
After Width: | Height: | Size: 654 B |
|
After Width: | Height: | Size: 726 B |
|
After Width: | Height: | Size: 804 B |
|
After Width: | Height: | Size: 305 B |
|
After Width: | Height: | Size: 340 B |
|
After Width: | Height: | Size: 354 B |
|
After Width: | Height: | Size: 371 B |
|
After Width: | Height: | Size: 398 B |
|
After Width: | Height: | Size: 411 B |
|
After Width: | Height: | Size: 422 B |
|
After Width: | Height: | Size: 442 B |
|
After Width: | Height: | Size: 333 B |
|
After Width: | Height: | Size: 415 B |
|
After Width: | Height: | Size: 521 B |
|
After Width: | Height: | Size: 586 B |
|
After Width: | Height: | Size: 687 B |
|
After Width: | Height: | Size: 781 B |
|
After Width: | Height: | Size: 858 B |
|
After Width: | Height: | Size: 971 B |
|
After Width: | Height: | Size: 315 B |
|
After Width: | Height: | Size: 345 B |
|
After Width: | Height: | Size: 382 B |
|
After Width: | Height: | Size: 412 B |
|
After Width: | Height: | Size: 439 B |
|
After Width: | Height: | Size: 476 B |
|
After Width: | Height: | Size: 511 B |
|
After Width: | Height: | Size: 542 B |
|
After Width: | Height: | Size: 296 B |
|
After Width: | Height: | Size: 306 B |
|
After Width: | Height: | Size: 318 B |
|
After Width: | Height: | Size: 336 B |
|
After Width: | Height: | Size: 352 B |
|
After Width: | Height: | Size: 360 B |
|
After Width: | Height: | Size: 379 B |
|
After Width: | Height: | Size: 391 B |
|
After Width: | Height: | Size: 293 B |
|
After Width: | Height: | Size: 307 B |
|
After Width: | Height: | Size: 319 B |
|
After Width: | Height: | Size: 335 B |
|
After Width: | Height: | Size: 348 B |
|
After Width: | Height: | Size: 363 B |
|
After Width: | Height: | Size: 374 B |
|
After Width: | Height: | Size: 390 B |
|
After Width: | Height: | Size: 314 B |
|
After Width: | Height: | Size: 358 B |
|
After Width: | Height: | Size: 410 B |
|
After Width: | Height: | Size: 446 B |
|
After Width: | Height: | Size: 490 B |
|
After Width: | Height: | Size: 526 B |
|
After Width: | Height: | Size: 581 B |
|
After Width: | Height: | Size: 609 B |
|
After Width: | Height: | Size: 285 B |
|
After Width: | Height: | Size: 288 B |
|
After Width: | Height: | Size: 296 B |
|
After Width: | Height: | Size: 298 B |
|
After Width: | Height: | Size: 298 B |
|
After Width: | Height: | Size: 300 B |
|
After Width: | Height: | Size: 302 B |
|
After Width: | Height: | Size: 305 B |
|
After Width: | Height: | Size: 321 B |
|
After Width: | Height: | Size: 371 B |
|
After Width: | Height: | Size: 426 B |
|
After Width: | Height: | Size: 475 B |
|
After Width: | Height: | Size: 528 B |
|
After Width: | Height: | Size: 587 B |
|
After Width: | Height: | Size: 628 B |
|
After Width: | Height: | Size: 694 B |
|
After Width: | Height: | Size: 312 B |
|
After Width: | Height: | Size: 341 B |
|
After Width: | Height: | Size: 378 B |
|
After Width: | Height: | Size: 414 B |
|
After Width: | Height: | Size: 444 B |
|
After Width: | Height: | Size: 479 B |
|
After Width: | Height: | Size: 509 B |
|
After Width: | Height: | Size: 544 B |
|
After Width: | Height: | Size: 320 B |
|
After Width: | Height: | Size: 396 B |
|
After Width: | Height: | Size: 471 B |
|
After Width: | Height: | Size: 534 B |
|
After Width: | Height: | Size: 615 B |
|
After Width: | Height: | Size: 686 B |
|
After Width: | Height: | Size: 781 B |
|
After Width: | Height: | Size: 855 B |