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

有ncnn测试代码吗?我这里测试自己的图片时输出的值的正确率很低,但是在insightFace那里验证时正确率99.5%左右 #8

Open
youyicloud opened this issue May 22, 2018 · 7 comments

Comments

@youyicloud
Copy link

有ncnn测试代码吗?我这里测试自己的图片时输出的值的正确率很低,但是在insightFace那里验证时正确率99.5%左右

@moli232777144
Copy link
Owner

有几个细节你排查下:
1.mtcnn检测,校正点使用的是sphere的五点对齐,112*112的在横坐标需+8;
2.ncnn模型不需要归一化预处理,mxnet直转的模型已包括该步骤;
3.初步测试lfw是否为同一个人的阈值应该在0.3左右;
4.移植全流程肯定会存在一定精度损失,建议直接用裁剪校正后的lfw图像先刷一遍识别率;

@youyicloud
Copy link
Author

@moli232777144 谢谢大佬,没想到你这么认真回复。我目前用的是欧式距离,但是识别出来通一个人的都有2点几到3点几,你用的是什么距离呢?我没有做归一化处理,用的是insightface训练的模型,我下载了lfw数据后,用insightface里的align成112*112了,然后用insightface里的eval目录下的代码加载mobilefacenet测试了align后的正确率都有99.5%,然后移植到ncnn后,输出的值就完全不对。

@youyicloud
Copy link
Author

@moli232777144 你计算的是什么距离呢?输出节点是fc1吧?

@moli232777144
Copy link
Owner

余弦距离,输出fc1

@youyicloud
Copy link
Author

好的,谢啦,我再试试

@youyicloud
Copy link
Author

youyicloud commented May 24, 2018

我用mxnet计算了一下fc1输出的值的余弦距离,结果还是不对.模型用的是从insightface下载的模型(地址),然后图片用的是完全不同的男女两个人,已经用mtcnn对齐了的lfw里的图片.

`#coding=utf-8
import mxnet as mx
import numpy as np
import math
import cv2
from collections import namedtuple
from sklearn import preprocessing
Batch= namedtuple('Batch', ['data'])

image_size = (112,112)
batch_size = 2

def load_model(model_prefix):
sym, arg_params, aux_params = mx.model.load_checkpoint(model_prefix, 0)
all_layers = sym.get_internals()
sym = all_layers['fc1_output']
model = mx.mod.Module(symbol=sym, label_names = None)
model.bind(data_shapes=[('data', (2, 3, image_size[0], image_size[1]))])
model.set_params(arg_params, aux_params)
return model

def dis(x,y):
return np.dot(x, y)/np.linalg.norm(x)/np.linalg.norm(y)

def test(model_prefix):
img_path_1 = "./img_test/41.jpg"
img_path_2 = "./img_test/31.jpg"
model = load_model(model_prefix)
img1 = cv2.cvtColor(cv2.imread(img_path_1), cv2.COLOR_BGR2RGB)
img1 = cv2.resize(img1, (112, 112), interpolation=cv2.INTER_CUBIC)
img2 = cv2.cvtColor(cv2.imread(img_path_2), cv2.COLOR_BGR2RGB)
img2 = cv2.resize(img2, (112, 112), interpolation=cv2.INTER_CUBIC)
img1 = np.transpose(img1, axes=(2, 0, 1))
img2 = np.transpose(img2, axes=(2, 0, 1))
data_batch = []
data_batch.append(img1)
data_batch.append(img2)
data_batch = np.array(data_batch)
print(data_batch.shape)
print(img2.shape)
model.forward(Batch([mx.nd.array(data_batch)]))
prob = model.get_outputs()[0].asnumpy()
print(dis(prob[0],prob[1]))

model_prefix = "../../models/model"
test(model_prefix)`

上面是代码,下面是输出,

[00:19:53] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v1.0.0. Attempting to upgra de... [00:19:53] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded! (2, 3, 112, 112) (3, 112, 112) -0.9996472
您能帮我看看问题出哪里吗?麻烦啦~ @moli232777144

@w840401
Copy link

w840401 commented Feb 23, 2021

我用mxnet计算了一下fc1输出的值的余弦距离,结果还是不对.模型用的是从insightface下载的模型(地址),然后图片用的是完全不同的男女两个人,已经用mtcnn对齐了的lfw里的图片.

`#coding=utf-8
import mxnet as mx
import numpy as np
import math
import cv2
from collections import namedtuple
from sklearn import preprocessing
Batch= namedtuple('Batch', ['data'])

image_size = (112,112)
batch_size = 2

def load_model(model_prefix):
sym, arg_params, aux_params = mx.model.load_checkpoint(model_prefix, 0)
all_layers = sym.get_internals()
sym = all_layers['fc1_output']
model = mx.mod.Module(symbol=sym, label_names = None)
model.bind(data_shapes=[('data', (2, 3, image_size[0], image_size[1]))])
model.set_params(arg_params, aux_params)
return model

def dis(x,y):
return np.dot(x, y)/np.linalg.norm(x)/np.linalg.norm(y)

def test(model_prefix):
img_path_1 = "./img_test/41.jpg"
img_path_2 = "./img_test/31.jpg"
model = load_model(model_prefix)
img1 = cv2.cvtColor(cv2.imread(img_path_1), cv2.COLOR_BGR2RGB)
img1 = cv2.resize(img1, (112, 112), interpolation=cv2.INTER_CUBIC)
img2 = cv2.cvtColor(cv2.imread(img_path_2), cv2.COLOR_BGR2RGB)
img2 = cv2.resize(img2, (112, 112), interpolation=cv2.INTER_CUBIC)
img1 = np.transpose(img1, axes=(2, 0, 1))
img2 = np.transpose(img2, axes=(2, 0, 1))
data_batch = []
data_batch.append(img1)
data_batch.append(img2)
data_batch = np.array(data_batch)
print(data_batch.shape)
print(img2.shape)
model.forward(Batch([mx.nd.array(data_batch)]))
prob = model.get_outputs()[0].asnumpy()
print(dis(prob[0],prob[1]))

model_prefix = "../../models/model"
test(model_prefix)`

上面是代码,下面是输出,

[00:19:53] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v1.0.0. Attempting to upgra de... [00:19:53] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded! (2, 3, 112, 112) (3, 112, 112) -0.9996472
您能帮我看看问题出哪里吗?麻烦啦~ @moli232777144

請問有成功測試出來了嗎
可以分享嗎?
感激不盡

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

3 participants