# acl_yolov5 **Repository Path**: yukming_law/acl_yolov5 ## Basic Information - **Project Name**: acl_yolov5 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 1 - **Created**: 2021-08-24 - **Last Updated**: 2025-06-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## ACL YoloV5 Demo #### 1.modify torch model requirment onnx >= 1.9 & numpy >= 1.17 1.1 modify the focus modular in models/common.py ``` class Focus(nn.Module): def forward(self, x): # x(b,c,w,h) -> y(b,4c,w/2,h/2) # <==== 修改内容 if torch.onnx.is_in_onnx_export(): a, b = x[..., ::2, :].transpose(-2, -1), x[..., 1::2, :].transpose(-2, -1) c = torch.cat([a[..., ::2, :], b[..., ::2, :], a[..., 1::2, :], b[..., 1::2, :]], 1).transpose(-2, -1) return self.conv(c) else: return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1)) # return self.conv(self.contract(x)) # =====> ``` 1.2 delete the postprocess in models/yolo.py ``` class Detect(nn.Module): def forward(self, x): # ... # <==== 修改内容 self.training = True # v6.0版本需补充该行 # =====> for i in range(self.nl): x[i] = self.m[i](x[i]) # conv # <==== 修改内容 if torch.onnx.is_in_onnx_export(): continue # =====> 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() # ... ``` 1.3 export onnx model ``` python3.7 models/export.py --weights=./yolov5s.pt --img-size=640 --batch-size 1 ``` #### 2.transfer onnx to om with ATC ```shell source /usr/local/Ascend/ascend-toolkit/set_env.sh atc --model=yolov5m.onnx --framework=5 --output=yolov5m --soc_version=Ascend310 --insert_op_conf=aipp_rgb.cfg --input_format=NCHW --input_shape="images:1,3,640,640" ``` #### 3.run demo 3.1 modify the classes number in AclProcess/AclProcess.cpp ``` #define CLASSES_NUM 80 ``` 3.2 ```shell mkdir build cd build cmake .. make ./ACL_YOLOV5 ./model/yollov5.om ./data/test.jpg ```