forked from subodh-malgonde/vehicle-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
24 lines (20 loc) · 797 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# code based on:
# YAD2K https://github.com/allanzelener/YAD2K
# darkflow https://github.com/thtrieu/darkflow
# Darknet.keras https://github.com/sunshineatnoon/Darknet.keras
# https://github.com/xslittlegrass/CarND-Vehicle-Detection
import numpy as np
import cv2
def load_weights(model, yolo_weight_file):
data = np.fromfile(yolo_weight_file, np.float32)
data = data[4:]
index = 0
for layer in model.layers:
shape = [w.shape for w in layer.get_weights()]
if shape != []:
kshape, bshape = shape
bia = data[index:index + np.prod(bshape)].reshape(bshape)
index += np.prod(bshape)
ker = data[index:index + np.prod(kshape)].reshape(kshape)
index += np.prod(kshape)
layer.set_weights([ker, bia])