micro_sam.evaluation.experiments
Predefined experiment settings for experiments with different prompt strategies.
1"""Predefined experiment settings for experiments with different prompt strategies. 2""" 3 4from typing import Dict, List, Optional 5 6 7# TODO fully define the dict type 8ExperimentSetting = Dict 9ExperimentSettings = List[ExperimentSetting] 10"""@private""" 11 12 13def full_experiment_settings( 14 use_boxes: bool = False, 15 positive_range: Optional[List[int]] = None, 16 negative_range: Optional[List[int]] = None, 17) -> ExperimentSettings: 18 """The full experiment settings. 19 20 Args: 21 use_boxes: Whether to run the experiments with or without boxes. 22 positive_range: The different number of positive points that will be used. 23 By defaul the values are set to [1, 2, 4, 8, 16]. 24 negative_range: The different number of negative points that will be used. 25 By defaul the values are set to [0, 1, 2, 4, 8, 16]. 26 27 Returns: 28 The list of experiment settings. 29 """ 30 experiment_settings = [] 31 if use_boxes: 32 experiment_settings.append( 33 {"use_points": False, "use_boxes": True, "n_positives": 0, "n_negatives": 0} 34 ) 35 36 # set default values for the ranges if none were passed 37 if positive_range is None: 38 positive_range = [1, 2, 4, 8, 16] 39 if negative_range is None: 40 negative_range = [0, 1, 2, 4, 8, 16] 41 42 for n_positives in positive_range: 43 for n_negatives in negative_range: 44 if n_positives == 0 and n_negatives == 0: 45 continue 46 experiment_settings.append( 47 {"use_points": True, "use_boxes": use_boxes, "n_positives": n_positives, "n_negatives": n_negatives} 48 ) 49 50 return experiment_settings 51 52 53def default_experiment_settings() -> ExperimentSettings: 54 """The three default experiment settings. 55 56 For the default experiments we use a single positive prompt, 57 two positive and four negative prompts and box prompts. 58 59 Returns: 60 The list of experiment settings. 61 """ 62 experiment_settings = [ 63 {"use_points": True, "use_boxes": False, "n_positives": 1, "n_negatives": 0}, # p1-n0 64 {"use_points": True, "use_boxes": False, "n_positives": 2, "n_negatives": 4}, # p2-n4 65 {"use_points": True, "use_boxes": False, "n_positives": 4, "n_negatives": 8}, # p4-n8 66 {"use_points": False, "use_boxes": True, "n_positives": 0, "n_negatives": 0}, # only box prompts 67 ] 68 return experiment_settings 69 70 71def get_experiment_setting_name(setting: ExperimentSetting) -> str: 72 """Get the name for the given experiment setting. 73 74 Args: 75 setting: The experiment setting. 76 Returns: 77 The name for this experiment setting. 78 """ 79 use_points, use_boxes = setting["use_points"], setting["use_boxes"] 80 assert use_points or use_boxes 81 prefix = "points" if use_points else "box" 82 pos, neg = setting["n_positives"], setting["n_negatives"] 83 name = f"p{pos}-n{neg}" if use_points else "p0-n0" 84 return f"{prefix}/{name}"
ExperimentSetting =
typing.Dict
def
full_experiment_settings( use_boxes: bool = False, positive_range: Optional[List[int]] = None, negative_range: Optional[List[int]] = None) -> List[Dict]:
14def full_experiment_settings( 15 use_boxes: bool = False, 16 positive_range: Optional[List[int]] = None, 17 negative_range: Optional[List[int]] = None, 18) -> ExperimentSettings: 19 """The full experiment settings. 20 21 Args: 22 use_boxes: Whether to run the experiments with or without boxes. 23 positive_range: The different number of positive points that will be used. 24 By defaul the values are set to [1, 2, 4, 8, 16]. 25 negative_range: The different number of negative points that will be used. 26 By defaul the values are set to [0, 1, 2, 4, 8, 16]. 27 28 Returns: 29 The list of experiment settings. 30 """ 31 experiment_settings = [] 32 if use_boxes: 33 experiment_settings.append( 34 {"use_points": False, "use_boxes": True, "n_positives": 0, "n_negatives": 0} 35 ) 36 37 # set default values for the ranges if none were passed 38 if positive_range is None: 39 positive_range = [1, 2, 4, 8, 16] 40 if negative_range is None: 41 negative_range = [0, 1, 2, 4, 8, 16] 42 43 for n_positives in positive_range: 44 for n_negatives in negative_range: 45 if n_positives == 0 and n_negatives == 0: 46 continue 47 experiment_settings.append( 48 {"use_points": True, "use_boxes": use_boxes, "n_positives": n_positives, "n_negatives": n_negatives} 49 ) 50 51 return experiment_settings
The full experiment settings.
Arguments:
- use_boxes: Whether to run the experiments with or without boxes.
- positive_range: The different number of positive points that will be used. By defaul the values are set to [1, 2, 4, 8, 16].
- negative_range: The different number of negative points that will be used. By defaul the values are set to [0, 1, 2, 4, 8, 16].
Returns:
The list of experiment settings.
def
default_experiment_settings() -> List[Dict]:
54def default_experiment_settings() -> ExperimentSettings: 55 """The three default experiment settings. 56 57 For the default experiments we use a single positive prompt, 58 two positive and four negative prompts and box prompts. 59 60 Returns: 61 The list of experiment settings. 62 """ 63 experiment_settings = [ 64 {"use_points": True, "use_boxes": False, "n_positives": 1, "n_negatives": 0}, # p1-n0 65 {"use_points": True, "use_boxes": False, "n_positives": 2, "n_negatives": 4}, # p2-n4 66 {"use_points": True, "use_boxes": False, "n_positives": 4, "n_negatives": 8}, # p4-n8 67 {"use_points": False, "use_boxes": True, "n_positives": 0, "n_negatives": 0}, # only box prompts 68 ] 69 return experiment_settings
The three default experiment settings.
For the default experiments we use a single positive prompt, two positive and four negative prompts and box prompts.
Returns:
The list of experiment settings.
def
get_experiment_setting_name(setting: Dict) -> str:
72def get_experiment_setting_name(setting: ExperimentSetting) -> str: 73 """Get the name for the given experiment setting. 74 75 Args: 76 setting: The experiment setting. 77 Returns: 78 The name for this experiment setting. 79 """ 80 use_points, use_boxes = setting["use_points"], setting["use_boxes"] 81 assert use_points or use_boxes 82 prefix = "points" if use_points else "box" 83 pos, neg = setting["n_positives"], setting["n_negatives"] 84 name = f"p{pos}-n{neg}" if use_points else "p0-n0" 85 return f"{prefix}/{name}"
Get the name for the given experiment setting.
Arguments:
- setting: The experiment setting.
Returns:
The name for this experiment setting.