基于轻量级卷积神经网络CNN开发构建打架斗殴识别分析系统

在很多公共场合中,因为一些不可控因素导致最终爆发打架斗殴或者大规则冲突事件的案例层出不穷,基于视频监控等技术手段智能自动化地识别出已有或者潜在的危险行为对于维护公共场合的安全稳定有着重要的意义。本文的核心目的就是想要基于CNN模型来尝试开发构建公众场景下的打架斗殴行为识别系统,这里我们从互联网中采集了相当批量的聚众数据,首先看下效果:
 

接下来看下数据集:

【有打架斗殴】

【无打架斗殴】

数据主要来源于互联网数据采集和后期的人工处理标注。

可以借助我编写的数据集随机划分函数,便捷地生成训练集-测试集,如下所示:

def randomSplit(dataDir="data/",train_ratio=0.80):"""数据集随机划分"""if not os.path.exists("labels.json") or not os.path.exists("dataset.json"):pic_list=[]labels_list = os.listdir(dataDir)labels_list.sort()print("labels_list: ", labels_list)with open("labels.json", "w") as f:f.write(json.dumps(labels_list))for one_label in os.listdir(dataDir):oneDir=dataDir+one_label+"/"one_list=[oneDir+one for one in os.listdir(oneDir)]pic_list+=one_listlength=len(pic_list)print("length: ", length)train_num=int(length*train_ratio)test_num=length-train_numprint("train_num: ", train_num, ", test_num: ", test_num)train_list=random.sample(pic_list, train_num)test_list=[one for one in pic_list if one not in train_list]dataset={}dataset["train"]=train_listdataset["test"]=test_listwith open("dataset.json","w") as f:f.write(json.dumps(dataset))else:print("Not Need To SplitData Again!!!!!")

接下来需要加载本地图像数据来解析创建可直接用于后续模型训练计算的数据集,核心实现如下所示:

def buildDataset():"""加载本地数据集创建数据集"""X_train, y_train = [], []X_test, y_test = [], []train_list=dataset["train"]test_list=dataset["test"]picDir = "data/train/"#训练集for one_path in train_list:try:print("one_path: ", one_path)one_img = parse4Img(one_path)one_y = parse4Label(one_pic_classes,labels_list)X_train.append(one_img)y_train.append(one_y)except Exception as e:print("train Exception: ", e)X_train = np.array(X_train)#测试集for one_path in test_list:try:print("one_path: ", one_path)one_img = parse4Img(one_path)one_y = parse4Label(one_pic_classes,labels_list)X_test.append(one_img)y_test.append(one_y)except Exception as e:print("test Exception: ", e)X_test = np.array(X_test)

完成数据集的解析构建之后就可以进行模型的开发训练工作了。

这部分可以参考我前面的博文的实现即可,这里就不再赘述了。本文中搭建的轻量级模型结构详情如下所示:

{"class_name": "Sequential","config": {"name": "sequential_1","layers": [{"class_name": "Conv2D","config": {"name": "conv2d_1","trainable": true,"batch_input_shape": [null, 100, 100, 3],"dtype": "float32","filters": 64,"kernel_size": [3, 3],"strides": [2, 2],"padding": "same","data_format": "channels_last","dilation_rate": [1, 1],"activation": "relu","use_bias": true,"kernel_initializer": {"class_name": "RandomUniform","config": {"minval": -0.05,"maxval": 0.05,"seed": null}},"bias_initializer": {"class_name": "Zeros","config": {}},"kernel_regularizer": null,"bias_regularizer": null,"activity_regularizer": null,"kernel_constraint": null,"bias_constraint": null}}, {"class_name": "MaxPooling2D","config": {"name": "max_pooling2d_1","trainable": true,"pool_size": [2, 2],"padding": "valid","strides": [2, 2],"data_format": "channels_last"}}, {"class_name": "Conv2D","config": {"name": "conv2d_2","trainable": true,"filters": 128,"kernel_size": [3, 3],"strides": [2, 2],"padding": "same","data_format": "channels_last","dilation_rate": [1, 1],"activation": "relu","use_bias": true,"kernel_initializer": {"class_name": "RandomUniform","config": {"minval": -0.05,"maxval": 0.05,"seed": null}},"bias_initializer": {"class_name": "Zeros","config": {}},"kernel_regularizer": null,"bias_regularizer": null,"activity_regularizer": null,"kernel_constraint": null,"bias_constraint": null}}, {"class_name": "MaxPooling2D","config": {"name": "max_pooling2d_2","trainable": true,"pool_size": [2, 2],"padding": "valid","strides": [2, 2],"data_format": "channels_last"}}, {"class_name": "Conv2D","config": {"name": "conv2d_3","trainable": true,"filters": 256,"kernel_size": [3, 3],"strides": [2, 2],"padding": "same","data_format": "channels_last","dilation_rate": [1, 1],"activation": "relu","use_bias": true,"kernel_initializer": {"class_name": "RandomUniform","config": {"minval": -0.05,"maxval": 0.05,"seed": null}},"bias_initializer": {"class_name": "Zeros","config": {}},"kernel_regularizer": null,"bias_regularizer": null,"activity_regularizer": null,"kernel_constraint": null,"bias_constraint": null}}, {"class_name": "MaxPooling2D","config": {"name": "max_pooling2d_3","trainable": true,"pool_size": [2, 2],"padding": "valid","strides": [2, 2],"data_format": "channels_last"}}, {"class_name": "Flatten","config": {"name": "flatten_1","trainable": true,"data_format": "channels_last"}}, {"class_name": "Dense","config": {"name": "dense_1","trainable": true,"units": 256,"activation": "relu","use_bias": true,"kernel_initializer": {"class_name": "VarianceScaling","config": {"scale": 1.0,"mode": "fan_avg","distribution": "uniform","seed": null}},"bias_initializer": {"class_name": "Zeros","config": {}},"kernel_regularizer": null,"bias_regularizer": null,"activity_regularizer": null,"kernel_constraint": null,"bias_constraint": null}}, {"class_name": "Dropout","config": {"name": "dropout_1","trainable": true,"rate": 0.1,"noise_shape": null,"seed": null}}, {"class_name": "Dense","config": {"name": "dense_2","trainable": true,"units": 512,"activation": "relu","use_bias": true,"kernel_initializer": {"class_name": "VarianceScaling","config": {"scale": 1.0,"mode": "fan_avg","distribution": "uniform","seed": null}},"bias_initializer": {"class_name": "Zeros","config": {}},"kernel_regularizer": null,"bias_regularizer": null,"activity_regularizer": null,"kernel_constraint": null,"bias_constraint": null}}, {"class_name": "Dropout","config": {"name": "dropout_2","trainable": true,"rate": 0.15,"noise_shape": null,"seed": null}}, {"class_name": "Dense","config": {"name": "dense_3","trainable": true,"units": 2,"activation": "softmax","use_bias": true,"kernel_initializer": {"class_name": "VarianceScaling","config": {"scale": 1.0,"mode": "fan_avg","distribution": "uniform","seed": null}},"bias_initializer": {"class_name": "Zeros","config": {}},"kernel_regularizer": null,"bias_regularizer": null,"activity_regularizer": null,"kernel_constraint": null,"bias_constraint": null}}]},"keras_version": "2.2.4","backend": "tensorflow"
}

默认200次epoch的迭代计算,训练完成后,对loss曲线和acc曲线进行了对比可视化展示,如下所示:

【loss对比曲线】

【acc对比曲线】

可以看到:模型的效果还是很不错的。

最后编写专用的可视化系统界面,进行实例化推理展示,实例结果如下所示:

后续的工作考虑结合视频连续帧的特点来进一步提升打架斗殴行为的识别精度,感兴趣的话也都可以自行尝试实践一下。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/140171.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Mathtype公式自动转Word自带公式

Mathtype公式自动转Word自带公式 前言/word技巧探索过程参考资料(有效与无效)全自动方案/代码/教程 前言/word技巧 word公式 用ALT号可以输入简单latex显示公式;复杂度,需要引入latex包的不行;显示不出来的话按一下en…

CentOS指令学习

目录 一、常用命令 1、ls 2、cd_pwd 3、touch_mkdir_rmdir_rm 4、cp_mv 5、whereis_which_PATH 6、find 7、grep 8、man_help 9、关机与重启 二、压缩解压 1、zip_unzip 2、gzip_gunzip 3、tar 三、其他指令 1、查看用户登录信息 2、磁盘使用情况 3、查看文件…

74HC165 并入串出

/******************************************************** 程序名:main.C 版 本:Ver1.0 芯 片:AT89C51或STC89C51 晶 体:片外12MHz 编 程: Joey 日 期:2023-11-13 描 述:通过 74HC165 对 16 按键…

Radius是什么意思? 安当加密

Radius是什么意思? RADIUS(Remote Authentication Dial In User Service)是一种远程用户拨号认证系统,它由RFC 2865和RFC 2866定义,是应用最广泛的AAA(Authentication、Authorization、Accounting&#xf…

Codeforces Round 788 (Div. 2) E. Hemose on the Tree(树上构造)

题目 t(t<5e4)组样例&#xff0c;每次给定一个数p&#xff0c; 表示一棵节点数为的树&#xff0c; 以下n-1条边&#xff0c;读入树边 对于n个点和n-1条边&#xff0c;每个点需要赋权&#xff0c;每条边需要赋权&#xff0c; 权值需要恰好构成[1,2n-1]的排列 并且当你赋…

《网络协议》04. 应用层(DNS DHCP HTTP)

title: 《网络协议》04. 应用层&#xff08;DNS & DHCP & HTTP&#xff09; date: 2022-09-05 14:28:22 updated: 2023-11-12 06:55:52 categories: 学习记录&#xff1a;网络协议 excerpt: 应用层、DNS、DHCP、HTTP&#xff08;URI & URL&#xff0c;ABNF&#xf…

【数据结构初阶】顺序表SeqList

描述 顺序表我们可以把它想象成在一个表格里面填数据&#xff0c;并对数据做调整&#xff1b; 那我们的第一个问题是&#xff1a;怎么样在创建出足够的空间呢&#xff1f; 我们可以去堆上申请&#xff0c;用一个指针指向一块空间&#xff0c;如果申请的空间不够&#xff0c;我…

Linux 部署Sentinel控制台

Sentinel 是面向分布式、多语言异构化服务架构的流量治理组件&#xff0c;主要以流量为切入点&#xff0c;从流量路由、流量控制、流量整形、熔断降级、系统自适应过载保护、热点流量防护等多个维度来帮助开发者保障微服务的稳定性。 1.版本选择 SpringCloudAlibaba SpringClo…

已解决:java.net.BindException: 地址已在使用

解决zookeeper报错&#xff1a;java.net.BindException: 地址已在使用&#xff0c;是因为端口被占用。显示Starting zookeeper ... STARTED&#xff0c;jps没有QuorumPeerMain进程。 问题截图&#xff1a; 看似Starting zookeeper ... STARTED&#xff0c;实则集群并没有启动…

2023.11.9 IDEA 配置 Lombok

目录 什么是 Lombok 如何使用 Lombok Lombok 的 Data 注解 什么是 Lombok Lombok 是一个 Java 库&#xff0c;能自动插入编译器并构建工具&#xff0c;简化 Java 开发它通过注解实现这一目的&#xff0c;可用来帮助开发人员消除 Java 的冗长代码&#xff0c;尤其是对于简单…

终端安全/SOC安全/汽车信息安全大课来袭-共计204节课

在近两年的时间里&#xff0c;我投入了大量的心血和精力&#xff0c;不仅创作了数千篇精美的图片&#xff0c;还编写了超过1000篇文章&#xff0c;以及数百篇内容丰富的PPT。经过这番努力我终于成功地构建出两套系统化的学习课程&#xff0c;它们分别是“Trustzone/TEE/安全从入…

什么是 CASB,在网络安全中的作用

数字化转型正在稳步攀升&#xff0c;组织现在越来越关注在线生产力系统和协作平台&#xff0c;各行各业的企业都采用了不同的云基础设施服务模式。云基础架构提供按需服务&#xff0c;可提高易用性、访问控制、内容协作和减少内部存储资源&#xff0c;以及许多其他好处。迁移到…

go学习之接口知识

文章目录 接口1.接口案例代码展示2.基本介绍3.基本语法4.应用场景介绍5.注意事项和细节6.接口编程经典案例7.接口与继承之间的比较8.面向对象编程--多态1&#xff09;基本介绍2&#xff09;快速入门3&#xff09;接口体现多态的两种形式 9.类型断言1&#xff09;先看一个需求2&…

登顶request模块

华子目录 Requests介绍安装requests模块常用方法常用属性实例引入各种请求方式基于get请求带参数的get请求推荐写法 基于post请求添加headers信息content获取二进制数据bytes类型获取json数据第一种方式第二种方式 response响应状态码判断 高级操作会话维持通过cookie维持会话通…

【Vue3】scoped 和样式穿透

我们使用很多 vue 的组件库&#xff08;element-plus、vant&#xff09;&#xff0c;在修改样式的时候需要进行其他操作才能成功更改样式&#xff0c;此时就用到了样式穿透。 而不能正常更改样式的原因就是 scoped 标记。 scoped 的渲染规则&#xff1a; <template>&l…

U-Mail邮件中继,让海外邮件沟通更顺畅

在海外&#xff0c;电子邮件是人们主要的通信工具&#xff0c;尤其是商务往来沟通&#xff0c;企业邮箱是标配。这主要是因为西方国家互联网发展较早&#xff0c;在互联网早期&#xff0c;电子邮件技术较为成熟&#xff0c;大家都用电子邮件交流&#xff0c;于是这成了一种潮流…

Android 基本属性绘制文本对象FontMetrics

FontMetrics对象 它以四个基本坐标为基准&#xff0c;分别为&#xff1a; ・FontMetrics.top ・FontMetrics.ascent ・FontMetrics.descent ・FontMetrics.bottom 如图: 要点如下&#xff1a; 1. 基准点是baseline 2. Ascent是baseline之上至字符最高处的距离 3. Descent是ba…

RT-Thread:嵌入式实时操作系统的设计与应用

RT-Thread&#xff08;Real-Time Thread&#xff09;是一个开源的嵌入式实时操作系统&#xff0c;其设计和应用在嵌入式领域具有重要意义。本文将从RT-Thread的设计理念、核心特性&#xff0c;以及在嵌入式系统中的应用等方面进行探讨&#xff0c;对其进行全面的介绍。 首先&a…

SMART PLC MODBUSTCP速度测试

SMART PLC MODBUSTCP通信详细介绍请参看下面文章链接: S7-200SMART PLC ModbusTCP通信(多服务器多从站轮询)_matlab sumilink 多个modbustcp读写_RXXW_Dor的博客-CSDN博客文章浏览阅读6.4k次,点赞5次,收藏10次。MBUS_CLIENT作为MODBUS TCP客户端通过S7-200 SMART CPU上的…

数据结构—二叉树的模拟实现(c语言)

目录 一.前言 二.模拟实现链式结构的二叉树 2.1二叉树的底层结构 2.2通过前序遍历的数组"ABD##E#H##CF##G##"构建二叉树 2.3二叉树的销毁 2.4二叉树查找值为x的节点 2.5二叉树节点个数 2.6二叉树叶子节点个数 2.7二叉树第k层节点个数 三.二叉树的遍历 3.1…