Comments (9)
netOutputImg[1]是mask的特征矩阵,需要和第一个输出中长度为32的特征掩码进行矩阵乘法之后得到1x160x160大小的mask图像,然后缩放两次(第一次是640x640(也就是mask比推理图像缩小了mask-ratio,默认为4),第二次从640x640开始)回到原图大小,至于你说的一维数组,我没搞懂你在说哪个是一维数组。
all() 就是第二个维度的32个通道数据全部要啊。其他通道根据你原来的检测框缩放到特征图上面的大小,将矩形区域切割出来。然后用小特征图与特征掩码进行计算减少计算量。
至于你说的报错的话,检查一下看看roi_rangs的第3和第4维度是不是超过160了,或者某个值为0了。那你详细看下注释的部分,我写了代码啊,你用这个运行看下
https://github.com/UNeedCryDear/yolov5-seg-opencv-dnn-cpp/blob/5b3629a4818ce4f88f440ce9999f633d59c8bd41/yolo_seg.cpp#L223
from yolov5-seg-opencv-onnxruntime-cpp.
netOutputImg[1]是mask的特征矩阵,需要和第一个输出中长度为32的特征掩码进行矩阵乘法之后得到1x160x160大小的mask图像,然后缩放两次(第一次是640x640(也就是mask比推理图像缩小了mask-ratio,默认为4),第二次从640x640开始)回到原图大小,至于你说的一维数组,我没搞懂你在说哪个是一维数组。 all() 就是第二个维度的32个通道数据全部要啊。其他通道根据你原来的检测框缩放到特征图上面的大小,将矩形区域切割出来。然后用小特征图与特征掩码进行计算减少计算量。
至于你说的报错的话,检查一下看看roi_rangs的第3和第4维度是不是超过160了,或者某个值为0了。那你详细看下注释的部分,我写了代码啊,你用这个运行看下
嗯。按照你说的偶尔会报错,按如下修改后,不报错了:
int rang_x = floor((temp_rect.x * params[0] + params[2]) / _netWidth * mask_rows);
int rang_y = floor((temp_rect.y * params[1] + params[3]) / _netHeight * mask_cols);
int rang_w = ceil(((temp_rect.x + temp_rect.width) * params[0] + params[2]) / _netWidth * mask_rows) - rang_x;
int rang_h = ceil(((temp_rect.y + temp_rect.height) * params[1] + params[3]) / _netHeight * mask_cols) - rang_y;
//rang_w = MAX(rang_w, 1);
//rang_h = MAX(rang_h, 1);
if ((rang_x + rang_w) > mask_rows) {
if (mask_rows - rang_x > 0)
rang_w = mask_rows - rang_x;
else
rang_x -= 1;
}
if ((rang_y + rang_h) > mask_cols) {
if (mask_cols - rang_y > 0)
rang_h = mask_cols - rang_y;
else
rang_y -= 1;
}
rang_x = MAX(rang_x, 0);
rang_y = MAX(rang_y, 0);
rang_w = MIN(MAX(rang_w, 1), mask_rows);
rang_h = MIN(MAX(rang_h, 1), mask_cols);
int roi_w = MIN(rang_w + rang_x, mask_rows);
int roi_h = MIN(rang_h + rang_y, mask_cols);
vector<cv::Range> roi_rangs;
roi_rangs.push_back(cv::Range(0, 1));
roi_rangs.push_back(cv::Range::all());
roi_rangs.push_back(cv::Range(rang_y, roi_h));
roi_rangs.push_back(cv::Range(rang_x, roi_w));
//crop
cv::Mat temp_mask_protos = maskmat(roi_rangs).clone();
cv::Mat protos = temp_mask_protos.reshape(0, { mask_channel,rang_w * rang_h });
cv::Mat matmulRes = (mask_proposals * protos).t();
cv::Mat masks_feature = matmulRes.reshape(1, { rang_h,rang_w });
cv::Mat dest, mask;
from yolov5-seg-opencv-onnxruntime-cpp.
新版的还是有点问题,
int rang_x = floor((temp_rect.x * params[0] + params[2]) / _netWidth * mask_rows);
int rang_y = floor((temp_rect.y * params[1] + params[3]) / _netHeight * mask_cols);
int rang_w = ceil(((temp_rect.x + temp_rect.width) * params[0] + params[2]) / _netWidth * mask_rows) - rang_x;
int rang_h = ceil(((temp_rect.y + temp_rect.height) * params[1] + params[3]) / _netHeight * mask_cols) - rang_y;
这几个参数,很容易崩溃,并且出来的分割图像,会有竖道道:
from yolov5-seg-opencv-onnxruntime-cpp.
你的row是宽度?cols是高度?
除非mask的长宽一致吗?不然你这里就错了。
另外,你这个条纹状我没有出现,你试试看下yolo-seg的原始模型有无这种情况,或者使用旧版本的GetMask看下有无问题。旧版本还这样的话就是你模型本身就有问题,或者你提供模型和图片我看下
from yolov5-seg-opencv-onnxruntime-cpp.
新版的还是有点问题, int rang_x = floor((temp_rect.x * params[0] + params[2]) / _netWidth * mask_rows); int rang_y = floor((temp_rect.y * params[1] + params[3]) / _netHeight * mask_cols); int rang_w = ceil(((temp_rect.x + temp_rect.width) * params[0] + params[2]) / _netWidth * mask_rows) - rang_x; int rang_h = ceil(((temp_rect.y + temp_rect.height) * params[1] + params[3]) / _netHeight * mask_cols) - rang_y; 这几个参数,很容易崩溃,并且出来的分割图像,会有竖道道:
这几个参数是计算最终检测框在mask图片上面的mask区域,由于需要抠图,所以需要保证其矩形区域的合法性就行,比如不能超过mask的长宽,矩形长宽不能为0,满足这些条件才能抠图
from yolov5-seg-opencv-onnxruntime-cpp.
你的row是宽度?cols是高度? 除非mask的长宽一致吗?不然你这里就错了。 另外,你这个条纹状我没有出现,你试试看下yolo-seg的原始模型有无这种情况,或者使用旧版本的GetMask看下有无问题。旧版本还这样的话就是你模型本身就有问题,或者你提供模型和图片我看下
旧版的没有问题,新版的有问题,row是宽度,cols是高度,是读取的模型输出尺寸1x32x160x160里面的,都是160
from yolov5-seg-opencv-onnxruntime-cpp.
请问这个32的特征掩码该怎么理解呢? 有没有对应的分割网络可以帮助理解?
from yolov5-seg-opencv-onnxruntime-cpp.
请问这个32的特征掩码该怎么理解呢? 有没有对应的分割网络可以帮助理解?
YOLACT里面有提到,论文你可以自己搜索下
from yolov5-seg-opencv-onnxruntime-cpp.
旧版的没有问题,新版的有问题,row是宽度,cols是高度,是读取的模型输出尺寸1x32x160x160里面的,都是160
opencv里面,img.rows是行数,也就是图像y方向的高度,img.cols是x方向的宽度,你这点不要搞混掉了,如果原始的没问题,你看下是不是这点的问题导致你的原始图像长宽反了出现条状。我也不知道你修改了哪些东西,无法复现你的问题。如果旧版本的没问题,那你换旧版本的吧。
from yolov5-seg-opencv-onnxruntime-cpp.
Related Issues (20)
- 错误字符串 HOT 4
- 请问onnxruntime安装是GPU版本的吗?【目前,我使用onnxruntime-cpu 1.12.0可以解决问题了】 HOT 9
- BUG HOT 3
- 预训练模型加载正常,但自训练模型报错 HOT 2
- 怎么使用? HOT 8
- 请问这种情况是哪地方错误了? HOT 5
- 为什么运行不出现结果 HOT 1
- 为什么c++推理时间比python中的推理时间更长? HOT 12
- onnxruntime推理出错 HOT 3
- 引发了异常: 读取访问权限冲突。 **Ort::GetApi**(...) 返回 nullptr。 HOT 2
- 移植问题 HOT 8
- 如何在ubuntu下运行? HOT 2
- undefined reference to `OrtSessionOptionsAppendExecutionProvider_CUDA' HOT 1
- Detect failed! HOT 1
- 运行时间 HOT 1
- mask =mask(temp_rect -Point(left, top)) > mask_threshold;请问这句话是什么意思?我总是在这里报错 HOT 8
- GPU推理内存占用过大 HOT 3
- c++推理结果与python推理结果不一致问题 HOT 16
- 代码崩溃: HOT 18
- Does this software work in a Ubuntu 18.04 machine without GPU? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yolov5-seg-opencv-onnxruntime-cpp.