garmentiq.landmark.derive
Deriving landmarks that the detection model does not predict.
1"""Deriving landmarks that the detection model does not predict.""" 2import copy 3from garmentiq.landmark.derivation import ( 4 prepare_args, 5 process, 6) 7 8 9def derive( 10 class_name: str, detection_dict: dict, derivation_dict: dict, **extra_args 11) -> tuple: 12 """ 13 Derives non-predefined landmark coordinates based on predefined landmarks and a mask. 14 15 This function identifies landmarks marked for derivation within the `detection_dict`, 16 prepares arguments for the derivation function using `prepare_args`, 17 processes the derivation using `process`, and updates the `detection_dict` 18 with the newly derived coordinates. 19 20 Args: 21 class_name (str): The name of the garment class. 22 detection_dict (dict): The dictionary containing detected landmarks, including predefined ones. 23 derivation_dict (dict): The dictionary defining derivation rules and available functions. 24 **extra_args: Additional keyword arguments required by the derivation functions, 25 such as `landmark_coords` (NumPy array of landmark coordinates) 26 and `np_mask` (NumPy array of the segmentation mask). 27 28 Returns: 29 tuple: A tuple containing: 30 - derived_coords (dict): A dictionary mapping the derived landmark IDs to their new (x, y) coordinates. 31 - detection_dict (dict): The original `detection_dict` updated with the derived landmark coordinates. 32 """ 33 non_predefined_landmark = { 34 k: detection_dict[class_name]["landmarks"][k]["derivation"] 35 for k, v in detection_dict[class_name]["landmarks"].items() 36 if v.get("predefined") is False 37 } 38 derived_coords = {} 39 detection_dict_copy = copy.deepcopy(detection_dict) 40 for k, v in non_predefined_landmark.items(): 41 args = prepare_args(non_predefined_landmark[k], derivation_dict, **extra_args) 42 derived_coord = tuple(float(x) for x in process(**args)) 43 derived_coords[k] = derived_coord 44 detection_dict_copy[class_name]["landmarks"][k]["x"] = derived_coord[0] 45 detection_dict_copy[class_name]["landmarks"][k]["y"] = derived_coord[1] 46 return derived_coords, detection_dict_copy
def
derive( class_name: str, detection_dict: dict, derivation_dict: dict, **extra_args) -> tuple:
10def derive( 11 class_name: str, detection_dict: dict, derivation_dict: dict, **extra_args 12) -> tuple: 13 """ 14 Derives non-predefined landmark coordinates based on predefined landmarks and a mask. 15 16 This function identifies landmarks marked for derivation within the `detection_dict`, 17 prepares arguments for the derivation function using `prepare_args`, 18 processes the derivation using `process`, and updates the `detection_dict` 19 with the newly derived coordinates. 20 21 Args: 22 class_name (str): The name of the garment class. 23 detection_dict (dict): The dictionary containing detected landmarks, including predefined ones. 24 derivation_dict (dict): The dictionary defining derivation rules and available functions. 25 **extra_args: Additional keyword arguments required by the derivation functions, 26 such as `landmark_coords` (NumPy array of landmark coordinates) 27 and `np_mask` (NumPy array of the segmentation mask). 28 29 Returns: 30 tuple: A tuple containing: 31 - derived_coords (dict): A dictionary mapping the derived landmark IDs to their new (x, y) coordinates. 32 - detection_dict (dict): The original `detection_dict` updated with the derived landmark coordinates. 33 """ 34 non_predefined_landmark = { 35 k: detection_dict[class_name]["landmarks"][k]["derivation"] 36 for k, v in detection_dict[class_name]["landmarks"].items() 37 if v.get("predefined") is False 38 } 39 derived_coords = {} 40 detection_dict_copy = copy.deepcopy(detection_dict) 41 for k, v in non_predefined_landmark.items(): 42 args = prepare_args(non_predefined_landmark[k], derivation_dict, **extra_args) 43 derived_coord = tuple(float(x) for x in process(**args)) 44 derived_coords[k] = derived_coord 45 detection_dict_copy[class_name]["landmarks"][k]["x"] = derived_coord[0] 46 detection_dict_copy[class_name]["landmarks"][k]["y"] = derived_coord[1] 47 return derived_coords, detection_dict_copy
Derives non-predefined landmark coordinates based on predefined landmarks and a mask.
This function identifies landmarks marked for derivation within the detection_dict,
prepares arguments for the derivation function using prepare_args,
processes the derivation using process, and updates the detection_dict
with the newly derived coordinates.
Arguments:
- class_name (str): The name of the garment class.
- detection_dict (dict): The dictionary containing detected landmarks, including predefined ones.
- derivation_dict (dict): The dictionary defining derivation rules and available functions.
- **extra_args: Additional keyword arguments required by the derivation functions,
such as
landmark_coords(NumPy array of landmark coordinates) andnp_mask(NumPy array of the segmentation mask).
Returns:
tuple: A tuple containing: - derived_coords (dict): A dictionary mapping the derived landmark IDs to their new (x, y) coordinates. - detection_dict (dict): The original
detection_dictupdated with the derived landmark coordinates.