deeplabcut.pose_estimation_pytorch.data.generative_sampling
A file containing code to perform generative sampling of keypoints for CTD.
This code comes from PoseFix (see https://arxiv.org/pdf/1812.03595.pdf), and was then
adapted for BUCTD (github.com/amathislab/BUCTD/blob/main/lib/dataset/pose_synthesis.py,
see synthesize_pose_fish(...)).
They say:
... synthesized poses need to be diverse and realistic. To satisfy these properties, we generate synthesized poses randomly based on the error distributions of real poses as described in [24]. The distributions include the frequency of each pose error (i.e., jitter, inversion, swap, and miss) according to the joint type, number of visible keypoints, and overlap in the input image. ... Types of Keypoints: Good. Good status is defined as a very small displacement from the GT keypoint. Jitter. Jitter error is defined as a small displacement from the GT keypoint. Inversion. Inversion error occurs when a pose estimation model is confused between semantically similar parts that belong to the same instance. Swap. Swap error represents a confusion between the same or similar parts which belong to different persons. Miss. Miss error represents a large displacement from the GT keypoint position.
In BUCTD and their adaptation to the maDLC fish dataset, they set: if cfg.DATASET.DATASET == 'coco': kps_symmetry = [(1, 2), (3, 4), (5, 6), ...] kps_sigmas = np.array([.26, .25, .25, ...]) / 10.0 elif cfg.DATASET.DATASET == 'crowdpose': kps_sigmas = np.array([.79, .79, .72, ...])/10.0 kps_symmetry= [(0, 1), (2, 3), (4, 5), ...] # l/r shoulder, l/r elbow, wrist, else: kps_symmetry = [] kps_sigmas = np.array([1.] * num_kpts)/10.0
Classes:
| Name | Description |
|---|---|
GenSamplingConfig |
Configuration for CTD models. |
GenerativeSampler |
Performs generative sampling of keypoints for CTD model training. |
GenSamplingConfig
dataclass
Configuration for CTD models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
The margin added around conditional keypoints |
required |
|
float | list[float]
|
The sigma for each keypoint. |
0.1
|
|
list[tuple[int, int]] | None
|
Indices of symmetric keypoints (e.g. left/right eye) |
None
|
|
float
|
The probability of applying jitter. Jitter error is defined as a small displacement from the GT keypoint. |
0.16
|
|
float
|
The probability of applying a swap error. Swap error represents a confusion between the same or similar parts which belong to different persons. |
0.08
|
|
float
|
The probability of applying an inversion error. Inversion error occurs when a pose estimation model is confused between semantically similar parts that belong to the same instance. |
0.03
|
|
float
|
The probability of applying a miss error. Miss error represents a large displacement from the GT keypoint position. |
0.1
|
Source code in deeplabcut/pose_estimation_pytorch/data/generative_sampling.py
GenerativeSampler
Performs generative sampling of keypoints for CTD model training.
Methods:
| Name | Description |
|---|---|
__call__ |
Samples keypoints. |
__init__ |
Args: |
get_distance_wrt_keypoint_sim |
Args: |
Source code in deeplabcut/pose_estimation_pytorch/data/generative_sampling.py
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 194 195 196 197 198 199 200 201 202 203 204 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 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
__call__
__call__(keypoints: ndarray, near_keypoints: ndarray, area: float, image_size: tuple[int, int]) -> np.ndarray
Samples keypoints.
PoseFix uses conditional keypoints (estimated by a bottom-up model) when ground truth keypoints are not available. For simplicity, we omit that. See https://github.com/mks0601/PoseFix_RELEASE/blob/master/main/gen_batch.py#L76
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
(num_keypoints, x-y-visibility) the ground truth keypoints |
required |
|
ndarray
|
(num_other_individuals, num_keypoints, x-y-visibility) joints from other individuals near this one, for which keypoints might be swapped |
required |
|
float
|
the total area of the bounding box surrounding the keypoints |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
the generative sampled keypoints, of shape (num_keypoints, x-y-visibility) |
Source code in deeplabcut/pose_estimation_pytorch/data/generative_sampling.py
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 194 195 196 197 198 199 200 201 202 203 204 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 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
__init__
__init__(
num_keypoints: int,
keypoint_sigmas: float | list[float] = 0.1,
keypoints_symmetry: list[tuple[int, int]] | None = None,
jitter_prob: float = 0.16,
swap_prob: float = 0.08,
inv_prob: float = 0.03,
miss_prob: float = 0.1,
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
the number of keypoints per individual |
required |
|
float | list[float]
|
the sigma for each keypoint |
0.1
|
|
list[tuple[int, int]] | None
|
indices of keypoints that are symmetric (e.g., left and right eye) |
None
|
|
float
|
The probability of applying jitter. Jitter error is defined as a small displacement from the GT keypoint. |
0.16
|
|
float
|
The probability of applying a swap error. Swap error represents a confusion between the same or similar parts which belong to different persons. |
0.08
|
|
float
|
The probability of applying an inversion error. Inversion error occurs when a pose estimation model is confused between semantically similar parts that belong to the same instance. |
0.03
|
|
float
|
The probability of applying a miss error. Miss error represents a large displacement from the GT keypoint position. |
0.1
|
Source code in deeplabcut/pose_estimation_pytorch/data/generative_sampling.py
get_distance_wrt_keypoint_sim
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
float
|
the desired keypoint similarity |
required |
|
float
|
the area of the bounding box for the individual |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
For each bodypart, the L2 distance for which the keypoint similarity is equal to ks |