def get_raw_data(self, i, rgb=True): cur_paths = self.paths[self.keys[i]] src = read_image_as_array(cur_paths['src_img']) dst = read_image_as_array(cur_paths['dst_img']) flow = self._read_flow_sintel(cur_paths['flow']) if not rgb: src = src[:, :, ::-1] dst = dst[:, :, ::-1] return src, dst, flow
def get_raw_data(self, i, rgb=True): """Returns the i-th example. This returns a color image and its label. The image is in HWC foramt. Args: i (int): The index of the example. rgb (bool): If false, the returned image will be in BGR. Returns: i-th example (image, label) """ img = utils.read_image_as_array( osp.join(self.data_dir, 'images', self.fns[i])) # RGB if img.ndim == 2: img = utils.gray2rgb(img) if not rgb: img = img[:, :, ::-1] if self.crop_bbox: bbox = self.bboxes[i] # (x, y, width, height) img = img[bbox[1]:bbox[1] + bbox[3], bbox[0]:bbox[0] + bbox[2]] label = self._data_labels[i] return img, label
def get_example(self, i): """Returns the i-th example. Returns a color image and bounding boxes. The image is in CHW format. The returned image is BGR. Args: i (int): The index of the example. Returns: tuple of an image and bounding boxes """ # Load a bbox and its category objects = self.objects[self.keys[i]] bbox = [] for obj in objects: _bb = obj['bbox'] name = obj['name'] label_id = self.labels.index(name) bbox_elem = np.asarray([_bb[0], _bb[1], _bb[2], _bb[3], label_id], dtype=np.float32) bbox.append(bbox_elem) bbox = np.stack(bbox) # Load a image img_file = os.path.join(self.data_dir, 'JPEGImages', obj['filename']) img = read_image_as_array(img_file) # RGB img = img[:, :, ::-1] # RGB to BGR img = img.transpose(2, 0, 1).astype(np.float32) return img, bbox
def get_example(self, i): """Returns the i-th example. Returns a color image and a label image. Both of them are in CHW format. Args: i (int): The index of the example. Returns: tuple of color image and label whose shapes are (3, H, W) and (1, H, W) respectively. H and W are height and width of the images. The dtype of the color image is :obj:`numpy.float32` and the dtype of the label image is :obj:`numpy.int32`. """ if i >= len(self): raise IndexError('index is too large') img_file = osp.join(self.data_dir, 'JPEGImages', self.ids[i] + '.jpg') img = read_image_as_array(img_file) label = self._load_label(self.data_dir, self.ids[i]) img = img[:, :, ::-1] # RGB to BGR img = img.transpose(2, 0, 1).astype(np.float32) label = label[None] return img, label
def get_example(self, i): """Returns the i-th example. Returns a color image and bounding boxes. The image is in CHW format. If `self.bgr` is True, the image is in BGR. If not, it is in RGB. Args: i (int): The index of the example. Returns: tuple of an image and its label. """ img = utils.read_image_as_array( osp.join(self.data_dir, 'images', self.fns[i])) # RGB if img.ndim == 2: img = utils.gray2rgb(img) if self.crop_bbox: bbox = self.bboxes[i] # (x, y, width, height) img = img[bbox[1]:bbox[1] + bbox[3], bbox[0]:bbox[0] + bbox[2]] label = self._data_labels[i] img = img[:, :, ::-1] # RGB to BGR img = img.transpose(2, 0, 1) return img, label
def get_raw_data(self, i, rgb=True): """Returns the i-th example. This returns a color image and bounding boxes. The color image has shape (H, W, 3). Args: i (int): The index of the example. rgb (bool): If false, the returned image will be in BGR. Returns: i-th example (image, bbox) """ # Load a bbox and its category objects = self.objects[self.keys[i]] bboxes = [] for obj in objects: bbox = obj['bbox'] name = obj['name'] label_id = self.labels.index(name) bbox = np.asarray([bbox[0], bbox[1], bbox[2], bbox[3], label_id], dtype=np.float32) bboxes.append(bbox) bboxes = np.stack(bboxes) # Load a image img_file = os.path.join(self.data_dir, 'JPEGImages', obj['filename']) img = read_image_as_array(img_file) # RGB if not rgb: img = img[:, :, ::-1] return img, bboxes
def get_raw_data(self, i, rgb=True): # this i is transformed to id for the entire dataset original_idx = self.selected_ids[i] img = read_image_as_array(osp.join( self.data_dir, 'images', self.fns[original_idx])) # RGB keypoints = self.keypoints_dict[original_idx] keypoints = np.array(keypoints, dtype=np.float32) if self.crop_bbox: bbox = self.bboxes[original_idx] # (x, y, width, height) img = img[bbox[1]: bbox[1] + bbox[3], bbox[0]: bbox[0] + bbox[2]] keypoints[:, :2] = keypoints[:, :2] - np.array([bbox[0], bbox[1]]) if not rgb: img = img[:, :, ::-1] return img, keypoints
def get_raw_data(self, i, rgb=True): """Returns the i-th example's images in HWC format. This returns a color image and its label. The image is in HWC foramt. Args: i (int): The index of the example. rgb (bool): If false, the returned image will be in BGR. Returns: i-th example (image, label image) """ img_file = osp.join(self.data_dir, 'JPEGImages', self.ids[i] + '.jpg') img = read_image_as_array(img_file) if not rgb: img = img[:, :, ::-1] label = self._load_label(self.data_dir, self.ids[i]) return img, label
def get_example(self, i): """Returns the i-th example. Returns a color image, class_id. The image is in CHW format. The returned image is BGR. Args: i (int): The index of the example. Returns: i-th example """ img = read_image_as_array(self.fns[i]) if img.ndim == 2: img = img[:, :, np.newaxis] img = img[:, :, ::-1] # BGR to RGB img = img.transpose(2, 0, 1).astype(np.float32) label = self.labels[i] return img, label
def get_raw_data(self, i, rgb=True): """Returns the i-th example's image and class data in HWC format. The color image that is returned is RGB. Args: i (int): The index of the example. rgb (bool): If false, the returned image will be in BGR. Returns: i-th example (image, class_id, super_class_id) """ img = utils.read_image_as_array(self.paths[i]) if img.ndim == 2: img = utils.gray2rgb(img) if not rgb: img = img[:, :, ::-1] class_id = self.class_ids[i] super_class_id = self.super_class_ids[i] return img, class_id, super_class_id
def get_raw_data(self, i, rgb=True): """Returns the i-th example. This returns a color image and its label. The image is in HWC foramt. Args: i (int): The index of the example. rgb (bool): If false, the returned image will be in BGR. Returns: i-th example (image, label) """ img = read_image_as_array(self.fns[i]) if img.ndim == 2: img = img[:, :, np.newaxis] if not rgb: img = img[:, :, ::-1] label = self.labels[i] return img, label
def get_by_class(self, class_id, i): """Returns the i-th example from the given class Note that the class_id starts from 1. The returned image is BGR. Args: class_id (int): The retrieved images will be in this class. i (int): The index of the example in the given class. Returns: i-th example from the given class. """ img = read_image_as_array(self.fns_dict[class_id][i]) if img.ndim == 2: img = img[:, :, np.newaxis] img = img[:, :, ::-1] # BGR to RGB img = img.transpose(2, 0, 1).astype(np.float32) return img
def get_example(self, i): """Returns the i-th example. Returns a color image, class_id and super_class_id. The image is in CHW format. The returned image is BGR. Args: i (int): The index of the example. Returns: i-th example """ class_id = np.array(self.class_ids[i], np.int32) super_class_id = np.array(self.super_class_ids[i], np.int32) img = utils.read_image_as_array(self.paths[i]) if img.ndim == 2: img = utils.gray2rgb(img) img = img[:, :, ::-1] # RGB to BGR img = img.transpose(2, 0, 1).astype(np.float32) return img, class_id, super_class_id