Exemple #1
0
    def __init__(self,
                 labels,
                 dataset,
                 ids,
                 rasters,
                 patches,
                 use_rasters=True):
        """
        :param labels: list of labels
        :param dataset: list of (latitude, longitude)
        :param ids: list of identifiers
        :param rasters: path to the rasters root
        :param patches: path to the patches root
        """
        self.labels = labels
        self.dataset = dataset
        self.ids = ids

        self.one_hot_size = 34
        self.one_hot = np.eye(self.one_hot_size)

        self.rasters = rasters

        self.patches = patches
        global patch_extractor
        if patch_extractor is None and rasters is not None and use_rasters:
            # 256 is mandatory as images have been extracted in 256 and will be stacked in the __getitem__ method
            patch_extractor = PatchExtractor(rasters, size=256, verbose=True)
            patch_extractor.add_all()

        self.extractor = patch_extractor
        return len(self.labels)

    def __getitem__(self, idx):
        tensor = self.extractor[self.dataset[idx]]
        return torch.from_numpy(tensor).float(), self.labels[idx]


if __name__ == '__main__':
    patch_extractor = PatchExtractor(
        '/Users/ykarmim/Documents/Cours/Master/Projet_DAC/geoLifeClef/data/rasters_GLC19',
        size=64,
        verbose=True)

    #patch_extractor.append('proxi_eau_fast')
    #patch_extractor.append('text')
    patch_extractor.add_all()

    # example of dataset
    dataset_list = [(43.61, 3.88), (42.61, 4.88), (46.15, -1.1), (49.54, -1.7)]
    labels_list = [0, 1, 0, 1]

    dataset_pytorch = GeoLifeClefDataset(patch_extractor, dataset_list,
                                         labels_list)

    print(len(dataset_pytorch), 'elements in the dataset')

    # dataset_pytorch can now be used in a data_loader
    data_loader = torch.utils.data.DataLoader(dataset_pytorch,
                                              shuffle=True,
                                              batch_size=2)
Exemple #3
0
from environmental_raster_glc import PatchExtractor

extractor = PatchExtractor(
    '/Users/ykarmim/Documents/Cours/Master/Projet_DAC/geoLifeClef/data/rasters_GLC19',
    size=64,
    verbose=True)

#extractor.append('proxi_eau_fast')
# extractor.append('text')
# extractor.append('clc')
# extractor.append('bs_top')
# extractor.append('oc_top')

extractor.add_all()

extractor.plot((43.61, 3.88))