Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

采用自己的网络模型,计算出的结果与matlab运算出的相差较大 #50

Closed
VivienFu opened this issue Jul 27, 2017 · 7 comments

Comments

@VivienFu
Copy link

如题,您可不可以帮忙指点问题可能出在哪儿?

确认过ncnn每层网络输入输出size,简单看了几个FC的weight值,是正确的。

会不会下面的代码有问题?

int detect_faceIDnet(const cv::Mat& bgr, float *feat)
{
ncnn::Mat in = ncnn::Mat::from_pixels(bgr.data, ncnn::Mat::PIXEL_BGR, bgr.cols, bgr.rows);
in.substract_mean_normalize(mean_vals, 0);

ncnn::Extractor ex = faceIDnet.create_extractor();
ex.set_light_mode(true);
ex.set_num_threads(4);
ex.input("data", in);
ncnn::Mat out;
ex.extract("eltwise_fc1", out);
for (int j = 0; j<FEAT_NUM; j++)
{
	const float* prob = out.data + out.cstep * j;
	feat[j] = prob[0];
	//cout << feat[j] << " ";		
}
//cout << endl;
return 0;

}

@nihui
Copy link
Member

nihui commented Jul 27, 2017

matlab 是 col-major 存储的,如果模型是 matlab 训练的,里头的 weight 要变换下。。

@VivienFu
Copy link
Author

@nihui 答复神速啊,非常感谢!

我的模型不是用matlab训练的,就是caffe.exe跑得训练。后来发现是数据预处理不一致导致的。
太弱了,还没有好好理解ncnn。
处理方式记录在blog中了,http://blog.csdn.net/fuwenyan/article/details/76213015

@nihui
Copy link
Member

nihui commented Jul 27, 2017

const float mean_vals[3] = { 127.5f, 127.5f, 127.5f };
const float norm_vals[3] = { 0.0078125f, 0.0078125f, 0.0078125f };
in.substract_mean_normalize(mean_vals, norm_vals);
这样应该也可以

@VivienFu
Copy link
Author

@nihui 原来如此!!!谢大神!

@Tomhouxin
Copy link

@nihui ,如果mean_vals[3] = {104.f, 112.f, 121.f}呢,对应的norm_vals[3] 是怎么算的

@nihui
Copy link
Member

nihui commented Feb 28, 2020

@nihui ,如果mean_vals[3] = {104.f, 112.f, 121.f}呢,对应的norm_vals[3] 是怎么算的

具体的 mean norm 要参考训练的设置
https://github.com/Tencent/ncnn/wiki/FAQ-ncnn-produce-wrong-result#pre-process

@jolt2017
Copy link

const float mean_vals[3] = { 127.5f, 127.5f, 127.5f };
const float norm_vals[3] = { 0.0078125f, 0.0078125f, 0.0078125f };
in.substract_mean_normalize(mean_vals, norm_vals);
这样应该也可以

您好,这里不是很理解,为啥均值和方差和pytorch 训练模型时使用的不一致???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants