instance_utils
sleap.sleap_io_adaptors.instance_utils
¶
Helper functions for sleap_io.Instance objects.
Functions:
| Name | Description |
|---|---|
bounding_box |
Return bounding box containing all points in |
fill_missing |
Add points for skeleton nodes that are missing in the instance. |
get_centroid |
Return instance centroid as an array of |
get_nodes_from_instance |
Return nodes that have been labelled (non-nan) for this instance. |
instance_get_points_array |
Get points array for backward compatibility. |
instance_get_scores |
Get point-wise scores for backward compatibility. |
instance_same_pose_as_compat |
Compare poses between instances for backward compatibility. |
node_points |
Return a list of (node, point) tuples for all labeled points. |
predicted_instance_from_numpy_compat |
Create PredictedInstance from numpy array with backward compatibility. |
bounding_box(instance)
¶
Return bounding box containing all points in [y1, x1, y2, x2] format.
Source code in sleap/sleap_io_adaptors/instance_utils.py
61 62 63 64 65 66 67 68 69 | |
fill_missing(instance, max_x=None, max_y=None)
¶
Add points for skeleton nodes that are missing in the instance.
This is useful when modifying the skeleton so the nodes appear in the GUI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Instance
|
sleap_io Instance object |
required |
max_x
|
Optional[float]
|
If specified, make sure points are not added outside of valid range. |
None
|
max_y
|
Optional[float]
|
If specified, make sure points are not added outside of valid range. |
None
|
Returns:
| Type | Description |
|---|---|
|
Modified instance with missing points filled |
Source code in sleap/sleap_io_adaptors/instance_utils.py
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 | |
get_centroid(instance)
¶
Return instance centroid as an array of (x, y) coordinates.
Notes
This computes the centroid as the median of the visible points.
Source code in sleap/sleap_io_adaptors/instance_utils.py
288 289 290 291 292 293 294 295 296 | |
get_nodes_from_instance(instance)
¶
Return nodes that have been labelled (non-nan) for this instance.
Source code in sleap/sleap_io_adaptors/instance_utils.py
46 47 48 49 50 51 52 53 54 55 56 57 58 | |
instance_get_points_array(instance)
¶
Get points array for backward compatibility.
This provides backward compatibility for the missing points_array attribute. Maps instance.points_array to instance.numpy() or instance.points["xy"].
Source code in sleap/sleap_io_adaptors/instance_utils.py
172 173 174 175 176 177 178 179 180 181 182 183 | |
instance_get_scores(instance)
¶
Get point-wise scores for backward compatibility.
This provides backward compatibility for the missing scores attribute. Maps instance.scores to point-wise scores from instance.points["score"] if available, or falls back to instance.score for PredictedInstance.
Source code in sleap/sleap_io_adaptors/instance_utils.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
instance_same_pose_as_compat(instance1, instance2)
¶
Compare poses between instances for backward compatibility.
This provides a safe way to compare instance poses that handles array comparison ambiguity issues.
Source code in sleap/sleap_io_adaptors/instance_utils.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
node_points(instance)
¶
Return a list of (node, point) tuples for all labeled points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
sleap_io Instance object |
required |
Returns:
| Type | Description |
|---|---|
List[Tuple[Node, ndarray]]
|
List of (Node, point_data) tuples where point_data is [x, y, visible, complete] |
Source code in sleap/sleap_io_adaptors/instance_utils.py
14 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 | |
predicted_instance_from_numpy_compat(points, skeleton, point_confidences=None, instance_score=None, track=None, **kwargs)
¶
Create PredictedInstance from numpy array with backward compatibility.
This provides backward compatibility for PredictedInstance.from_numpy() method signature changes. Maps old parameter names to new ones.
Source code in sleap/sleap_io_adaptors/instance_utils.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |