From 9f09a83b0a74b97bc08fb2e911ff723134473191 Mon Sep 17 00:00:00 2001 From: wxywb Date: Thu, 31 Mar 2022 16:03:26 +0800 Subject: [PATCH] shape bug fix. Signed-off-by: wxywb --- README.md | 71 ++++++++++++++++++++---------------------------- mobilefacenet.py | 8 ++++-- 2 files changed, 34 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 35ee893..8f7ed78 100644 --- a/README.md +++ b/README.md @@ -5,23 +5,46 @@ ## Desription -A class of extremely efficient CNN models to extract 68 landmarks from a facial image[1]. +A class of extremely efficient CNN models to extract 68 landmarks from a facial image[MobileFaceNets](https://arxiv.org/pdf/1804.07573.pdf). +## Code Example + +extracted facial landmark from './img1.jpg'. + +*Write the pipeline in simplified style*: + +```python +from towhee import dc + +dc.glob('./img1.jpg') \ + .face_landmark_detection.mobilefacenet() \ + .to_list() +``` + +*Write a same pipeline with explicit inputs/outputs name specifications:* ```python -from towhee import ops +from towhee import dc -model = ops.face_landmark_detection.mobilefacenet() -landmark = model(img) +dc.glob['path']('./img1.jpg') \ + .image_decode.cv2['path', 'img']() \ + .face_landmark_detection.mobilefacenet() \ + .to_list() ``` ## Factory Constructor Create the operator via the following factory method -***ops.face_landmark_detection.mobilefacenet()*** +***ops.face_landmark_detection.mobilefacenet(pretrained = True)*** + +**Parameters:** +​ ***pretrained*** +​ whether load the pretrained weights.. + +​ supported types: `bool`, default is True, using pretrained weights ## Interface @@ -29,13 +52,6 @@ An image embedding operator takes an image as input. it extracts the embedding b **Args:** -​ ***framework*** - -​ the framework of the model - -​ supported types: `str`, default is 'pytorch' - - ​ ***pretrained*** ​ whether load the pretrained weights.. @@ -45,7 +61,7 @@ An image embedding operator takes an image as input. it extracts the embedding b **Parameters:** -​ ***image***: *towhee._types.Image* +​ ***image***: *np.ndarray* ​ The input image. @@ -54,32 +70,3 @@ An image embedding operator takes an image as input. it extracts the embedding b ​ The extracted facial landmark. -## Code Example - -extracted facial landmark from './img1.jpg'. - -*Write the pipeline in simplified style*: - -```python -import towhee.DataCollection as dc - -dc.glob('./img1.jpg') - .face_landmark_detection.mobilefacenet() - .to_list() -``` - -*Write a same pipeline with explicit inputs/outputs name specifications:* - -```python -import towhee.DataCollection as dc - -dc.glob['path']('./img1.jpg') - .image_decode.cv2['path', 'img']() - .face_landmark_detection.mobilefacenet() - .to_list() -``` - - -## Reference - -[1].https://arxiv.org/pdf/1804.07573.pdf diff --git a/mobilefacenet.py b/mobilefacenet.py index 98666d6..e8a472d 100644 --- a/mobilefacenet.py +++ b/mobilefacenet.py @@ -22,9 +22,11 @@ import torch from torchvision import transforms +from towhee import register from towhee.operator import NNOperator from towhee.types.image_utils import to_pil from towhee._types import Image +from towhee.types import arg, to_image_color #import mobilefacenet @@ -34,8 +36,8 @@ class Mobilefacenet(NNOperator): Mobilefacenet """ - def __init__(self, framework: str = 'pytorch', pretrained = True): - super().__init__(framework=framework) + def __init__(self, pretrained = True): + super().__init__() sys.path.append(str(Path(__file__).parent)) from mobilefacenet_impl import MobileFaceNet self.model = MobileFaceNet([112, 112], 136) @@ -47,7 +49,7 @@ class Mobilefacenet(NNOperator): normalize = transforms.Normalize( mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) - self.tfms = transforms.Compose([transforms.Scale(112), + self.tfms = transforms.Compose([transforms.Scale([112,112]), transforms.ToTensor(), normalize])