2 Copyright (c) 2019 Intel Corporation
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
19 from ..config import PathField
20 from ..representation import FacialLandmarksAnnotation
21 from ..utils import convert_bboxes_xywh_to_x1y1x2y2, read_csv
22 from .format_converter import BaseFormatConverter, BaseFormatConverterConfig
25 class LandmarksRegressionConfig(BaseFormatConverterConfig):
26 landmarks_csv_file = PathField()
27 bbox_csv_file = PathField(optional=True)
30 class LandmarksRegression(BaseFormatConverter):
31 __provider__ = 'landmarks_regression'
33 _config_validator_type = LandmarksRegressionConfig
36 self.landmarks_csv = self.config['landmarks_csv_file']
37 self.bbox_csv = self.config.get('bbox_csv_file')
41 for row in read_csv(self.landmarks_csv):
42 identifier = row['NAME_ID'] + '.jpg'
44 [float(row["P1X"]), float(row["P2X"]), float(row["P3X"]), float(row["P4X"]), float(row["P5X"])]
47 [float(row["P1Y"]), float(row["P2Y"]), float(row["P3Y"]), float(row["P4Y"]), float(row["P5Y"])]
50 annotation = FacialLandmarksAnnotation(identifier, x_values, y_values)
51 annotation.metadata['left_eye'] = 0
52 annotation.metadata['right_eye'] = 1
53 annotations.append(annotation)
56 for index, row in enumerate(read_csv(self.bbox_csv)):
57 annotations[index].metadata['rect'] = convert_bboxes_xywh_to_x1y1x2y2(
58 int(row["X"]), int(row["Y"]), int(row["W"]), int(row["H"])
62 'label_map': {0: 'Left Eye', 1: 'Right Eye', 2: 'Nose', 3: 'Left Mouth Corner', 4: 'Right Mouth Corner'}
64 return annotations, meta