| 199 | def _train_with_module(iter_num=3, data=None): |
| 200 | class DataModule(flow.nn.Module): |
| 201 | def __init__(self, data): |
| 202 | super().__init__() |
| 203 | self.data_list = [] |
| 204 | self.idx = 0 |
| 205 | for pair in data: |
| 206 | for i in range(4): |
| 207 | s = i * 4 |
| 208 | e = s + 4 |
| 209 | micro_batch_image = pair[0][s:e] |
| 210 | micro_batch_label = pair[1][s:e] |
| 211 | self.data_list.append( |
| 212 | ( |
| 213 | flow.Tensor(micro_batch_image).to("cuda:3"), |
| 214 | flow.Tensor(micro_batch_label).to("cuda:3"), |
| 215 | ) |
| 216 | ) |
| 217 | |
| 218 | def forward(self): |
| 219 | image = self.data_list[self.idx][0] |