Insightface: Windows Support For RetinaFace

Created on 13 May 2019  路  15Comments  路  Source: deepinsight/insightface

Would you please consider supporting Windows for RetinaFace?

The bbox and other cython related codes are written to make use of Linux's GCC to compile and without Linux we can't test the code on Windows platforms.

Thanks for the great support.

Most helpful comment

@Neltherion https://github.com/miwaliu/Retinaface for windows

All 15 comments

You can select the python implementation, instead of cxx.

@nttstar Thanks for the followup. By "python implementation" you mean bbox_overlaps_py? even if I change bbox_overlaps to bbox_overlaps_py there's another problem with anchors_cython which doesn't have a python implementation.

@Neltherion you can rewrite the .pyx files under ./rcnn/cython into .py files, and it will be very slow on web_cam demo

@Ancho5515 Thanks, but as you said, that would be a really bad approach. I'm still not familiar enough with Cython but would be really be that hard to change the code to also work on Windows too?

@Neltherion https://github.com/miwaliu/Retinaface for windows

@miwaliu Thanks... Checking it...

@miwaliu If I'm not mistaken, you're using the Python Wrappers instead of the Cython code... Am I right?

Instead of using python implementation, you can try to compile *.pyx files into windows binaries (*.pyd) :

  1. Replace setup.py in RetinaFace/rcnn/cython dir to:
# setup.py
from distutils.core import setup, Extension
from Cython.Build import cythonize
import numpy

setup(
    ext_modules=cythonize(["bbox.pyx", "anchors.pyx", "cpu_nms.pyx"]),
    include_dirs=[numpy.get_include()]
)
  1. Use cmd to run python setup.py build_ext --inplace in RetinaFace/rcnn/cython dir

  2. Copy the three windows binaries (*.pyd) generated in RetinaFace/rcnn/cython/rcnn/cpython to RetinaFace/rcnn/cython

  3. Run the test code : )

@loscheris锛宩ust do step by step as you do锛孖 got 锟糰nchors.c, anchors.cp36-win_amd64.pyd and anchors.pyx, and bbox.c, bbox.cp36-win_amd64.pyd and bbox.pyx, and cpu_nms.c, cpu_nms.cp36-win_amd64.pyd and cpu_nms.pyx. 锟糱ut still wrong. I don't know WHY.

@github-luffy you can change the cpu_nms.pyx line 25 to :
cdef np.ndarray[np.int_t, ndim=1] order = scores.argsort()[::-1].astype('int32')

@791136190
I have changed the cpu_nms.pyx line 25 to : cdef np.ndarray[np.int_t, ndim=1] order = scores.argsort()[::-1].astype('int32')
But still wrong. Please help me!
Traceback (most recent call last):
File "test.py", line 38, in
faces, landmarks = detector.detect(img, thresh, scales=scales, do_flip=flip)
File "D:\RetinaFace\retinaface.py", line 441, in detect
keep = self.nms(pre_det)
File "D:\RetinaFace\rcnn\processing\nms.py", line 17, in _nms
return cpu_nms(dets, thresh)
File "cpu_nms.pyx", line 25, in rcnn.cython.cpu_nms.cpu_nms
ValueError: Buffer dtype mismatch, expected 'int_t' but got 'long long'

@791136190
I have changed the cpu_nms.pyx line 25 to : cdef np.ndarray[np.int_t, ndim=1] order = scores.argsort()[::-1].astype('int32')
But still wrong. Please help me!
Traceback (most recent call last):
File "test.py", line 38, in
faces, landmarks = detector.detect(img, thresh, scales=scales, do_flip=flip)
File "D:\RetinaFace\retinaface.py", line 441, in detect
keep = self.nms(pre_det)
File "D:\RetinaFace\rcnn\processing\nms.py", line 17, in _nms
return cpu_nms(dets, thresh)
File "cpu_nms.pyx", line 25, in rcnn.cython.cpu_nms.cpu_nms
ValueError: Buffer dtype mismatch, expected 'int_t' but got 'long long'

I have solved the problem, I need to rerun the code python setup.py build_ext --inplace in RetinaFace/rcnn/cython dir

Why don't you give a try to pip install insightface?

It has a pure python implementation and it is pretty efficient.

In my case I run the below code to cythonize python files:

setup(
    cythonize(["bbox.pyx", "anchors.pyx", "cpu_nms.pyx"]),
    include_dirs=[numpy.get_include()]
)

After that, for creating pyd files (don't forget --inplace argument) I comment the above code and then re-run the code by the below setup( I know this is not the best way to resolve the issue but It's a simple workaround)

setup(
    ext_modules=[Extension('bbox', ['bbox.c']),
                 Extension('anchors', ['anchors.c']),
                 Extension('cpu_nms', ['cpu_nms.c'])],
    include_dirs=[numpy.get_include()]
)

Know the pyd files are created :)

Why don't you give a try to pip install insightface?

It has a pure python implementation and it is pretty efficient.

Thanks, I think your solution is the most straightforward when I just want to use the face detection function with pretrained models.

Was this page helpful?
0 / 5 - 0 ratings