logo
Browse Source

fix display issue.

Signed-off-by: wxywb <xy.wang@zilliz.com>
main
wxywb 3 years ago
parent
commit
c8e40df761
  1. 18
      README.md
  2. BIN
      result1.png
  3. BIN
      result2.png
  4. 11
      retinaface.py

18
README.md

@ -6,12 +6,11 @@
## Desription ## Desription
This operator detects faces in the images by using [RetinaFace](https://arxiv.org/abs/1905.00641) Detector. It will return the bounding box positions and the confidence scores of detected faces. This repo is a adapataion from [repo](https://github.com/biubug6/Pytorch_Retinaface).
This operator detects faces in the images by using [RetinaFace](https://arxiv.org/abs/1905.00641) Detector. It will return the bounding box positions and the confidence scores of detected faces. This repo is an adaptaion from [biubug6/Pytorch_Retinaface](https://github.com/biubug6/Pytorch_Retinaface).
## Code Example ## Code Example
Load an image from path './dog.jpg'
and use the pretrained RetinaFace to generate face bounding boxes.
Load an image from path './turing.png' and use the pretrained RetinaFace model to generate face bounding boxes and confidence scores.
*Write the pipeline in simplified style*: *Write the pipeline in simplified style*:
@ -34,7 +33,8 @@ import towhee
towhee.glob['path']('turing.png') \ towhee.glob['path']('turing.png') \
.image_decode.cv2['path', 'img']() \ .image_decode.cv2['path', 'img']() \
.face_detection.retinaface['img', ('bbox','score')]() \ .face_detection.retinaface['img', ('bbox','score')]() \
.select('img', 'bbox', 'score').show()
.select('img', 'bbox', 'score') \
.show()
``` ```
<img src="https://towhee.io/face-detection/retinaface/raw/branch/main/result2.png" alt="result2" style="height:60px;"/> <img src="https://towhee.io/face-detection/retinaface/raw/branch/main/result2.png" alt="result2" style="height:60px;"/>
@ -43,15 +43,15 @@ towhee.glob['path']('turing.png') \
Create the operator via the following factory method. Create the operator via the following factory method.
***ops.face_detection.retinaface()***
***face_detection.retinaface()***
## Interface ## Interface
A face detection operator takes an image as input. it generates the bounding box positions and confidence scores back to ndarray.
A face detection operator takes an image as input. It generates the bounding box positions and confidence scores back to ndarray.
**Parameters:** **Parameters:**
***image***: *numpy.ndarray.*
***img***: *numpy.ndarray.*
​ the image to detect faces. ​ the image to detect faces.
@ -59,11 +59,11 @@ A face detection operator takes an image as input. it generates the bounding box
**Returns:** **Returns:**
*numpy.ndarray*
*List[(int, int, int, int)]*
​ The detected face bounding boxes. ​ The detected face bounding boxes.
*numpy.ndarray*
*List[float]*
​ The detected face bounding boxes confident scores. ​ The detected face bounding boxes confident scores.

BIN
result1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 15 KiB

BIN
result2.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 116 KiB

After

Width:  |  Height:  |  Size: 123 KiB

11
retinaface.py

@ -29,7 +29,7 @@ from towhee._types import Image
from towhee.types.arg import arg, to_image_color from towhee.types.arg import arg, to_image_color
@register(output_schema=['bbox', 'score'])
@register(output_schema=['box', 'score'])
class Retinaface(Operator): class Retinaface(Operator):
""" """
Retinaface Retinaface
@ -41,8 +41,11 @@ class Retinaface(Operator):
self.model = Model() self.model = Model()
@arg(1, to_image_color('RGB') ) @arg(1, to_image_color('RGB') )
def __call__(self, image: Image):
img = torch.FloatTensor(numpy.asarray(to_pil(image)))
def __call__(self, img: Image):
img = torch.FloatTensor(numpy.asarray(to_pil(img)))
bboxes, keypoints = self.model(img) bboxes, keypoints = self.model(img)
bboxes = bboxes.cpu().detach().numpy() bboxes = bboxes.cpu().detach().numpy()
return bboxes[:,:4].astype(int), bboxes[:,4]
bl, sl = bboxes[:,:4].astype(int), bboxes[:,4]
rbboxes = [tuple(box) for box in bl]
return rbboxes, sl.tolist()

Loading…
Cancel
Save