Exemplo n.º 1
0
 def __init__(self,
              datapipe: Iterable[Tuple[str, BufferedIOBase]],
              *,
              handlers: Union[None, List[Callable]] = None,
              length: int = -1):
     super().__init__()
     self.datapipe: Iterable[Tuple[str, BufferedIOBase]] = datapipe
     if handlers:
         self.decoder = Decoder(handlers)
     else:
         self.decoder = Decoder(
             [decoder_basichandlers,
              decoder_imagehandler('torch')])
     self.length: int = length
Exemplo n.º 2
0
 def __init__(self,
              datapipe: Iterable[Tuple[str, BufferedIOBase]],
              *handlers: Callable,
              key_fn: Callable = extension_extract_fn) -> None:
     super().__init__()
     self.datapipe: Iterable[Tuple[str, BufferedIOBase]] = datapipe
     if not handlers:
         handlers = (decoder_basichandlers, decoder_imagehandler('torch'))
     self.decoder = Decoder(*handlers, key_fn=key_fn)
Exemplo n.º 3
0
 def __init__(self,
              datapipe: Iterable[Tuple[str, BufferedIOBase]],
              *handlers: Callable,
              key_fn: Callable = extension_extract_fn) -> None:
     super().__init__()
     self.datapipe: Iterable[Tuple[str, BufferedIOBase]] = datapipe
     if not handlers:
         handlers = (decoder_basichandlers, decoder_imagehandler('torch'))
     self.decoder = Decoder(*handlers, key_fn=key_fn)
     _deprecation_warning(
         type(self).__name__,
         deprecation_version="1.12",
         removal_version="1.13",
         old_functional_name="routed_decode",
     )
Exemplo n.º 4
0
    def __init__(
        self,
        root: Union[str, pathlib.Path],
        *,
        year: str = "2012",
        split: str = "train",
        target_type: str = "detection",  # segmentation
        decoder: Optional[str] = "pil",
    ):
        self.target_type = target_type
        self.decoder = Decoder([imagehandler(decoder)]) if decoder else None

        root = pathlib.Path(root).resolve()
        # TODO: make this variable based on the input
        archive = "VOCtrainval_11-May-2012.tar"

        split_folder = SPLIT_FOLDER[target_type]
        target_type_folder = TARGET_TYPE_FOLDER[target_type]

        datapipe = (str(root / archive), )
        datapipe = dp.iter.LoadFilesFromDisk(datapipe)
        datapipe = dp.iter.ReadFilesFromTar(datapipe)

        split_files: Dict[str, Tuple[str, io.BufferedIOBase]] = {}
        self.images: Dict[str, Tuple[str, io.BufferedIOBase]] = {}
        self.targets: Dict[str, Tuple[str, io.BufferedIOBase]] = {}

        for data in datapipe:
            parent_ = pathlib.Path(data[0]).parent
            parent = parent_.name
            grand_parent = parent_.parent.name

            if grand_parent == "ImageSets" and parent == split_folder:
                dct = split_files
            elif parent == "JPEGImages":
                dct = self.images
            elif parent == target_type_folder:
                dct = self.targets
            else:
                continue

            dct[self._data_to_key(data)] = data

        self.keys = ReadLineFromFile((split_files[split], ))