加盟编程教育哪家好,多合一可拖曳修改优化网站建设,用旧电脑做网站,百青藤广告联盟前言
想做一个目标旋转角度检测的工程#xff0c;但是网上多少python的#xff0c;或者linux的。在win10 visual 2022移植部署#xff0c;记录一下。 参考 这篇文章没有C win10 环境下的部署教程#xff0c;我相对于是对此做了补充。
1、下载工程
https://github.com/sh…前言
想做一个目标旋转角度检测的工程但是网上多少python的或者linux的。在win10 visual 2022移植部署记录一下。 参考 这篇文章没有C win10 环境下的部署教程我相对于是对此做了补充。
1、下载工程
https://github.com/shouxieai/tensorRT_Pro
2 模型导出
在 ultralytics/engine/exporter.py 文件中改动一处
# output_names [output0, output1] if isinstance(self.model, SegmentationModel) else [output0]
# dynamic self.args.dynamic
# if dynamic:
# dynamic {images: {0: batch, 2: height, 3: width}} # shape(1,3,640,640)
# if isinstance(self.model, SegmentationModel):
# dynamic[output0] {0: batch, 2: anchors} # shape(1, 116, 8400)
# dynamic[output1] {0: batch, 2: mask_height, 3: mask_width} # shape(1,32,160,160)
# elif isinstance(self.model, DetectionModel):
# dynamic[output0] {0: batch, 2: anchors} # shape(1, 84, 8400)
# exporter.py
output_names [output0, output1] if isinstance(self.model, SegmentationModel) else [output]
dynamic self.args.dynamic
if dynamic:dynamic {images: {0: batch}} # shape(1,3,640,640)if isinstance(self.model, SegmentationModel):dynamic[output0] {0: batch, 2: anchors} # shape(1, 116, 8400)dynamic[output1] {0: batch, 2: mask_height, 3: mask_width} # shape(1,32,160,160)elif isinstance(self.model, DetectionModel):dynamic[output] {0: batch} # shape(1, 84, 8400)在 ultralytics/nn/modules/head.py 文件中改动一处
def forward(self, x):Concatenates and returns predicted bounding boxes and class probabilities.bs x[0].shape[0] # batch sizeangle torch.cat([self.cv4[i](x[i]).view(bs, self.ne, -1) for i in range(self.nl)], 2) # OBB theta logits# NOTE: set angle as an attribute so that decode_bboxes could use it.angle (angle.sigmoid() - 0.25) * math.pi # [-pi/4, 3pi/4]# angle angle.sigmoid() * math.pi / 2 # [0, pi/2]if not self.training:self.angle anglex Detect.forward(self, x)if self.training:return x, angle#return torch.cat([x, angle], 1) if self.export else (torch.cat([x[0], angle], 1), (x[1], angle))return torch.cat([x, angle], 1).permute(0, 2, 1) if self.export else (torch.cat([x[0], angle], 1), (x[1], angle))在终端执行如下指令即可完成 onnx 导出
from ultralytics import YOLOmodel YOLO(yolov8_obb_zwc_0918.pt)success model.export(formatonnx, dynamicTrue, simplifyTrue)3 C
修改一个简单的测试测序在原工程app_yolo_obb.cpp 的基础上修改如下
#include trt_builder.hpp
#include trt_infer.hpp
#include ilogger.hpp
#include yolo_obb.hpp
static const char* dotalabels[] {0topleft, 1topright, 2downleft, 3downright, 4top,5right, 6down, 7left, bridge, large vehicle,small vehicle, helicopter, roundabout, soccer ball field, swimming pool
};
using namespace std;
static vectorcv::Point xywhr2xyxyxyxy(const YoloOBB::Box box) {float cos_value std::cos(box.angle);float sin_value std::sin(box.angle);float w_2 box.width / 2, h_2 box.height / 2;float vec1_x w_2 * cos_value, vec1_y w_2 * sin_value;float vec2_x -h_2 * sin_value, vec2_y h_2 * cos_value;vectorcv::Point corners;corners.push_back(cv::Point(box.center_x vec1_x vec2_x, box.center_y vec1_y vec2_y));corners.push_back(cv::Point(box.center_x vec1_x - vec2_x, box.center_y vec1_y - vec2_y));corners.push_back(cv::Point(box.center_x - vec1_x - vec2_x, box.center_y - vec1_y - vec2_y));corners.push_back(cv::Point(box.center_x - vec1_x vec2_x, box.center_y - vec1_y vec2_y));return corners;
}
static void test_single_image() {// //----initialauto engine YoloOBB::create_infer(E:***.trt, // engine file0, // gpu id0.25f, // confidence threshold0.45f, // nms thresholdYoloOBB::NMSMethod::FastGPU, // NMS method, fast GPU / CPU1024, // max objectsfalse // preprocess use multi stream);if (engine nullptr) {INFOE(Engine is nullptr);return;}//auto files iLogger::find_files(IMG, *.jpg;*.jpeg;*.png;*.gif;*.tif);vectorcv::Mat images;for (int i 0; i files.size(); i) {auto image cv::imread(files[i]);images.emplace_back(image);}//for (auto img : images)//{// cv::imshow(src, img);// cv::waitKey(0);//}for(auto img:images){cv::Mat imageimg ;if (image.empty()) {INFOE(Image is empty);return;}auto boxes engine-commit(image).get();for (auto obj : boxes) {uint8_t b, g, r;tie(b, g, r) iLogger::random_color(obj.class_label);auto corners xywhr2xyxyxyxy(obj);cv::polylines(image, vectorvectorcv::Point{corners}, true, cv::Scalar(b, g, r), 2, 16);auto name dotalabels[obj.class_label];auto caption iLogger::format(%s %.2f, name, obj.confidence);int width cv::getTextSize(caption, 0, 1, 2, nullptr).width 10;cv::rectangle(image, cv::Point(corners[0].x - 3, corners[0].y - 33), cv::Point(corners[0].x - 3 width, corners[0].y), cv::Scalar(b, g, r), -1);cv::putText(image, caption, cv::Point(corners[0].x - 3, corners[0].y - 5), 0, 1, cv::Scalar::all(0), 2, 16);}INFO(Save to Result.jpg, %d objects, boxes.size());cv::imwrite(Result.jpg, image);cv::imshow(result, image);cv::waitKey(0);}engine.reset();
}
int main() {test_single_image();return 0;
}3.1 工程下IMG 文件夹结构(你要测试的图片集合) 3.2 所需要的CPP 3.3 编译 添加头文件 3.3 .cu的文件需要设置CUDA C/C 编译类型 4 结果 5 PS
Cuda 、cudnn 、OpenCV,的配置可以自行百度or参考我的往期文章https://blog.csdn.net/qq_36784503/article/details/138597169 文章转载自: http://www.morning.xrpjr.cn.gov.cn.xrpjr.cn http://www.morning.rqbr.cn.gov.cn.rqbr.cn http://www.morning.paoers.com.gov.cn.paoers.com http://www.morning.tcxk.cn.gov.cn.tcxk.cn http://www.morning.rkbly.cn.gov.cn.rkbly.cn http://www.morning.xxknq.cn.gov.cn.xxknq.cn http://www.morning.yrqb.cn.gov.cn.yrqb.cn http://www.morning.nlbhj.cn.gov.cn.nlbhj.cn http://www.morning.plkrl.cn.gov.cn.plkrl.cn http://www.morning.grtwn.cn.gov.cn.grtwn.cn http://www.morning.mtbth.cn.gov.cn.mtbth.cn http://www.morning.jkmjm.cn.gov.cn.jkmjm.cn http://www.morning.xfncq.cn.gov.cn.xfncq.cn http://www.morning.c7623.cn.gov.cn.c7623.cn http://www.morning.dktyc.cn.gov.cn.dktyc.cn http://www.morning.wjpsn.cn.gov.cn.wjpsn.cn http://www.morning.cknws.cn.gov.cn.cknws.cn http://www.morning.jlmrx.cn.gov.cn.jlmrx.cn http://www.morning.yrdn.cn.gov.cn.yrdn.cn http://www.morning.hwlmy.cn.gov.cn.hwlmy.cn http://www.morning.qgwpx.cn.gov.cn.qgwpx.cn http://www.morning.dnconr.cn.gov.cn.dnconr.cn http://www.morning.yesidu.com.gov.cn.yesidu.com http://www.morning.kbgzj.cn.gov.cn.kbgzj.cn http://www.morning.sqnrz.cn.gov.cn.sqnrz.cn http://www.morning.jrqw.cn.gov.cn.jrqw.cn http://www.morning.khtyz.cn.gov.cn.khtyz.cn http://www.morning.hkcjx.cn.gov.cn.hkcjx.cn http://www.morning.rwyw.cn.gov.cn.rwyw.cn http://www.morning.wtcd.cn.gov.cn.wtcd.cn http://www.morning.dcmnl.cn.gov.cn.dcmnl.cn http://www.morning.gyfhk.cn.gov.cn.gyfhk.cn http://www.morning.nytqy.cn.gov.cn.nytqy.cn http://www.morning.fsqbx.cn.gov.cn.fsqbx.cn http://www.morning.ctqlq.cn.gov.cn.ctqlq.cn http://www.morning.ymyhg.cn.gov.cn.ymyhg.cn http://www.morning.rhmt.cn.gov.cn.rhmt.cn http://www.morning.gbgdm.cn.gov.cn.gbgdm.cn http://www.morning.xbrxk.cn.gov.cn.xbrxk.cn http://www.morning.lzqdd.cn.gov.cn.lzqdd.cn http://www.morning.yfnjk.cn.gov.cn.yfnjk.cn http://www.morning.hxycm.cn.gov.cn.hxycm.cn http://www.morning.xtkw.cn.gov.cn.xtkw.cn http://www.morning.thlzt.cn.gov.cn.thlzt.cn http://www.morning.uytae.cn.gov.cn.uytae.cn http://www.morning.gxfzrb.com.gov.cn.gxfzrb.com http://www.morning.cjsrg.cn.gov.cn.cjsrg.cn http://www.morning.snnwx.cn.gov.cn.snnwx.cn http://www.morning.yxwcj.cn.gov.cn.yxwcj.cn http://www.morning.srnth.cn.gov.cn.srnth.cn http://www.morning.qmtzq.cn.gov.cn.qmtzq.cn http://www.morning.ttdbr.cn.gov.cn.ttdbr.cn http://www.morning.txtzr.cn.gov.cn.txtzr.cn http://www.morning.hdpcn.cn.gov.cn.hdpcn.cn http://www.morning.xxiobql.cn.gov.cn.xxiobql.cn http://www.morning.ghqyr.cn.gov.cn.ghqyr.cn http://www.morning.hphqy.cn.gov.cn.hphqy.cn http://www.morning.nslwj.cn.gov.cn.nslwj.cn http://www.morning.gpnfg.cn.gov.cn.gpnfg.cn http://www.morning.njdtq.cn.gov.cn.njdtq.cn http://www.morning.fyzsq.cn.gov.cn.fyzsq.cn http://www.morning.ntwxt.cn.gov.cn.ntwxt.cn http://www.morning.nkyc.cn.gov.cn.nkyc.cn http://www.morning.ygkk.cn.gov.cn.ygkk.cn http://www.morning.ghqyr.cn.gov.cn.ghqyr.cn http://www.morning.fhqdb.cn.gov.cn.fhqdb.cn http://www.morning.gmgnp.cn.gov.cn.gmgnp.cn http://www.morning.wgbmj.cn.gov.cn.wgbmj.cn http://www.morning.skcmt.cn.gov.cn.skcmt.cn http://www.morning.bklhx.cn.gov.cn.bklhx.cn http://www.morning.pjrgb.cn.gov.cn.pjrgb.cn http://www.morning.shangwenchao4.cn.gov.cn.shangwenchao4.cn http://www.morning.hqrkq.cn.gov.cn.hqrkq.cn http://www.morning.ybgyz.cn.gov.cn.ybgyz.cn http://www.morning.rbffj.cn.gov.cn.rbffj.cn http://www.morning.bwttj.cn.gov.cn.bwttj.cn http://www.morning.rwzc.cn.gov.cn.rwzc.cn http://www.morning.yhdqq.cn.gov.cn.yhdqq.cn http://www.morning.bqwrn.cn.gov.cn.bqwrn.cn http://www.morning.qgghr.cn.gov.cn.qgghr.cn