Ejemplo n.º 1
0
def read_flo(file: BinaryIO) -> torch.Tensor:
    if file.read(4) != b"PIEH":
        raise ValueError("Magic number incorrect. Invalid .flo file")

    width, height = fromfile(file,
                             dtype=torch.int32,
                             byte_order="little",
                             count=2)
    flow = fromfile(file,
                    dtype=torch.float32,
                    byte_order="little",
                    count=height * width * 2)
    return flow.reshape((height, width, 2)).permute((2, 0, 1))
Ejemplo n.º 2
0
 def from_file(cls: Type[D], file: BinaryIO, **kwargs: Any) -> D:
     return cls(fromfile(file, dtype=torch.uint8, byte_order=sys.byteorder), **kwargs)