前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >防溺水智能预警系统解决方案

防溺水智能预警系统解决方案

原创
作者头像
燧机科技
修改2023-09-21 10:39:05
3030
修改2023-09-21 10:39:05
举报
文章被收录于专栏:燧机科技-视频AI智能分析

防溺水智能预警系统算法采用yolov7先进的AI视觉识别算法模型框架,防溺水智能预警系统算法实现对危险水域人员活动、水面情况等各项指标的监测和分析。当发现有人进入危险水域或出现紧急情况时,算法会立即发出预警信号。防溺水智能预警系统算法采用一个单独的CNN模型实现end-to-end的目标检测,首先将输入图片resize到448x448,然后送入CNN网络,最后处理网络预测结果得到检测的目标。

代码语言:javascript
复制
def yolo_filter_boxes(box_confidence, boxes, box_class_probs, threshold = .6):
    """Filters YOLO boxes by thresholding on object and class confidence.
    
    Arguments:
    box_confidence -- tensor of shape (19, 19, 5, 1)
    boxes -- tensor of shape (19, 19, 5, 4)
    box_class_probs -- tensor of shape (19, 19, 5, 80)
    threshold -- real value, if [ highest class probability score < threshold], then get rid of the corresponding box
    
    Returns:
    scores -- tensor of shape (None,), containing the class probability score for selected boxes
    boxes -- tensor of shape (None, 4), containing (b_x, b_y, b_h, b_w) coordinates of selected boxes
    classes -- tensor of shape (None,), containing the index of the class detected by the selected boxes
    
    Note: "None" is here because you don't know the exact number of selected boxes, as it depends on the threshold. 
    For example, the actual output size of scores would be (10,) if there are 10 boxes.
    """
    
    # Step 1: 计算 box scores
    box_scores = box_confidence*box_class_probs
     # Step 2: 通过最大的box scores找到对应最大的box_class
    box_classes = K.argmax(box_scores,axis=-1)
    box_class_scores = K.max(box_scores,axis=-1)

    # Step 3: 设置过滤器
    filtering_mask = box_class_scores >= threshold

   # Step 4: 把过滤器应用到scores, boxes and classes
    ### START CODE HERE ### (≈ 3 lines)
    scores = tf.boolean_mask(box_class_scores, filtering_mask)
    boxes = tf.boolean_mask(boxes, filtering_mask)
    classes = tf.boolean_mask(box_classes, filtering_mask)

在介绍防溺水智能预警系统算法之前,首先先介绍一下滑动窗口技术,这对我们理解算法是有帮助的。防溺水智能预警系统算法采用滑动窗口的目标检测算法思路非常简单,它将检测问题转化为了图像分类问题。其基本原理就是采用不同大小和比例(宽高比)的窗口在整张图片上以一定的步长进行滑动,然后对这些窗口对应的区域做图像分类,这样就可以实现对整张图片的检测了,如DPM就是采用这种思路。但是这个方法有致命的缺点,就是你并不知道要检测的目标大小是什么规模,所以你要设置不同大小和比例的窗口去滑动,而且还要选取合适的步长。但是这样会产生很多的子区域,并且都要经过分类器去做预测,这需要很大的计算量,所以你的分类器不能太复杂,因为要保证速度。解决思路之一就是减少要分类的子区域,这就是R-CNN的一个改进策略,防溺水智能预警系统算法采用了selective search方法来找到最有可能包含目标的子区域(Region Proposal),其实可以看成采用启发式方法过滤掉很多子区域,这会提升效率。

防溺水智能预警系统算法模型精度和推理性能比较均衡的是yolov7 模型(对应的开源git版本为0.1版)。根据源码+导出的onnx文件+“张大刀”等的网络图(修改了其中目前我认为的一些bug,增加一些细节)。防溺水智能预警系统算法重新绘制了yoloV7 0.1版本的非常详尽网络结构。注意:

1)其中的特征图结果维度注释是按照箭头的流方向,不是固定的上下方向。

2)输入输出仅仅是指当前模块的输入输出,整体需要根据流方向累乘计算最终的结果。

3)防溺水智能预警系统算法模型版本没有辅助训练头。

防溺水智能预警系统算法整体上和YOLOV5是相似的,主要是网络结构的内部组件的更换(涉及一些新的sota的设计思想)、辅助训练头、标签分配思想等。整体预处理、loss等可参考yolov5

代码语言:javascript
复制
def iou(box1, box2):
Arguments:
    box1 -- first box, list object with coordinates (x1, y1, x2, y2)
    box2 -- second box, list object with coordinates (x1, y1, x2, y2)
    """


    # Calculate the (y1, x1, y2, x2) coordinates of the intersection of box1 and box2. Calculate its Area.

    xi1 = max(box1[0],box2[0])
    yi1 = max(box1[1],box2[1])
    xi2 = min(box1[2],box2[2])
    yi2 = min(box1[3],box2[3])
    inter_area = (xi2-xi1)*(yi2-yi1) 

    # Calculate the Union area by using Formula: Union(A,B) = A + B - Inter(A,B)
    box1_area = (box1[2]-box1[0])*(box1[3]-box1[1])
    box2_area = (box2[2]-box2[0])*(box2[3]-box2[1])
    union_area = (box1_area+box2_area) - inter_area
    
    # compute the IoU
    iou = inter_area/union_area

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档