前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >AI人员打架识别算法

AI人员打架识别算法

原创
作者头像
燧机科技
发布2023-09-22 09:02:27
4440
发布2023-09-22 09:02:27
举报

AI打架识别算法基于Detection网络模型算法框架,AI打架识别算法识别校园打架斗殴行为,发现立即打架斗殴行为算法会立即抓拍告警推送打架事件信息。AI人员打架识别算法目标检测架构分为两种,一种是two-stage,一种是one-stage,区别就在于 two-stage 有region proposal过程,类似于一种海选过程,网络会根据候选区域生成位置和类别,而AI人员打架识别算法直接从图片生成位置和类别。

1. 研究现状

目前AI人员打架识别算法,主要有3种主流的方法,分别是:

(1)基于Detection的打架检测。其主要思想是: 将打架作为一种类别,通过分类的方式,将打架行为检测出来。目前这方面的研究较少,且没有公开可用的数据集,想要沿着这条路走,需自备数据集,自行探索。

(2)基于骨骼点的打架检测。其主要思想是:通过OpenPose等框架,将人体的骨骼点回归出来,然后基于骨骼点写逻辑,进行判断。目前有一部分人是基于这个做的打架检测。但是打架过程中如果人员纠缠在一起的话,利用骨骼点准确判断就比较困难。

(3)基于视频理解的打架检测。其主要思想是: 基于时序进行判断。打架对时序有着较强的依赖,利用目标检测技术去识别打架容易出现误检测或者漏检情况。另外如果人员重叠遮挡严重的话,基于骨骼点的行为识别,就有很大的局限性。而基于视频理解的打架检测,则较好的解决了这些问题。但是这种实现起来难度也较大。

2.选取的方案

我这里选择方案1,AI人员打架识别算法基于目标检测做打架识别。前文也提到了,目前数据集十分匮乏。笔者也是反复查找,终于拿到了国外的一份很好的数据集。考虑到不同于一般的目标检测任务,所以数据集也是笔者亲自标注的,没有让第三方人员介入,目的就是保证标注的合理与精准。

基本流程是:

Labelme标注 -> 标注数据整理与格式转换 -> AI人员打架识别算法模型训练 -> 部署

2.2 AI人员打架识别算法标注数据整理与格式转换

        Labelme标注的数据,无法直接用在训练中,需要自己再转换下。因为准备采用Yolo算法,所以这里我们要将Labelme格式转换成Yolo格式。以下是转换脚本:

代码语言:javascript
复制
"""
2023.1.1
该代码实现了labelme导出的json文件,批量转换成yolo需要的txt文件,且包含了坐标归一化
原来labelme标注之后的是:1.jpg  1.json
经过该脚本处理后,得到的是1.jpg 1.json 1.txt
"""
import os
import numpy as np
import json
from glob import glob
import cv2
from sklearn.model_selection import train_test_split
from os import getcwd
 
classes = ["NOFight", "Fight", "Person"]
# 1.标签路径
labelme_path = "Data20200108/"
isUseTest = False  # 是否创建test集
# 3.获取待处理文件
files = glob(labelme_path + "*.json")
files = [i.replace("\\", "/").split("/")[-1].split(".json")[0] for i in files]
print(files)
if isUseTest:
    trainval_files, test_files = train_test_split(files, test_size=0.1, random_state=55)
else:
    trainval_files = files
# split
train_files, val_files = train_test_split(trainval_files, test_size=0.1, random_state=55)
 
 
def convert(size, box):
    dw = 1. / (size[0])
    dh = 1. / (size[1])
    x = (box[0] + box[1]) / 2.0 - 1
    y = (box[2] + box[3]) / 2.0 - 1
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x * dw
    w = w * dw
    y = y * dh
    h = h * dh
    return (x, y, w, h)
 
 
wd = getcwd()
print(wd)
 
 
def ChangeToYolo5(files, txt_Name):
    if not os.path.exists('tmp/'):
        os.makedirs('tmp/')
    list_file = open('tmp/%s.txt' % (txt_Name), 'w')
    for json_file_ in files:
        json_filename = labelme_path + json_file_ + ".json"
        imagePath = labelme_path + json_file_ + ".jpg"
        list_file.write('%s/%s\n' % (wd, imagePath))
        out_file = open('%s/%s.txt' % (labelme_path, json_file_), 'w')
        json_file = json.load(open(json_filename, "r", encoding="utf-8"))
        height, width, channels = cv2.imread(labelme_path + json_file_ + ".jpg").shape
        for multi in json_file["shapes"]:
            points = np.array(multi["points"])
            xmin = min(points[:, 0]) if min(points[:, 0]) > 0 else 0
            xmax = max(points[:, 0]) if max(points[:, 0]) > 0 else 0
            ymin = min(points[:, 1]) if min(points[:, 1]) > 0 else 0
            ymax = max(points[:, 1]) if max(points[:, 1]) > 0 else 0
            label = multi["label"]
            if xmax <= xmin:
                pass
            elif ymax <= ymin:
                pass
            else:
                cls_id = classes.index(label)
                b = (float(xmin), float(xmax), float(ymin), float(ymax))
                bb = convert((width, height), b)
                out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
                print(json_filename, xmin, ymin, xmax, ymax, cls_id)
 
 
ChangeToYolo5(train_files, "train")
ChangeToYolo5(val_files, "val")
# ChangeToYolo5(test_files, "test")

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

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 2.2 AI人员打架识别算法标注数据整理与格式转换
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档