def __getitem__(self, idx): name = self.img_name_list[idx] name_str = decode_int_filename(name) img = imageio.imread(get_img_path(name_str, self.voc12_root)) ms_img_list = [] for s in self.scales: if s == 1: s_img = img else: s_img = imutils.pil_rescale(img, s, order=3) s_img = self.img_normal(s_img) s_img = imutils.HWC_to_CHW(s_img) ms_img_list.append(np.stack([s_img, np.flip(s_img, -1)], axis=0)) if len(self.scales) == 1: ms_img_list = ms_img_list[0] out = { "name": name_str, "img": ms_img_list, "size": (img.shape[0], img.shape[1]), "label": torch.from_numpy(self.label_list[idx]) } return out
def __getitem__(self, idx): name = self.img_name_list[idx] name_str = decode_int_filename(name) img = imageio.imread(get_img_path(name_str, self.voc12_root)) label = imageio.imread(os.path.join(self.label_dir, name_str + '.png')) img = np.asarray(img) if self.rescale: img, label = imutils.random_scale((img, label), scale_range=self.rescale, order=(3, 0)) if self.img_normal: img = self.img_normal(img) if self.hor_flip: img, label = imutils.random_lr_flip((img, label)) if self.crop_method == "random": img, label = imutils.random_crop((img, label), self.crop_size, (0, 255)) else: img = imutils.top_left_crop(img, self.crop_size, 0) label = imutils.top_left_crop(label, self.crop_size, 255) img = imutils.HWC_to_CHW(img) return {'name': name, 'img': img, 'label': label}
def __getitem__(self, idx): name = self.img_name_list[idx] name_str = decode_int_filename(name) img = np.asarray( imageio.imread(get_img_path(name_str, self.voc12_root))) if self.resize_long: img = imutils.random_resize_long(img, self.resize_long[0], self.resize_long[1]) if self.rescale: img = imutils.random_scale(img, scale_range=self.rescale, order=3) if self.img_normal: img = self.img_normal(img) if self.hor_flip: img = imutils.random_lr_flip(img) if self.crop_size: if self.crop_method == "random": img = imutils.random_crop(img, self.crop_size, 0) else: img = imutils.top_left_crop(img, self.crop_size, 0) if self.to_torch: img = imutils.HWC_to_CHW(img) return {'name': name_str, 'img': img}