If class ID is specified, filter all other classes. Args: labels: `int64` `Tensor` or `SparseTensor` with shape [D1, ... DN, num_labels], where N >= 1 and num_labels is the number of target classes for the associated prediction. Commonly, N=1 and `labels` has shape [batch_si
(labels, predictions_idx, selected_id=None)
| 2258 | |
| 2259 | |
| 2260 | def _maybe_select_class_id(labels, predictions_idx, selected_id=None): |
| 2261 | """If class ID is specified, filter all other classes. |
| 2262 | |
| 2263 | Args: |
| 2264 | labels: `int64` `Tensor` or `SparseTensor` with shape |
| 2265 | [D1, ... DN, num_labels], where N >= 1 and num_labels is the number of |
| 2266 | target classes for the associated prediction. Commonly, N=1 and `labels` |
| 2267 | has shape [batch_size, num_labels]. [D1, ... DN] must match |
| 2268 | `predictions_idx`. |
| 2269 | predictions_idx: `int64` `Tensor` of class IDs, with shape [D1, ... DN, k] |
| 2270 | where N >= 1. Commonly, N=1 and `predictions_idx` has shape |
| 2271 | [batch size, k]. |
| 2272 | selected_id: Int id to select. |
| 2273 | |
| 2274 | Returns: |
| 2275 | Tuple of `labels` and `predictions_idx`, possibly with classes removed. |
| 2276 | """ |
| 2277 | if selected_id is None: |
| 2278 | return labels, predictions_idx |
| 2279 | return (_select_class_id(labels, selected_id), |
| 2280 | _select_class_id(predictions_idx, selected_id)) |
| 2281 | |
| 2282 | |
| 2283 | def _sparse_true_positive_at_k(labels, |
no test coverage detected