BaseModel¶
sahi.models.base
¶
Classes¶
DetectionModel
¶
Source code in sahi/models/base.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
Functions¶
__init__(model_path=None, model=None, config_path=None, device=None, mask_threshold=0.5, confidence_threshold=0.3, category_mapping=None, category_remapping=None, load_at_init=True, image_size=None)
¶
Init object detection/instance segmentation model. Args: model_path: str Path for the instance segmentation model weight config_path: str Path for the mmdetection instance segmentation model config file device: Torch device, "cpu", "mps", "cuda", "cuda:0", "cuda:1", etc. mask_threshold: float Value to threshold mask pixels, should be between 0 and 1 confidence_threshold: float All predictions with score < confidence_threshold will be discarded category_mapping: dict: str to str Mapping from category id (str) to category name (str) e.g. {"1": "pedestrian"} category_remapping: dict: str to int Remap category ids based on category names, after performing inference e.g. {"car": 3} load_at_init: bool If True, automatically loads the model at initialization image_size: int Inference input size.
Source code in sahi/models/base.py
check_dependencies()
¶
convert_original_predictions(shift_amount=[[0, 0]], full_shape=None)
¶
Converts original predictions of the detection model to a list of prediction.ObjectPrediction object. Should be called after perform_inference(). Args: shift_amount: list To shift the box and mask predictions from sliced image to full sized image, should be in the form of [shift_x, shift_y] full_shape: list Size of the full image after shifting, should be in the form of [height, width]
Source code in sahi/models/base.py
load_model()
¶
This function should be implemented in a way that detection model should be initialized and set to self.model. (self.model_path, self.config_path, and self.device should be utilized)
perform_inference(image)
¶
This function should be implemented in a way that prediction should be performed using self.model and the prediction result should be set to self._original_predictions. Args: image: np.ndarray A numpy array that contains the image to be predicted.
Source code in sahi/models/base.py
set_device(device=None)
¶
Sets the device pytorch should use for the model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device
¶ |
Optional[str]
|
Torch device, "cpu", "mps", "cuda", "cuda:0", "cuda:1", etc. |
None
|
Source code in sahi/models/base.py
set_model(model, **kwargs)
¶
This function should be implemented to instantiate a DetectionModel out of an already loaded model Args: model: Any Loaded model