To ease the accessibility of data based on the class, we will use `group_examples` to group examples based on class. Every key in `grouped_examples` corresponds to a class in MNIST dataset. For every key in `grouped_examples`, every va
(self)
| 95 | self.group_examples() |
| 96 | |
| 97 | def group_examples(self): |
| 98 | """ |
| 99 | To ease the accessibility of data based on the class, we will use `group_examples` to group |
| 100 | examples based on class. |
| 101 | |
| 102 | Every key in `grouped_examples` corresponds to a class in MNIST dataset. For every key in |
| 103 | `grouped_examples`, every value will conform to all of the indices for the MNIST |
| 104 | dataset examples that correspond to that key. |
| 105 | """ |
| 106 | |
| 107 | # get the targets from MNIST dataset |
| 108 | np_arr = np.array(self.dataset.targets.clone(), dtype=None, copy=None) |
| 109 | |
| 110 | # group examples based on class |
| 111 | self.grouped_examples = {} |
| 112 | for i in range(0,10): |
| 113 | self.grouped_examples[i] = np.where((np_arr==i))[0] |
| 114 | |
| 115 | def __len__(self): |
| 116 | return self.data.shape[0] |