def __init__(self, **kwargs): """ the parent __init__ method automatically populates this instance with attributes from the form """ super(DataIngestion, self).__init__(**kwargs) self.random_indices = None if not 'seed' in self.userdata: # choose random seed and add to userdata so it gets persisted self.userdata['seed'] = random.randint(0, 1000) random.seed(self.userdata['seed']) # open first image in label folder to retrieve palette # all label images must use the same palette - this is enforced # during dataset creation filename = self.make_image_list(self.label_folder)[0] image = self.load_label(filename) self.userdata[COLOR_PALETTE_ATTRIBUTE] = image.getpalette() # get labels if those were provided if self.class_labels_file: with open(self.class_labels_file) as f: self.userdata['class_labels'] = f.read().splitlines()
def __init__(self, **kwargs): """ the parent __init__ method automatically populates this instance with attributes from the form """ super(DataIngestion, self).__init__(**kwargs) self.random_indices = None if 'seed' not in self.userdata: # choose random seed and add to userdata so it gets persisted self.userdata['seed'] = random.randint(0, 1000) if 'colormap_method' not in self.userdata: self.userdata['colormap_method'] = 'label' random.seed(self.userdata['seed']) if self.userdata['colormap_method'] == "label": # open first image in label folder to retrieve palette # all label images must use the same palette - this is enforced # during dataset creation filename = self.text_image_list('label_file')[0] image = self.load_label(filename) self.userdata[COLOR_PALETTE_ATTRIBUTE] = image.getpalette() else: # read colormap from file with open(self.colormap_text_file) as f: palette = [] lines = f.read().splitlines() for line in lines: for val in line.split(): try: palette.append(int(val)) except: raise ValueError("Your color map file seems to " "be badly formatted: '%s' is not " "an integer" % val) # fill rest with zeros palette = palette + [0] * (256 * 3 - len(palette)) self.userdata[COLOR_PALETTE_ATTRIBUTE] = palette self.palette_img = PIL.Image.new("P", (1, 1)) self.palette_img.putpalette(palette) # get labels if those were provided if self.class_labels_file: with open(self.class_labels_file) as f: self.userdata['class_labels'] = f.read().splitlines()
def __init__(self, **kwargs): """ the parent __init__ method automatically populates this instance with attributes from the form """ super(DataIngestion, self).__init__(**kwargs) self.random_indices = None if 'seed' not in self.userdata: # choose random seed and add to userdata so it gets persisted self.userdata['seed'] = random.randint(0, 1000) if 'colormap_method' not in self.userdata: self.userdata['colormap_method'] = 'label' random.seed(self.userdata['seed']) if self.userdata['colormap_method'] == "label": # open first image in label folder to retrieve palette # all label images must use the same palette - this is enforced # during dataset creation filename = self.make_image_list(self.label_folder)[0] image = self.load_label(filename) self.userdata[COLOR_PALETTE_ATTRIBUTE] = image.getpalette() else: # read colormap from file with open(self.colormap_text_file) as f: palette = [] lines = f.read().splitlines() for line in lines: for val in line.split(): try: palette.append(int(val)) except: raise ValueError("Your color map file seems to " "be badly formatted: '%s' is not " "an integer" % val) # fill rest with zeros palette = palette + [0] * (256 * 3 - len(palette)) self.userdata[COLOR_PALETTE_ATTRIBUTE] = palette self.palette_img = PIL.Image.new("P", (1, 1)) self.palette_img.putpalette(palette) # get labels if those were provided if self.class_labels_file: with open(self.class_labels_file) as f: self.userdata['class_labels'] = f.read().splitlines()