| 12 | |
| 13 | |
| 14 | class SitsDataset(Dataset): |
| 15 | def __init__(self, |
| 16 | path, |
| 17 | split, |
| 18 | domain_shift, |
| 19 | num_channels, |
| 20 | num_classes, |
| 21 | img_size, |
| 22 | true_size, |
| 23 | train_length): |
| 24 | super(SitsDataset, self).__init__() |
| 25 | self.path = path |
| 26 | self.image_folder, self.gt_folder = join(path, split if domain_shift else 'train'), join(path, 'labels') |
| 27 | self.split = split |
| 28 | self.domain_shift = domain_shift |
| 29 | self.num_channels = num_channels |
| 30 | self.num_classes = num_classes |
| 31 | self.img_size = img_size |
| 32 | self.true_size = true_size |
| 33 | self.train_length = train_length |
| 34 | self.monthly_dates = get_monthly_dates_dict() |
| 35 | self.gt, self.sits_ids = self.load_ground_truth(split) |
| 36 | self.collate_fn = collate_fn |
| 37 | self.mean, self.std, self.month_list = None, None, None # Needs to be defined in subclass |
| 38 | |
| 39 | def __len__(self): |
| 40 | if self.split == 'train': |
| 41 | return len(self.sits_ids) * ((self.true_size // self.img_size) ** 2 - 4) |
| 42 | elif self.domain_shift: |
| 43 | return len(self.sits_ids) * (self.true_size // self.img_size) ** 2 |
| 44 | else: |
| 45 | return len(self.sits_ids) * 2 |
| 46 | |
| 47 | def __getitem__(self, i): |
| 48 | """Returns an item from the dataset. |
| 49 | Args: |
| 50 | i (int): index of the item |
| 51 | Returns: |
| 52 | dict: dictionary with keys "data", "gt", "positions", "idx" |
| 53 | Shapes: |
| 54 | data: T x C x H x W |
| 55 | gt: T x H x W |
| 56 | positions: T |
| 57 | idx: 1 |
| 58 | """ |
| 59 | if self.split == 'train': |
| 60 | num_patches_per_sits = (self.true_size // self.img_size) ** 2 - 4 |
| 61 | sits_number = i // num_patches_per_sits |
| 62 | patch_loc_i, patch_loc_j = None, None |
| 63 | months = self.get_random_months(sits_number) |
| 64 | elif self.domain_shift: |
| 65 | num_patches_per_sits = (self.true_size // self.img_size) ** 2 |
| 66 | sits_number = i // num_patches_per_sits |
| 67 | patch_loc_i = (i % num_patches_per_sits) // (self.true_size // self.img_size) |
| 68 | patch_loc_j = (i % num_patches_per_sits) % (self.true_size // self.img_size) |
| 69 | months = list(range(24)) |
| 70 | else: |
| 71 | num_patches_per_sits = 2 |
nothing calls this directly
no outgoing calls
no test coverage detected