Create text labels. Args: classes (list[int]): a list of class ids for each example. scores (list[float] or None): list of scores for each example. class_names (list[str]): a list of class names, ordered by their ids. ground_truth (bool): whether the labels a
(classes, scores, class_names, ground_truth=False)
| 16 | |
| 17 | |
| 18 | def _create_text_labels(classes, scores, class_names, ground_truth=False): |
| 19 | """ |
| 20 | Create text labels. |
| 21 | Args: |
| 22 | classes (list[int]): a list of class ids for each example. |
| 23 | scores (list[float] or None): list of scores for each example. |
| 24 | class_names (list[str]): a list of class names, ordered by their ids. |
| 25 | ground_truth (bool): whether the labels are ground truth. |
| 26 | Returns: |
| 27 | labels (list[str]): formatted text labels. |
| 28 | """ |
| 29 | try: |
| 30 | labels = [class_names[i] for i in classes] |
| 31 | except IndexError: |
| 32 | logger.error("Class indices get out of range: {}".format(classes)) |
| 33 | return None |
| 34 | |
| 35 | if ground_truth: |
| 36 | labels = ["[{}] {}".format("GT", label) for label in labels] |
| 37 | elif scores is not None: |
| 38 | assert len(classes) == len(scores) |
| 39 | labels = [ |
| 40 | "[{:.2f}] {}".format(s, label) for s, label in zip(scores, labels) |
| 41 | ] |
| 42 | return labels |
| 43 | |
| 44 | |
| 45 | # class ImgVisualizer(Visualizer): |
nothing calls this directly
no outgoing calls
no test coverage detected