在当今社区中,电动车已经成为了常见的代步工具。然而,问题也开始显现出来。电动车缺乏有效的管控,区域缺乏专门停放的位置,导致许多人选择推电动车进电梯回家充电,或从高层引线,这无疑增加了风险。一旦电动车起火,会持续释放出有害烟尘,30秒足以致命;如电动车进电梯后起火乘客也无法顺利逃生,必然导致伤亡事故乃至特大安全事故。因此,现行的管理方式已经无法满足社区和小区的安全需求。
为了解决电动车进电梯所带来的安全隐患,电动车进电梯识别算法应运而生。电动车进电梯识别算法能够准确地识别电动车进电梯的行为,并且可以区分出其他类似车辆,例如自行车、手推车等。当电动车进电梯被识别出后,系统将会实时报警,及时通知管理人员进行处理。这项算法的核心优势在于其高效的识别能力和实时报警功能,可以有效地减少因电动车进电梯而引发的安全问题。
使用电动车进电梯识别算法能够取得显著的效果。首先,能够帮助管理人员维护电动车管理的秩序,减少因管理不规范而导致的混乱局面。其次,针对电动车进电梯的行为,该算法能够实现实时监控并及时报警,有助于管理人员及时发现和处理潜在的安全隐患,降低了电动车给人们带来的风险。通过应用该算法,我们可以更好地保障社区的安全,提升居民的生活品质。
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
总之,我们可以看到电动车进电梯识别算法在解决当前电动车管理难题上的重要作用。它不仅提高了管理效率,减少了安全风险,更为社区的居民带来了更安全、更舒适的生活环境。