Skip to content

Commit

Permalink
更新faq文档 (#2831)
Browse files Browse the repository at this point in the history
* update faq.md about ncnn-produce-wrong-result

* update faq.md  about print Mat content and visualize Mat content

* update faq.md about efficient roi resize rotate

* update faq.md about convert to fp16

* update faq.md about use ncnn with pytorch or onnx

* update faq.md about add the url of netron

* update faq.md about add the url of convertmodel

Co-authored-by: runrunrun1994 <runrunrun1994@163.com>
  • Loading branch information
runrunrun1994 and runrunrun1994 committed Apr 11, 2021
1 parent 81f051e commit 895ae1f
Showing 1 changed file with 90 additions and 1 deletion.
91 changes: 90 additions & 1 deletion docs/faq.md
Expand Up @@ -96,6 +96,8 @@ opencv rtti -> opencv-mobile

## pytorch - onnx

[use ncnn with pytorch or onnx](https://github.com/Tencent/ncnn/wiki/use-ncnn-with-pytorch-or-onnx)

## tensorflow 1.x/2.x - keras

## tensorflow 2.x - mlir
Expand All @@ -106,8 +108,12 @@ onnx-simplifier 静态shape

## convertmodel

[https://convertmodel.com/](https://convertmodel.com/) **[@大老师](https://github.com/daquexian)**

## netron

[https://github.com/lutzroeder/netron](https://github.com/lutzroeder/netron)

## 怎么生成有固定 shape 信息的模型?

Input 0=w 1=h 2=c
Expand All @@ -116,6 +122,8 @@ why gpu能更快

## ncnnoptimize 怎么转成 fp16 模型

`ncnnoptimize model.param model.bin yolov5s-opt.param yolov5s-opt.bin 65536`

## ncnnoptimize 怎样查看模型的 FLOPS / 内存占用情况

## 怎么修改模型支持动态 shape?
Expand Down Expand Up @@ -216,6 +224,8 @@ https://github.com/Tencent/ncnn/wiki/use-ncnn-with-pytorch-or-onnx

## 如何 resize crop rotate 图片

[efficient roi resize rotate](https://github.com/Tencent/ncnn/wiki/efficient-roi-resize-rotate)

## 如何人脸5点对齐

get_affine_transform
Expand Down Expand Up @@ -301,13 +311,92 @@ for msvc++:
for g++:

setenv("OMP_WAIT_POLICY", "passive", 1)

reference: https://stackoverflow.com/questions/34439956/vc-crash-when-freeing-a-dll-built-with-openmp

# 跑出来的结果对不上

[ncnn-produce-wrong-result](https://github.com/Tencent/ncnn/wiki/FAQ-ncnn-produce-wrong-result)

## 如何打印 ncnn::Mat 的值?

```C++
void pretty_print(const ncnn::Mat& m)
{
for (int q=0; q<m.c; q++)
{
const float* ptr = m.channel(q);
for (int y=0; y<m.h; y++)
{
for (int x=0; x<m.w; x++)
{
printf("%f ", ptr[x]);
}
ptr += m.w;
printf("\n");
}
printf("------------------------\n");
}
}
```
## 如何可视化 ncnn::Mat 的值?
```
void visualize(const char* title, const ncnn::Mat& m)
{
std::vector<cv::Mat> normed_feats(m.c);

for (int i=0; i<m.c; i++)
{
cv::Mat tmp(m.h, m.w, CV_32FC1, (void*)(const float*)m.channel(i));

cv::normalize(tmp, normed_feats[i], 0, 255, cv::NORM_MINMAX, CV_8U);

cv::cvtColor(normed_feats[i], normed_feats[i], cv::COLOR_GRAY2BGR);

// check NaN
for (int y=0; y<m.h; y++)
{
const float* tp = tmp.ptr<float>(y);
uchar* sp = normed_feats[i].ptr<uchar>(y);
for (int x=0; x<m.w; x++)
{
float v = tp[x];
if (v != v)
{
sp[0] = 0;
sp[1] = 0;
sp[2] = 255;
}

sp += 3;
}
}
}

int tw = m.w < 10 ? 32 : m.w < 20 ? 16 : m.w < 40 ? 8 : m.w < 80 ? 4 : m.w < 160 ? 2 : 1;
int th = (m.c - 1) / tw + 1;

cv::Mat show_map(m.h * th, m.w * tw, CV_8UC3);
show_map = cv::Scalar(127);

// tile
for (int i=0; i<m.c; i++)
{
int ty = i / tw;
int tx = i % tw;

normed_feats[i].copyTo(show_map(cv::Rect(tx * m.w, ty * m.h, m.w, m.h)));
}

cv::resize(show_map, show_map, cv::Size(0,0), 2, 2, cv::INTER_NEAREST);
cv::imshow(title, show_map);
}
```
## 总是输出第一张图的结果
复用 Extractor?!
Expand Down

0 comments on commit 895ae1f

Please sign in to comment.