(mask, point_labels = 1, seed=None)
| 88 | torch.save(states, os.path.join(output_dir, 'checkpoint_best.pth')) |
| 89 | |
| 90 | def random_click(mask, point_labels = 1, seed=None): |
| 91 | # check if all masks are black |
| 92 | max_label = max(set(mask.flatten())) |
| 93 | if max_label == 0: |
| 94 | point_labels = max_label |
| 95 | # max agreement position |
| 96 | indices = np.argwhere(mask == max_label) |
| 97 | # return point_labels, indices[np.random.randint(len(indices))] |
| 98 | if seed is not None: |
| 99 | rand_instance = random.Random(seed) |
| 100 | rand_num = rand_instance.randint(0, len(indices) - 1) |
| 101 | else: |
| 102 | rand_num = random.randint(0, len(indices) - 1) |
| 103 | output_index_1 = indices[rand_num][0] |
| 104 | output_index_0 = indices[rand_num][1] |
| 105 | return point_labels, np.array([output_index_0, output_index_1]) |
| 106 | |
| 107 | def generate_bbox(mask, variation=0, seed=None): |
| 108 | if seed is not None: |
no outgoing calls
no test coverage detected