@@ -0,0 +1,1596 @@
+# -*- coding: utf-8 -*-%0A# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved%0A%0Aimport logging%0Aimport numpy as np%0Afrom typing import Callable, List, Optional%0Aimport torch%0Afrom torch.utils.data.dataset import Dataset%0A%0Afrom detectron2.data.detection_utils import read_image%0A%0AImageTransform = Callable%5B%5Btorch.Tensor%5D, torch.Tensor%5D%0A%0A%0Aclass ImageListDataset(Dataset):%0A    %22%22%22%0A    Dataset that provides images from a list.%0A    %22%22%22%0A%0A    _EMPTY_IMAGE = torch.empty((1, 1, 3))%0A%0A    def __init__(self, image_list: List%5Bstr%5D, transform: Optional%5BImageTransform%5D = None):%0A        %22%22%22%0A        Args:%0A            image_list (List%5Bstr%5D): list of paths to image files%0A        %22%22%22%0A        self.image_list = image_list%0A        self.transform = transform%0A%0A    def __getitem__(self, idx: int) -%3E torch.Tensor:%0A        %22%22%22%0A        Gets selected images from the list%0A%0A        Args:%0A            idx (int): video index in the video list file%0A        Returns:%0A            image (torch.Tensor): tensor of size %5BH, W, 3%5D%0A        %22%22%22%0A        fpath = self.image_list%5Bidx%5D%0A%0A        try:%0A            image = torch.from_numpy(np.ascontiguousarray(read_image(fpath, format=%22BGR%22)))%0A            if self.transform is not None:%0A                image = self.transform(image.unsqueeze(0))%5B0%5D  # Transforms are done on batches%0A            return image%0A        except (OSError, RuntimeError) as e:%0A            logger = logging.getLogger(__name__)%0A            logger.warning(f%22Error opening image file container %7Bfpath%7D: %7Be%7D%22)%0A%0A        return self._EMPTY_IMAGE%0A%0A    def __len__(self):%0A        return len(self.image_list)%0A

Add ImageList Dataset