| 79 | self.random_erasing = None |
| 80 | |
| 81 | def __iter__(self): |
| 82 | stream = torch.cuda.Stream() |
| 83 | first = True |
| 84 | |
| 85 | for next_input, next_target in self.loader: |
| 86 | with torch.cuda.stream(stream): |
| 87 | next_input = next_input.cuda(non_blocking=True) |
| 88 | next_target = next_target.cuda(non_blocking=True) |
| 89 | if self.fp16: |
| 90 | next_input = next_input.half().sub_(self.mean).div_(self.std) |
| 91 | else: |
| 92 | next_input = next_input.float().sub_(self.mean).div_(self.std) |
| 93 | if self.random_erasing is not None: |
| 94 | next_input = self.random_erasing(next_input) |
| 95 | |
| 96 | if not first: |
| 97 | yield input, target |
| 98 | else: |
| 99 | first = False |
| 100 | |
| 101 | torch.cuda.current_stream().wait_stream(stream) |
| 102 | input = next_input |
| 103 | target = next_target |
| 104 | |
| 105 | yield input, target |
| 106 | |
| 107 | def __len__(self): |
| 108 | return len(self.loader) |