💎A high level pipeline for face landmarks detection, it supports training, evaluating, exporting, inference(Python/C++) and 100+ data augmentations, can easily install via pip.
from torchlm.data import LandmarksWFLWConverter, Landmarks300WConverter
# setup your path to the original downloaded dataset from official
converter = Landmarks300WConverter(
data_dir="/data/extended/landmark/ibug_300W_dlib/", save_dir="/data/extended/landmark/ibug_300W_dlib/converted",
extend=0.2, rebuild=True, target_size=256, keep_aspect=False,
force_normalize=True, force_absolute_path=True
)
converter.convert()
converter.show(count=30) # show you some converted images with landmarks for debugging
Error Message
Converting 300W Train Annotations: 0%| | 0/3148 [00:00<?, ?it/s]
---------------------------------------------------------------------------
UFuncTypeError Traceback (most recent call last)
Input In [1], in <cell line: 8>()
2 # setup your path to the original downloaded dataset from official
3 converter = Landmarks300WConverter(
4 data_dir="/data/extended/landmark/ibug_300W_dlib//", save_dir="/data/extended/landmark/ibug_300W_dlib/converted",
5 extend=0.2, rebuild=True, target_size=256, keep_aspect=False,
6 force_normalize=True, force_absolute_path=True
7 )
----> 8 converter.convert()
9 converter.show(count=30)
File /opt/anaconda/envs/facial/lib/python3.9/site-packages/torchlm/data/_converters.py:329, in Landmarks300WConverter.convert(self)
322 test_anno_file = open(self.save_test_annotation_path, "w")
324 for annotation in tqdm.tqdm(
325 self.train_annotations,
326 colour="GREEN",
327 desc="Converting 300W Train Annotations"
328 ):
--> 329 crop, landmarks, new_img_name = self._process_annotation(annotation=annotation)
330 if crop is None or landmarks is None:
331 continue
File /opt/anaconda/envs/facial/lib/python3.9/site-packages/torchlm/data/_converters.py:493, in Landmarks300WConverter._process_annotation(self, annotation)
491 crop = image[int(ymin):int(ymax), int(xmin):int(xmax), :]
492 # adjust according to left-top corner
--> 493 landmarks[:, 0] -= float(xmin)
494 landmarks[:, 1] -= float(ymin)
496 if self.target_size is not None and self.resize_op is not None:
UFuncTypeError: Cannot cast ufunc 'subtract' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'
Solution
Change this line
# adjust according to left-top corner
landmarks[:, 0] -= float(xmin)
landmarks[:, 1] -= float(ymin)
Use this line instead
# adjust according to left-top corner
landmarks[:, 0] = landmarks[:, 0] - float(xmin)
landmarks[:, 1] = landmarks[:, 1] - float(ymin)
Example code
Error Message
Solution
Change this line
Use this line instead
Environment