def __getitem__(self, idx):
    path = self.paths[idx]
    if self.conf.grayscale:
        mode = cv2.IMREAD_GRAYSCALE
    else:
        mode = cv2.IMREAD_COLOR
    image = cv2.imread(str((self.root / path)), mode)
    if (not self.conf.grayscale):
        image = image[:, :, ::(- 1)]
    if (image is None):
        raise ValueError(f'Cannot read image {str(path)}.')
    image = image.astype(np.float32)
    size = image.shape[:2][::(- 1)]
    (w, h) = size
    if (self.conf.resize_max and (max(w, h) > self.conf.resize_max)):
        scale = (self.conf.resize_max / max(h, w))
        (h_new, w_new) = (int(round((h * scale))), int(round((w * scale))))
        image = cv2.resize(image, (w_new, h_new), interpolation=cv2.INTER_LINEAR)
    if self.conf.grayscale:
        image = image[None]
    else:
        image = image.transpose((2, 0, 1))
    image = (image / 255.0)
    data = {'name': path.as_posix(), 'image': image, 'original_size': np.array(size)}
    return data
def __getitem__(self, idx):
    path = self.paths[idx]
    if self.conf.grayscale:
        mode = cv2.IMREAD_GRAYSCALE
    else:
        mode = cv2.IMREAD_COLOR
    image = cv2.imread(str((self.root / path)), mode)
    if (not self.conf.grayscale):
        image = image[:, :, ::(- 1)]
    if (image is None):
        raise ValueError(f'Cannot read image {str(path)}.')
    image = image.astype(np.float32)
    size = image.shape[:2][::(- 1)]
    (w, h) = size
    if (self.conf.resize_max and (max(w, h) > self.conf.resize_max)):
        scale = (self.conf.resize_max / max(h, w))
        (h_new, w_new) = (int(round((h * scale))), int(round((w * scale))))
        image = cv2.resize(image, (w_new, h_new), interpolation=cv2.INTER_LINEAR)
    if self.conf.grayscale:
        image = image[None]
    else:
        image = image.transpose((2, 0, 1))
    image = (image / 255.0)
    data = {'name': path.as_posix(), 'image': image, 'original_size': np.array(size)}
    return data