Hi,
How we can test pretrained models on CPU ?
it gaves:
RuntimeError: simple_bind error. Arguments:
data: (1, 3L, 68L, 68L)
[23:39:56] src/storage/storage.cc:118: Compile with USE_CUDA=1 to enable GPU usage
这个需要GPU支持
You can manually set Mxnet to use CPU. In face_model.py line 46, set ctx = mx.cpu(0) instead of the argument that passed.
Thanks I missed that.
now it gaves below error:
Traceback (most recent call last):
File "test.py", line 23, in
gender, age = model.get_ga(img)
File "face_model.py", line 104, in get_ga
self.ga_model.forward(db, is_train=False)
AttributeError: 'NoneType' object has no attribute 'forward'
Gender and age model haven't been release yet.
@Wisgon ,你有训练好的模型嘛
No, I don't have.
I just want to test face recognition performance. than what is the step that I need to follow ? I am confused
Best
Also have this error in test.py:
line 21 : f1 = model.get_feature(img)
Traceback (most recent call last):
File "/Users/alpullu/Projects/insightface/deploy/test.py", line 21, in
f1 = model.get_feature(img)
File "/Users/alpullu/Projects/insightface/deploy/face_model.py", line 93, in get_feature
self.model.forward(db, is_train=False)
AttributeError: 'NoneType' object has no attribute 'forward'
The author had comment ~/deploy/test.py line 21 now. You had better update your repo
I will update and let you know.
Still not updated. I want to basicly test to compare faces to thest model accuracy. Yes we are not expert try to learn now.
How I can do this ? I need just need a simple guide for:
1- load model LResNet50E-IR
2 - load to face images
3-extrac features
4-compare their similarity
5-make decision depens on the number.
and need to try on CPU.
any help ? it could also helpfull for others.
Best
Hey MyraBaba,
What arguments are you passing when you run test.py? I got the same error when I wasn't specifying the directory to the model. You also have to give it the epoch number. I got it to work with this:
--model C:\Users\{user}\insightface\models\model-r50-am-lfw\,0
The number at the end specifies the epoch. The model-r50-am-lfw folder contains the .params, symbol.json, and the log. It looks like mxnet assumes a lot about the names of these files. For example, the number in front of "-params" has to be the epoch number. So I have "-0000.params" and I pass an epoch of 0. You might have to change the file names to get it to work.
Also, for some reason test.py attempts to do gender and age recognition by default, so that has to be turned off. The end of my test.py looks like this:
`model = face_model.FaceModel(args)
img = cv2.imread('Tom_Hanks_54745.png')
img = model.get_input(img)
f1 = model.get_feature(img)
print(f1[0:10])
f2 = model.get_feature(img)
dist = np.sum(np.square(f1-f2))
print(dist)
sim = np.dot(f1, f2.T)
print(sim)
I got below error:
loading /Users/alpullu/Projects/insightface/models/model-r50-am-lfw/ 0
[19:43:26] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.12.1. Attempting to upgrade...
[19:43:26] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
[19:43:26] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.8.0. Attempting to upgrade...
[19:43:26] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mxnet/model.py:927: DeprecationWarning: mxnet.model.FeedForward has been deprecated. Please use mxnet.mod.Module instead.
kwargs)
[19:43:26] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.8.0. Attempting to upgrade...
[19:43:26] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
[19:43:26] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.8.0. Attempting to upgrade...
[19:43:26] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
[19:43:26] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.8.0. Attempting to upgrade...
[19:43:26] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
[ 1.06205717 -3.00269191 84.31859815 118.66388603]
[[35 50]
[72 48]
[61 78]
[36 90]
[66 87]]
Traceback (most recent call last):
File "/Users/alpullu/Projects/insightface/deploy/test.py", line 29, inkwargs)
f2 = model.get_feature(img)
File "/Users/alpullu/Projects/insightface/deploy/face_model.py", line 93, in get_feature
self.model.forward(db, is_train=False)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mxnet/module/module.py", line 608, in forward
infer_shape error. Arguments:
data: (1,)
self.reshape(new_dshape, new_lshape)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mxnet/module/module.py", line 470, in reshape
self._exec_group.reshape(self._data_shapes, self._label_shapes)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mxnet/module/executor_group.py", line 381, in reshape
self.bind_exec(data_shapes, label_shapes, reshape=True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mxnet/module/executor_group.py", line 357, in bind_exec
allow_up_sizing=True, *dict(data_shapes_i + label_shapes_i))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mxnet/executor.py", line 402, in reshape
arg_shapes, _, aux_shapes = self._symbol.infer_shape(
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mxnet/symbol/symbol.py", line 989, in infer_shape
res = self._infer_shape_impl(False, *args, *kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mxnet/symbol/symbol.py", line 1119, in _infer_shape_impl
ctypes.byref(complete)))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mxnet/base.py", line 146, in check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: Error in operator conv0: [19:43:27] src/operator/nn/./convolution-inl.h:492: Check failed: dshp.ndim() == 4U (1 vs. 4) Input data should be 4D in batch-num_filter-y-x
Stack trace returned 8 entries:
[bt] (0) 0 libmxnet.so 0x0000000107d707cf libmxnet.so + 59343
[bt] (1) 1 libmxnet.so 0x0000000107d7056f libmxnet.so + 58735
[bt] (2) 2 libmxnet.so 0x0000000107e983ed libmxnet.so + 1270765
[bt] (3) 3 libmxnet.so 0x0000000108e9077e MXNDListFree + 1571518
[bt] (4) 4 libmxnet.so 0x0000000108d5de8a MXNDListFree + 315850
[bt] (5) 5 libmxnet.so 0x0000000108d5682e MXNDListFree + 285550
[bt] (6) 6 libmxnet.so 0x0000000108d02d69 MXSymbolInferShape + 2281
[bt] (7) 7 _ctypes.so 0x0000000104c4d5c7 ffi_call_unix64 + 79
Process finished with exit code 1
code is:
`import face_model
import argparse
import cv2
import sys
import numpy as np
parser = argparse.ArgumentParser(description='face model test')
# general
parser.add_argument('--image-size', default='112,112', help='')
parser.add_argument('--model', default='', help='path to load model.')
parser.add_argument('--ga-model', default='', help='path to load model.')
parser.add_argument('--gpu', default=0, type=int, help='gpu id')
parser.add_argument('--det', default=0, type=int, help='mtcnn option, 1 means using R+O, 0 means detect from begining')
parser.add_argument('--flip', default=0, type=int, help='whether do lr flip aug')
parser.add_argument('--threshold', default=1.24, type=float, help='ver dist threshold')
args = parser.parse_args()
model = face_model.FaceModel(args)
img = cv2.imread('Tom_Hanks_54745.png')
img = model.get_input(img)
f1 = model.get_feature(img)
#print(f1[0:10])
# gender, age = model.get_ga(img)
# print(gender)
# print(age)
# sys.exit(0)
img = cv2.imread('/raid5data/dplearn/megaface/facescrubr/112x112/Tom_Hanks/Tom_Hanks_54733.png')
f2 = model.get_feature(img)
dist = np.sum(np.square(f1-f2))
print(dist)
sim = np.dot(f1, f2.T)
print(sim)
#diff = np.subtract(source_feature, target_feature)
#dist = np.sum(np.square(diff),1)
`
models folder has :
model-r50-am-lfw/
-symbol.json
-0000.params
and the run parameter 👍
--model Projects/insightface/models/model-r50-am-lfw/,0
just comment out the line img = cv2.imread('/raid5data/dplearn/megaface/facescrubr/112x112/Tom_Hanks/Tom_Hanks_54733.png')
It's replacing img with nothing because that path doesn't exist
I missed that now it worked.
I gave:
[20:05:47] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
[ 1.06205717 -3.00269191 84.31859815 118.66388603]
[[35 50]
[72 48]
[61 78]
[36 90]
[66 87]]
0.0
1.0
Process finished with exit code 0
So it means the distance is the for the same image.
if I want to compare two image they should be the 122x122 right ? and also face already detected and focused or it si detecting faces for this compare ?
thanks
They should be 112x112. It is detecting faces for this compare.
Hi,
Is this dist = np.sum(np.square(f1-f2)) distance for loss-type=0: Softmax . or loss-type=4: ArcFace ?
And the distance between 0 and 1 right ? closing means to 1 more similar or opposite?
I guess :
distance lower means more similar.
similarity close to 1 means more similar
Sounds right
@MyraBaba @xxllp @Sparkkkk @Wisgon @glorioushedgehog @nttstar
Do you have the new ga-model for age and sex classification? I've been looking all over the place, I still can't find the ga-model.
I don't have a good GPU so that I can't train a model myself, so I want to wait for the author's pre training model.
Do you know that the author is sharing this ga-model?
thanks!
I didnt find also . as far as I know there is not.
by the way ; I am trying to convert the some part to the c++ from python for more speed gain. any experience ?
@MyraBaba
I advise you not to do this because it is too difficult and too much trouble. Spending a lot of time and effort may only get a very small boost. The best way to increase speed is to spend money on GPUs.
@MyraBaba what's the CPU performance result?
Still not able to port %100 to c++ . But I am sure it will be better that python and compilable for the edge.
Most helpful comment
You can manually set Mxnet to use CPU. In face_model.py line 46, set ctx = mx.cpu(0) instead of the argument that passed.