当前位置: 首页 > news >正文

收录查询站长工具做放单主持的网站

收录查询站长工具,做放单主持的网站,晋城网站建设费用,wordpress 查看访客Yolov8部署——segmentation部署以及批量推理 参考:在windows上部署Yolov8主要参考下面两个仓库,https://github.com/xunzixunzi/tensorrt-cpp-api和https://github.com/xunzixunzi/YOLOv8-TensorRT-CPP,代码说是适合批量处理,但是代码中是以…

Yolov8部署——segmentation部署以及批量推理

参考:在windows上部署Yolov8主要参考下面两个仓库,https://github.com/xunzixunzi/tensorrt-cpp-api和https://github.com/xunzixunzi/YOLOv8-TensorRT-CPP,代码说是适合批量处理,但是代码中是以batchsize=1为例,所以需要修改一下。
具体修改:我需要的batchsize=6,是要将一张大图,切分成小图,之后以batchsize=6进行推理,主要修改bool YoloV8::infer(const cv::cuda::GpuMat& inputImage, std::vector<InferenceObject>& inferenceObjects)void YoloV8::preprocess(const cv::cuda::GpuMat& gpuImg, std::vector<std::vector<cv::cuda::GpuMat>>& inputs)这个函数,我是把这两个函数合起来进行批量推断修改如下:

// 处理输入图片std::vector<std::vector<cv::cuda::GpuMat>> inputs;   //二维向量const auto& inputDims = m_trtEngine->getInputDims();int imgWidth = gpuImage.cols;int imgHeight = gpuImage.rows;int numCols = imgWidth / blockWidth;int numRows = imgHeight / blockHeight;const int totalBlocks = numCols * numRows;//总的张数int blockCounter = 0;//分割并存储每个图像块到 input 向量中std::vector<cv::cuda::GpuMat> input;for (int y = 0; y < numRows; ++y) {for (int x = 0; x < numCols; ++x) {cv::Rect roi(x * blockWidth, y * blockHeight, blockWidth, blockHeight);cv::cuda::GpuMat block(gpuImage(roi));cv::cuda::GpuMat rgbMat;cv::cuda::cvtColor(block, rgbMat, cv::COLOR_BGR2RGB);if (rgbMat.rows != inputDims[0].d[1] || rgbMat.cols != inputDims[0].d[2]) {throw std::runtime_error("Error:图片尺寸不对.");}else {input.emplace_back(rgbMat);}blockCounter++;if (input.size() == 6 || (input.size() != 6 && blockCounter == totalBlocks)) {while (input.size() < 6) {// 如果不足六张图像,则用全黑的图像补全cv::cuda::GpuMat blackImage(blockHeight, blockWidth, CV_8UC3, cv::Scalar(0, 0, 0));input.emplace_back(blackImage);}inputs.emplace_back(std::move(input));std::vector<std::vector<std::vector<float>>> featureVector;auto succ = m_trtEngine->runInference(inputs, featureVector);if (!succ) {throw std::runtime_error("Error: Unable to run inference.");}input.clear();inputs.clear();featureVectors.insert(featureVectors.end(), std::make_move_iterator(featureVector.begin()), std::make_move_iterator(featureVector.end()));}}}

之后模型后处理拼接推断结果:

// 后处理阶段需要用m_imgHeight = static_cast<float>(blockWidth);m_imgWidth = static_cast<float>(blockHeight);m_ratio = 1.f / std::min(inputDims[0].d[2] / static_cast<float>(blockWidth), inputDims[0].d[1] / static_cast<float>(blockHeight));int numColsl = gpuImage.cols / blockWidth;int numRowsl = gpuImage.rows / blockHeight;cv::Mat fullMask = cv::Mat::zeros(gpuImage.size(), CV_8UC1);int cnt = 0;for (int i = 0; i < numRowsl; ++i) {for (int j = 0; j < numColsl; ++j) {std::vector<std::vector<float>> batch;batch = featureVectors[cnt];postprocessSegmentation(batch, inferenceObjects);if (!inferenceObjects.empty()) {for (int k = 0; k < inferenceObjects.size(); ++k) {auto& object = inferenceObjects[k];std::vector<int> objectInfo;objectInfo.push_back(object.label); // 假设id是int类型objectInfo.push_back(object.rect.x + j * 640); // x值objectInfo.push_back(object.rect.y + i * 640); // y值objectInfo.push_back(object.rect.width); // 宽度wobjectInfo.push_back(object.rect.height); // 高度h// 将objectInfo添加到Result向量中Result.push_back(objectInfo);if (!object.boxMask.empty()) {// 对对象的rect位置进行操作object.rect.x += j * 640;object.rect.y += i * 640;// 在fullMask上根据修改后的对象的rect位置放置掩码cv::Mat roi = fullMask(object.rect);cv::Mat resizedMask;cv::resize(object.boxMask, resizedMask, object.rect.size());resizedMask.copyTo(roi, resizedMask);}fullMask.copyTo(BinMat);}}cnt += 1;inferenceObjects.clear();}}

最后得到Result(里面存储分割并分类的标签、x、y、height和width)和一个分割的掩码二值化图。

http://www.yayakq.cn/news/158669/

相关文章:

  • 电子商务网站开发项目策划书公司网站怎么做关键字
  • 杭州网站建设公司导航百度推广官方网站登录入口
  • wordpress做的著名网站电视台网站策划书
  • 专做PPP项目网站做网站必须在工信部备案吗
  • 心理咨询网站建设论文学计算机工资一月多少
  • 手机端的网站怎么做上海网站建设公司官网
  • 天津建网站阿里巴巴网站icp编号怎么查
  • 免费h5页面制作平台有哪些优化大师专业版
  • 东营机关建设网站wordpress微博功能
  • 网站建设手机字体大小怎样建立自己的网站
  • 哪个网站建设搜索引擎优化seo包括
  • 枣阳建设局网站快速建站官网
  • 成都网站建设公司服务wordpress大
  • 哪些网站是用vue做的文化传媒网站封面
  • 海口建设网站的公司哪家好雄安微网站开发
  • 安平县外贸网站建设泉州做企业网站
  • 重庆建设网站哪家专业全屋定制网
  • 如何做一份企业网站网站建设过时了吗
  • 市网站建设空白word个人简历
  • 昌平网站建设公司做网站需要做需求分析吗
  • 陕西住房和城乡建设部网站首页哪里学网站建设推广
  • 淘宝网站开发类目没法上架商品新手学做网站12天婴
  • 网站建设相关资料文件全球速卖通大学
  • 灌云网站设计专业网站制作哪便宜
  • 免费机械网站模板国内上市的网络公司排名
  • 菠菜源码怎么做网站常德做网站专业公司
  • 乐清网站制作电话网站关键词布局图
  • 微信的网站怎么做哪里有平面设计
  • 台州网站设计建设省级网站建设标准
  • 韩城市住房和城乡建设局网站wordpress如何访问后台页面