becauseofAI / MobileFace

A face recognition solution on mobile device.
MIT License
746 stars 207 forks source link

face size for feature extraction #8

Closed kaishijeng closed 4 years ago

kaishijeng commented 5 years ago

Insightface uses face size (112,112) for feature extraction. In your example in get_face_feature_mxnet.py, face size (100,100). is used. Should we use (100,100) for feature extraction?

Thanks,

AaronYKing commented 5 years ago

@kaishijeng The identification v1 is trained with size (100, 100), and v2 and v3 are (112, 112). When reference, you can use any reasonable size, such as (100, 100), (112, 112), (96,96), (128, 128). But testing using the same size as training maybe get the best performance.

kaishijeng commented 5 years ago

@AaronYKing

Thanks for the info. I am using identification V2 to extract feature after croping and alignment (using dlib) and do comparisons for a couple people, the result is not very encouraging, ie, not able to get find a good threshold for feature distance. Below is my alignment code and preprocessing step before feature extraction:

      align2=fa.align(img2, gray2, rect)
      align2=cv2.resize(align2,(112,112))
      align2 = (align2-127.5)/127.5
AaronYKing commented 5 years ago

@kaishijeng Can you test the aligned faces provided by the author in the link firstly?

kaishijeng commented 5 years ago

@AaronYKing

Will try your suggestion later. It seems there is an issue to use identification V2 in get_face_feature_mxnet.py. V1 is OK with this code. The error is:

Traceback (most recent call last): File "./get_face_feature_mxnet.py", line 74, in face_feature_extractor = MobileFaceFeatureExtractor(model_file, epoch, batch_size, context, gpu_id) File "./get_face_feature_mxnet.py", line 53, in init self.model.set_params(arg_params, aux_params) File "/usr/local/lib/python3.5/dist-packages/mxnet/module/module.py", line 350, in set_params allow_extra=allow_extra) File "/usr/local/lib/python3.5/dist-packages/mxnet/module/module.py", line 309, in init_params _impl(desc, arr, arg_params) File "/usr/local/lib/python3.5/dist-packages/mxnet/module/module.py", line 297, in _impl cache_arr.copyto(arr) File "/usr/local/lib/python3.5/dist-packages/mxnet/ndarray/ndarray.py", line 2074, in copyto return _internal._copyto(self, out=other) File "", line 25, in _copyto File "/usr/local/lib/python3.5/dist-packages/mxnet/_ctypes/ndarray.py", line 92, in _imperative_invoke ctypes.byref(out_stypes))) File "/usr/local/lib/python3.5/dist-packages/mxnet/base.py", line 252, in check_call raise MXNetError(py_str(_LIB.MXGetLastError())) mxnet.base.MXNetError: [14:13:22] /home/travis/build/dmlc/mxnet-distro/mxnet-build/3rdparty/mshadow/../../src/operator/tensor/../elemwise_op_common.h:135: Check failed: assign(&dattr, vec.at(i)) Incompatible attr in node at 0-th output: expected [32,3,3,3], got [32,1,3,3]

Stack trace returned 10 entries: [bt] (0) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x3e95ea) [0x7f64f32bd5ea] [bt] (1) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x3e9c11) [0x7f64f32bdc11] [bt] (2) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x72e5fd) [0x7f64f36025fd] [bt] (3) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x72f23d) [0x7f64f360323d] [bt] (4) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(mxnet::imperative::SetShapeType(mxnet::Context const&, nnvm::NodeAttrs const&, std::vector<mxnet::NDArray, std::allocator<mxnet::NDArray> > const&, std::vector<mxnet::NDArray, std::allocator<mxnet::NDArray> > const&, mxnet::DispatchMode)+0x94a) [0x7f64f5d013ca] [bt] (5) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(mxnet::Imperative::Invoke(mxnet::Context const&, nnvm::NodeAttrs const&, std::vector<mxnet::NDArray, std::allocator<mxnet::NDArray> > const&, std::vector<mxnet::NDArray, std::allocator<mxnet::NDArray*> > const&)+0x309) [0x7f64f5d0bc89] [bt] (6) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x2d3fd69) [0x7f64f5c13d69] [bt] (7) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(MXImperativeInvokeEx+0x6f) [0x7f64f5c1435f] [bt] (8) /usr/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so(ffi_call_unix64+0x4c) [0x7f651dbb7e20] [bt] (9) /usr/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so(ffi_call+0x2eb) [0x7f651dbb788b]

becauseofAI commented 5 years ago

@kaishijeng Sorry for the late reply. I have fixed the bug.