| 11 | |
| 12 | |
| 13 | class Transform: |
| 14 | def __init__(self, split): |
| 15 | self.totensor = transforms.ToTensor() |
| 16 | self.resize = transforms.Resize((256, 256)) |
| 17 | self.split = split |
| 18 | |
| 19 | def __call__(self, img, label): |
| 20 | img = self.totensor(img.copy()) |
| 21 | label = self.totensor(label.copy()) |
| 22 | |
| 23 | if self.split != "train": |
| 24 | return img.permute(1, 2, 0).float(), label.squeeze(0).int() |
| 25 | |
| 26 | crop = transforms.RandomResizedCrop(256) |
| 27 | params = crop.get_params(img, scale=(0.08, 1.0), ratio=(0.75, 1.33)) |
| 28 | img = TF.crop(img, *params) |
| 29 | label = TF.crop(label, *params) |
| 30 | |
| 31 | if np.random.random() > 0.5: |
| 32 | img = TF.hflip(img) |
| 33 | label = TF.hflip(label) |
| 34 | |
| 35 | if np.random.random() > 0.5: |
| 36 | img = TF.vflip(img) |
| 37 | label = TF.vflip(label) |
| 38 | |
| 39 | img = self.resize(img) |
| 40 | label = cv2.resize( |
| 41 | label.squeeze(0).numpy(), dsize=(256, 256), interpolation=cv2.INTER_NEAREST |
| 42 | ) # Resize provided by pytorch will have some random noise |
| 43 | # return img.permute(1, 2, 0).float(), label.squeeze(0).int() |
| 44 | return img.permute(1, 2, 0).float(), label |
| 45 | |
| 46 | |
| 47 | class MultiTempV2XSimSeg(V2XSimSeg): |
nothing calls this directly
no outgoing calls
no test coverage detected