Skip to content

Commit f7fab38

Browse files
committed
Added files.
0 parents  commit f7fab38

12 files changed

+753
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.swp
2+
*.pyc
3+
__pycache__/

README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Edge TPU - Tiny YOLO v3
2+
3+
![Demo](blob:https://giphy.com/755055f6-7e72-41e8-9721-c106ee4f5385)
4+
5+
This repository contains the instructions and scripts to run the Tiny YOLO-v3 on Google's Edge TPU USB Accelerator.
6+
7+
### 1 - Convert darknet .weights to Keras model
8+
The network can be trained using either the original darknet implementation (https://github.com/pjreddie/darknet) or one of its forks (e.g. https://github.com/AlexeyAB/darknet).
9+
10+
**Important note:** The Edge TPU does not support the Leaky ReLU function, so it should be replaced by the regular ReLU. (https://coral.ai/docs/edgetpu/models-intro/#supported-operations)
11+
12+
The darknet weights can be converted to a Keras model using: https://github.com/qqwweee/keras-yolo3. However, this implementation doesn't support the regular ReLU function. Additionally, the TF-Lite conversion later also requires the input shape to be explicit (instead of `None`). So, I've made a fork with the (stupidly simple) required modifications here: https://github.com/guichristmann/keras-yolo3.
13+
14+
python convert.py tiny-yolo-cfg.cfg darknet-weights.weights keras-filename.h5
15+
16+
### 2 - Convert Keras to TF-Lite model with full integer quantization.
17+
To run on Edge TPU, we need to convert the Keras model to TF-Lite and apply post-training full integer quantization. https://www.tensorflow.org/lite/performance/post_training_quantization.
18+
19+
python keras_to_tflite_quant.py keras-model.h5 output-filename.tflite
20+
21+
**Note**: The quantization of the `RESIZE_NEAREST_NEIGHBOR` op is only supported in Tensorflow nightly packages as of now, so you need use that for this script.
22+
23+
pip install tf-nightly
24+
25+
### 3 - Compile with Edge TPU compiler
26+
Install the Edge TPU library and compiler: https://coral.ai/docs/edgetpu/compiler/.
27+
28+
Run the compiler on the TF-Lite quantized model:
29+
30+
edgetpu_compiler quantized.tflite
31+
32+
If everyhing is correct you should get a log with every op mapped to Edge TPU:
33+
34+
Edge TPU Compiler version 2.0.267685300
35+
Input: quantized.tflite
36+
Output: quantized_edgetpu.tflite
37+
Operator Count Status
38+
RESIZE_NEAREST_NEIGHBOR 1 Mapped to Edge TPU
39+
MAX_POOL_2D 6 Mapped to Edge TPU
40+
CONCATENATION 1 Mapped to Edge TPU
41+
QUANTIZE 4 Mapped to Edge TPU
42+
CONV_2D 13 Mapped to Edge TPU

cfg/coco-tiny-v3-relu.cfg

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
[net]
2+
# Testing
3+
#batch=1
4+
#subdivisions=1
5+
# Training
6+
batch=32
7+
subdivisions=2
8+
width=416
9+
height=416
10+
channels=3
11+
momentum=0.9
12+
decay=0.0005
13+
angle=0
14+
saturation = 1.5
15+
exposure = 1.5
16+
hue=.1
17+
18+
learning_rate=0.001
19+
burn_in=1000
20+
max_batches = 1250416
21+
policy=steps
22+
steps=400000,450000
23+
scales=.1,.1
24+
25+
[convolutional]
26+
batch_normalize=1
27+
filters=16
28+
size=3
29+
stride=1
30+
pad=1
31+
activation=relu
32+
33+
[maxpool]
34+
size=2
35+
stride=2
36+
37+
[convolutional]
38+
batch_normalize=1
39+
filters=32
40+
size=3
41+
stride=1
42+
pad=1
43+
activation=relu
44+
45+
[maxpool]
46+
size=2
47+
stride=2
48+
49+
[convolutional]
50+
batch_normalize=1
51+
filters=64
52+
size=3
53+
stride=1
54+
pad=1
55+
activation=relu
56+
57+
[maxpool]
58+
size=2
59+
stride=2
60+
61+
[convolutional]
62+
batch_normalize=1
63+
filters=128
64+
size=3
65+
stride=1
66+
pad=1
67+
activation=relu
68+
69+
[maxpool]
70+
size=2
71+
stride=2
72+
73+
[convolutional]
74+
batch_normalize=1
75+
filters=256
76+
size=3
77+
stride=1
78+
pad=1
79+
activation=relu
80+
81+
[maxpool]
82+
size=2
83+
stride=2
84+
85+
[convolutional]
86+
batch_normalize=1
87+
filters=512
88+
size=3
89+
stride=1
90+
pad=1
91+
activation=relu
92+
93+
[maxpool]
94+
size=2
95+
stride=1
96+
97+
[convolutional]
98+
batch_normalize=1
99+
filters=1024
100+
size=3
101+
stride=1
102+
pad=1
103+
activation=relu
104+
105+
###########
106+
107+
[convolutional]
108+
batch_normalize=1
109+
filters=256
110+
size=1
111+
stride=1
112+
pad=1
113+
activation=relu
114+
115+
[convolutional]
116+
batch_normalize=1
117+
filters=512
118+
size=3
119+
stride=1
120+
pad=1
121+
activation=relu
122+
123+
[convolutional]
124+
size=1
125+
stride=1
126+
pad=1
127+
filters=255
128+
activation=linear
129+
130+
131+
132+
[yolo]
133+
mask = 3,4,5
134+
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
135+
classes=80
136+
num=6
137+
jitter=.3
138+
ignore_thresh = .7
139+
truth_thresh = 1
140+
random=1
141+
142+
[route]
143+
layers = -4
144+
145+
[convolutional]
146+
batch_normalize=1
147+
filters=128
148+
size=1
149+
stride=1
150+
pad=1
151+
activation=relu
152+
153+
[upsample]
154+
stride=2
155+
156+
[route]
157+
layers = -1, 8
158+
159+
[convolutional]
160+
batch_normalize=1
161+
filters=256
162+
size=3
163+
stride=1
164+
pad=1
165+
activation=relu
166+
167+
[convolutional]
168+
size=1
169+
stride=1
170+
pad=1
171+
filters=255
172+
activation=linear
173+
174+
[yolo]
175+
mask = 0,1,2
176+
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
177+
classes=80
178+
num=6
179+
jitter=.3
180+
ignore_thresh = .7
181+
truth_thresh = 1
182+
random=1

cfg/coco.names

+80
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

cfg/tiny_yolo_anchors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10,14, 23,27, 37,58, 81,82, 135,169, 344,319

0 commit comments

Comments
 (0)