人员拥挤检测系统通过Python网络模型算法技术,人员拥挤检测算法对校园/厂区/车间/港口/街道等场景的监控画面区域实现7X24小时全天候不间断进行自动分析监测,当人员拥挤检测算法监测到现场区域范围内,有异常的人群聚集(出现拥挤情况)时,人员拥挤检测算法会立刻抓拍存档并通知相关后台人员及时查看处理群疏散。
Python是一种由Guido van Rossum开发的通用编程语言,它很快就变得非常流行,主要是因为它的简单性和代码可读性。它使程序员能够用更少的代码行表达思想,而不会降低可读性。与C / C++等语言相比,Python速度较慢。也就是说,Python可以使用C / C++轻松扩展,这使我们可以在C / C++中编写计算密集型代码,并创建可用作Python模块的Python包装器。这给我们带来了两个好处:首先,代码与原始C / C++代码一样快(因为它是在后台工作的实际C++代码),其次,在Python中编写代码比使用C / C++更容易。OpenCV-Python是原始OpenCV C++实现的Python包装器。
随着社会的发展和人们生活水平的快速进步,大家对于日常生产生活场景下的人员人身安全越来越重视。不管是在校园、工地、商场、厂区车间还是城市街道。人员异常拥挤,会引发扎堆人群的相继摇晃,很容易发生踩踏事件。特别是,当一个人失去重心摔倒,非常产生安全隐患。
class Detect(nn.Module):
stride = None # strides computed during build
onnx_dynamic = False # ONNX export parameter
def __init__(self, nc=80, anchors=(), ch=(), inplace=True): # detection layer
super().__init__()
self.nc = nc # number of classes
self.no = nc + 5 # number of outputs per anchor
self.nl = len(anchors) # number of detection layers
self.na = len(anchors[0]) // 2 # number of anchors
self.grid = [torch.zeros(1)] * self.nl # init grid
self.anchor_grid = [torch.zeros(1)] * self.nl # init anchor grid
self.register_buffer('anchors', torch.tensor(anchors).float().view(self.nl, -1, 2)) # shape(nl,na,2)
self.m = nn.ModuleList(nn.Conv2d(x, self.no * self.na, 1) for x in ch) # output conv
self.inplace = inplace # use in-place ops (e.g. slice assignment)
def forward(self, x):
z = [] # inference output
for i in range(self.nl):
x[i] = self.m[i](x[i]) # conv
bs, _, ny, nx = x[i].shape # x(bs,255,20,20) to x(bs,3,20,20,85)
x[i] = x[i].view(bs, self.na, self.no, ny, nx).permute(0, 1, 3, 4, 2).contiguous()
if not self.training: # inference
if self.onnx_dynamic or self.grid[i].shape[2:4] != x[i].shape[2:4]:
self.grid[i], self.anchor_grid[i] = self._make_grid(nx, ny, i)
y = x[i].sigmoid()
if self.inplace:
y[..., 0:2] = (y[..., 0:2] * 2 - 0.5 + self.grid[i]) * self.stride[i] # xy
y[..., 2:4] = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i] # wh
else: # for YOLOv5 on AWS Inferentia https://github.com/ultralytics/yolov5/pull/2953
xy = (y[..., 0:2] * 2 - 0.5 + self.grid[i]) * self.stride[i] # xy
wh = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i] # wh
y = torch.cat((xy, wh, y[..., 4:]), -1)
z.append(y.view(bs, -1, self.no))
return x if self.training else (torch.cat(z, 1), x)
def _make_grid(self, nx=20, ny=20, i=0):
d = self.anchors[i].device
if check_version(torch.__version__, '1.10.0'): # torch>=1.10.0 meshgrid workaround for torch>=0.7 compatibility
yv, xv = torch.meshgrid([torch.arange(ny).to(d), torch.arange(nx).to(d)], indexing='ij')
else:
yv, xv = torch.meshgrid([torch.arange(ny).to(d), torch.arange(nx).to(d)])
grid = torch.stack((xv, yv), 2).expand((1, self.na, ny, nx, 2)).float()
anchor_grid = (self.anchors[i].clone() * self.stride[i]) \
.view((1, self.na, 1, 1, 2)).expand((1, self.na, ny, nx, 2)).float()
return grid, anchor_grid
人员拥挤检测系统对街道/生产车间/校园等现场监控区域实时监测,人员拥挤检测算法当监测到监控画面中人数达到或者超过后台设置的范围数量时,不需人为干预,人员拥挤检测系统立即告警,同时将告警截图和视频推送给相关后台人员提醒后台工作人员及时处理疏散。人员拥挤检测系统通过AI智能分析技术手段,有效避免踩踏、滋事等事故,提升现场监控区域的管控效率及时控制局面,有效避免意外事故的发生,确保现场安全。
标签:anchors,Python,拥挤,self,torch,grid,检测,anchor From: https://blog.51cto.com/u_16270964/11899755