mirror of
https://github.com/Ascend/ascend_community_projects.git
synced 2025-09-26 20:01:17 +08:00
u
This commit is contained in:
@@ -16,7 +16,7 @@ yolov5s是非常优秀的轻量级检测网络,但是有时候模型依然比
|
||||
|
||||
### 1.2 支持的版本
|
||||
|
||||
本样例配套的CANN版本为[5.0.5](https://www.hiascend.com/software/cann/commercial)。支持的SDK版本为[2.0.4](https://www.hiascend.com/software/Mindx-sdk)。
|
||||
本样例配套的CANN版本为[5.0.4](https://www.hiascend.com/software/cann/commercial)。支持的SDK版本为[2.0.4](https://www.hiascend.com/software/Mindx-sdk)。
|
||||
|
||||
MindX SDK安装前准备可参考《用户指南》,[安装教程](https://gitee.com/ascend/mindxsdk-referenceapps/blob/master/docs/quickStart/1-1安装SDK开发套件.md)
|
||||
|
||||
@@ -176,7 +176,7 @@ $$
|
||||
|
||||
## 4 模型转换
|
||||
|
||||
ONNX模型可通过[地址]()获取,下载后使用模型转换工具 ATC 将 pb 模型转换为 om 模型,模型转换工具相关介绍参考链接:[https://support.huaweicloud.com/tg-cannApplicationDev330/atlasatc_16_0005.html](https://gitee.com/link?target=https%3A%2F%2Fsupport.huaweicloud.com%2Ftg-cannApplicationDev330%2Fatlasatc_16_0005.html) 。
|
||||
ONNX模型可通过[地址](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/ascend_community_projects/yolov5prune/prune_onnx.rar)获取,下载后使用模型转换工具 ATC 将 pb 模型转换为 om 模型,模型转换工具相关介绍参考链接:[https://support.huaweicloud.com/tg-cannApplicationDev330/atlasatc_16_0005.html](https://gitee.com/link?target=https%3A%2F%2Fsupport.huaweicloud.com%2Ftg-cannApplicationDev330%2Fatlasatc_16_0005.html) 。
|
||||
|
||||
模型转换,步骤如下:
|
||||
|
||||
|
BIN
YOLOv5Prune/compute_mAP/__pycache__/voc_eval.cpython-39.pyc
Normal file
BIN
YOLOv5Prune/compute_mAP/__pycache__/voc_eval.cpython-39.pyc
Normal file
Binary file not shown.
@@ -66,23 +66,22 @@ def do_eval(devkit_path, image_set, classes, output_dir):
|
||||
rec, prec, ap = evaluate(
|
||||
filename, annopath, imagesetfile, cls, cachedir, ovthresh=0.55)
|
||||
aps += [ap]
|
||||
print('AP for {} = {:.4f}'.format(cls, ap))
|
||||
|
||||
os.system('touch '+os.path.join(output_dir, cls + '_pr.pkl'))
|
||||
with open(os.path.join(output_dir, cls + '_pr.pkl'), 'rb+') as f:
|
||||
pickle.dump({'rec': rec, 'prec': prec, 'ap': ap}, f)
|
||||
print('Results:')
|
||||
print('~~~~~~~~')
|
||||
print('Mean AP = {:.4f}'.format(np.mean(aps)))
|
||||
print('~~~~~~~~')
|
||||
print('Results:')
|
||||
for ap in aps:
|
||||
print('{:.3f}'.format(ap))
|
||||
print('{:.3f}'.format(np.mean(aps)))
|
||||
for ap, cls in zip(aps, classes):
|
||||
print('AP for {} = {:.4f}'.format(cls, ap))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parse_args()
|
||||
|
||||
res_dir = os.path.abspath(args.output_dir[0])
|
||||
print(output_dir)
|
||||
with open(args.class_file, 'r') as file:
|
||||
lines = file.readlines()
|
||||
class_name = [t.strip('\n') for t in lines]
|
||||
|
@@ -69,7 +69,6 @@ def evaluate(detpath,
|
||||
imagenames = [x.strip() for x in lines]
|
||||
|
||||
if os.path.isfile(cachefile):
|
||||
print('cachefile = ', cachefile)
|
||||
with open(cachefile, 'rb') as f:
|
||||
recs = pickel.load(f)
|
||||
else:
|
||||
|
@@ -23,7 +23,7 @@
|
||||
#include "opencv4/opencv2/opencv.hpp"
|
||||
const int color_list[20][3] = { {216, 82, 24}, {236, 176, 31}, {125, 46, 141}, {118, 171, 47}, {76, 189, 237}, {238, 19, 46},
|
||||
{76, 76, 76}, {153, 153, 153}, {255, 0, 0}, {255, 127, 0}, {190, 190, 0}, {0, 255, 0}, {0, 0, 255},
|
||||
{170, 0, 255}, {84, 84, 0}, {84, 170, 0}, {84, 255, 0}, {170, 84, 0}, {170, 170, 0}, {170, 255, 0}}
|
||||
{170, 0, 255}, {84, 84, 0}, {84, 170, 0}, {84, 255, 0}, {170, 84, 0}, {170, 170, 0}, {170, 255, 0}};
|
||||
|
||||
float pad_w = 0.0, pad_h = 0.0;
|
||||
float ratio = 1.0;
|
||||
@@ -207,7 +207,7 @@ void SaveImage(const std::string& result, const cv::Mat src, const std::string&
|
||||
cv::Rect rect(it.x0, it.y0, it.x1 - it.x0, it.y1 - it.y0);
|
||||
cv::rectangle(src, rect, color);
|
||||
char text[256];
|
||||
sprintf(text, "%s %.1f%", it.className.c_str(), it.conf);
|
||||
sprintf(text, "%s %.2f", it.className.c_str(), it.conf);
|
||||
int baseLine = 0;
|
||||
double fontScale = 0.4;
|
||||
cv::Scalar fontColor = cv::Scalar(255, 255, 255);
|
||||
@@ -219,7 +219,6 @@ void SaveImage(const std::string& result, const cv::Mat src, const std::string&
|
||||
}
|
||||
void SaveTxt(const std::string& result, const std::string& line)
|
||||
{
|
||||
// web::json::value jsonText = web::json::value::parse(result);
|
||||
auto res = ParseResult(result);
|
||||
for (auto it : res) {
|
||||
std::ofstream outfile("./txt_result/det_test_" + it.className + ".txt", std::ios::app);
|
||||
@@ -247,6 +246,7 @@ int work(const std::string& id, MxStream::MxStreamManager& mxStreamManager)
|
||||
std::string img_path = imageSetPath+'/'+id+".jpg";
|
||||
MxStream::MxstDataInput dataBuffer;
|
||||
cv::Mat src;
|
||||
int ret;
|
||||
if (task == "eval") {
|
||||
src = cv::imread(img_path);
|
||||
cv::Mat img = letterBox(src);
|
||||
@@ -278,10 +278,6 @@ int work(const std::string& id, MxStream::MxStreamManager& mxStreamManager)
|
||||
dataBuffer.dataPtr = nullptr;
|
||||
return ret;
|
||||
}
|
||||
double time = (double)(clock() - start) / CLOCKS_PER_SEC;
|
||||
time_min = (std::min)(time_min, time);
|
||||
time_max = (std::max)(time_max, time);
|
||||
time_avg += time;
|
||||
std::string result = std::string((char *)output->dataPtr, output->dataSize);
|
||||
if (saveImage == true) { SaveImage(result, src, id); }
|
||||
if (saveTxt == true) { SaveTxt(result, id); }
|
||||
@@ -317,7 +313,12 @@ int run()
|
||||
if (in) {
|
||||
while (getline(in, line)) {
|
||||
loop_num++;
|
||||
auto start = clock();
|
||||
work(line, mxStreamManager);
|
||||
double time = (double)(clock() - start) / CLOCKS_PER_SEC;
|
||||
time_min = (std::min)(time_min, time);
|
||||
time_max = (std::max)(time_max, time);
|
||||
time_avg += time;
|
||||
}
|
||||
time_avg /= loop_num;
|
||||
}
|
||||
|
@@ -14,12 +14,13 @@
|
||||
|
||||
cd ./models/yolov5/
|
||||
atc \
|
||||
--model=prune55_t.onnx \
|
||||
--model=prune60_t.onnx \
|
||||
--framework=5 \
|
||||
--output=./prune55_t \
|
||||
--output=./prune60_t \
|
||||
--input_format=NCHW \
|
||||
--input_shape="images:1,3,512,512" \
|
||||
--enable_small_channel=1 \
|
||||
--insert_op_conf=./aipp_yolov5.cfg \
|
||||
--soc_version=Ascend310 \
|
||||
--out_nodes="Transpose_260:0;Transpose_308:0;Transpose_356:0" \
|
||||
--out_nodes="Transpose_260:0;Transpose_520:0;Transpose_780:0" \
|
||||
cd -
|
Reference in New Issue
Block a user