资源简介

基于深度学习的实时车辆检测代码,详情见博客:http://blog.csdn.net/adamshan/article/details/79193775

资源截图

代码片段和文件信息

# code based on:
# YAD2K https://github.com/allanzelener/YAD2K
# darkflow https://github.com/thtrieu/darkflow
# Darknet.keras https://github.com/sunshineatnoon/Darknet.keras

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])


def load_weights(model yolo_weight_file):
    tiny_data = np.fromfile(yolo_weight_file np.float32)[4:]

    index = 0
    for layer in model.layers:
        weights = layer.get_weights()
        if len(weights) > 0:
            filter_shape bias_shape = [w.shape for w in weights]
            if len(filter_shape) > 2:  # For convolutional layers
                filter_shape_i = filter_shape[::-1]
                bias_weight = tiny_data[index:index + np.prod(bias_shape)].reshape(bias_shape)
                index += np.prod(bias_shape)
                filter_weight = tiny_data[index:index + np.prod(filter_shape_i)].reshape(filter_shape_i)
                filter_weight = np.transpose(filter_weight (2 3 1 0))
                index += np.prod(filter_shape)
                layer.set_weights([filter_weight bias_weight])
            else:  # For regular hidden layers
                bias_weight = tiny_data[index:index + np.prod(bias_shape)].reshape(bias_shape)
                index += np.prod(bias_shape)
                filter_weight = tiny_data[index:index + np.prod(filter_shape)].reshape(filter_shape)
                index += np.prod(filter_shape)
                layer.set_weights([filter_weight bias_weight])


class Box:
    def __init__(self):
        self.x self.y = float() float()
        self.w self.h = float() float()
        self.c = float()
        self.prob = float()


def overlap(x1 w1 x2 w2):
    l1 = x1 - w1 / 2.
    l2 = x2 - w2 / 2.
    left = max(l1 l2)
    r1 = x1 + w1 / 2.
    r2 = x2 + w2 / 2.
    right = min(r1 r2)
    return right - left


def box_intersection(a b):
    w = overlap(a.x a.w b.x b.w)
    h = overlap(a.y a.h b.y b.h)
    if w < 0 or h < 0: return 0
    area = w * h
    return area


def box_union(a b):
    i = box_intersection(a b)
    u = a.w * a.h + b.w * b.h - i
    return u


def box_iou(a b):
    return box_intersection(a b) / box_union(a b)


def yolo_net_out_to_car_boxes(net_out threshold=0.2 sqrt=1.8 C=20 B=2 S=7):
    class_num = 6
    boxes = []
    SS = S * S  # number of grid cells
    prob_size = SS * C  # class probabilities
    conf_size = SS * B  # confidences for each grid cell

    probs = net_out[0: prob_size]
   

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-01-29 01:40  test_images\
     文件      232093  2018-01-29 01:40  test_images\test6.jpg
     文件      243874  2018-01-29 01:40  test_images\test5.jpg
     文件      201192  2018-01-29 01:40  test_images\test4.jpg
     文件      147583  2018-01-29 01:40  test_images\test3.jpg
     文件      174209  2018-01-29 01:40  test_images\test2.jpg
     文件      217239  2018-01-29 01:40  test_images\test1.jpg
     目录           0  2018-01-29 01:42  utils\
     文件        4867  2018-01-29 01:40  utils\utils.py
     文件         140  2018-01-29 01:42  utils\__init__.pyc
     文件        4629  2018-01-29 01:42  utils\utils.pyc
     文件          21  2018-01-29 01:40  utils\__init__.py
     文件     1002237  2018-01-29 03:59  car_detection.ipynb
     文件    11389950  2018-01-29 02:12  cartail0.avi

评论

共有 条评论