Skip to content
Snippets Groups Projects
Commit 2ac1b506 authored by Frisinghelli Daniel's avatar Frisinghelli Daniel
Browse files

Removed cval kwarg: is now set automatically

parent 391743ad
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ import csv ...@@ -18,6 +18,7 @@ import csv
import glob import glob
import enum import enum
import itertools import itertools
import logging
# externals # externals
import numpy as np import numpy as np
...@@ -30,6 +31,9 @@ from pysegcnn.core.constants import (Landsat8, Sentinel2, Label, SparcsLabels, ...@@ -30,6 +31,9 @@ from pysegcnn.core.constants import (Landsat8, Sentinel2, Label, SparcsLabels,
from pysegcnn.core.utils import (img2np, is_divisible, tile_topleft_corner, from pysegcnn.core.utils import (img2np, is_divisible, tile_topleft_corner,
parse_landsat_scene, parse_sentinel2_scene) parse_landsat_scene, parse_sentinel2_scene)
# module level logger
LOGGER = logging.getLogger(__name__)
# generic image dataset class # generic image dataset class
class ImageDataset(Dataset): class ImageDataset(Dataset):
...@@ -60,10 +64,7 @@ class ImageDataset(Dataset): ...@@ -60,10 +64,7 @@ class ImageDataset(Dataset):
# whether to pad the image to be evenly divisible in square tiles # whether to pad the image to be evenly divisible in square tiles
# of size (tile_size x tile_size) # of size (tile_size x tile_size)
'pad': False, 'pad': False
# the value to pad the samples
'cval': 0,
} }
...@@ -130,25 +131,12 @@ class ImageDataset(Dataset): ...@@ -130,25 +131,12 @@ class ImageDataset(Dataset):
# always use the original dataset together with the augmentations # always use the original dataset together with the augmentations
self.transforms = [None] + self.transforms self.transforms = [None] + self.transforms
# check if the padding value is equal to any of the class # when padding, add a new "no data" label to the ground truth
# identifiers in the ground truth mask
if self.pad and sum(self.padding) > 0: if self.pad and sum(self.padding) > 0:
if self.cval in self.labels.keys(): self.cval = max(self.labels) + 1
raise ValueError('Constant padding value cval={} is not ' self.labels[self.cval] = {'label': 'No data', 'color': 'black'}
'allowed: class "{}" is represented as {} in ' LOGGER.info('Adding label "No data" with value={} to ground truth.'
'the ground truth.' .format(self.cval))
.format(self.cval,
self.labels[self.cval]['label'],
self.cval)
)
# add the "no data" label to the class labels of the ground truth
else:
if not 0 <= self.cval <= 255:
raise ValueError('Expecting 0 <= cval <= 255, got cval={}.'
.format(self.cval))
print('Adding label "No data" with value={} to ground truth.'
.format(self.cval))
self.labels[self.cval] = {'label': 'No data', 'color': 'black'}
def _build_labels(self): def _build_labels(self):
return {band.id: {'label': band.name.replace('_', ' '), return {band.id: {'label': band.name.replace('_', ' '),
...@@ -446,9 +434,9 @@ class StandardEoDataset(ImageDataset): ...@@ -446,9 +434,9 @@ class StandardEoDataset(ImageDataset):
gt = gt.pop() gt = gt.pop()
except IndexError: except IndexError:
print('Skipping scene {}: ground truth not available ' LOGGER.info('Skipping scene {}: ground truth not available'
'(pattern = {}).' ' (pattern = {}).'.format(scene['id'],
.format(scene['id'], self.gt_pattern)) self.gt_pattern))
continue continue
# iterate over the tiles # iterate over the tiles
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment