Split camera (b, q) into a list of cameras (b', q'), such that b' * q' * h * w < chunk_size. Note that we only chunk q or chunk b Returns: list of cameras
(self, chunk_size: int)
| 1863 | ) |
| 1864 | |
| 1865 | def split(self, chunk_size: int) -> T.List['Camera']: |
| 1866 | """ |
| 1867 | Split camera (b, q) into a list of cameras (b', q'), |
| 1868 | such that b' * q' * h * w < chunk_size. |
| 1869 | |
| 1870 | Note that we only chunk q or chunk b |
| 1871 | |
| 1872 | Returns: |
| 1873 | list of cameras |
| 1874 | """ |
| 1875 | if chunk_size < 0: |
| 1876 | return [self] |
| 1877 | |
| 1878 | hw = self.width_px * self.height_px |
| 1879 | N = max(1, int(chunk_size / hw)) # max bq for each chunk |
| 1880 | q = self.H_c2w.size(1) |
| 1881 | b = self.H_c2w.size(0) |
| 1882 | |
| 1883 | if N >= b * q: |
| 1884 | return [self] |
| 1885 | elif N > q: |
| 1886 | # chunk b |
| 1887 | chunk_dim = 0 |
| 1888 | chunks = math.ceil(b / int(N / q)) |
| 1889 | |
| 1890 | H_c2w_list = torch.chunk(self.H_c2w, chunks=chunks, dim=chunk_dim) |
| 1891 | intrinsic_list = torch.chunk(self.intrinsic, chunks=chunks, dim=chunk_dim) |
| 1892 | |
| 1893 | cameras = [] |
| 1894 | for H, ins in zip(H_c2w_list, intrinsic_list): |
| 1895 | cameras.append( |
| 1896 | Camera( |
| 1897 | H_c2w=H, |
| 1898 | intrinsic=ins, |
| 1899 | width_px=self.width_px, |
| 1900 | height_px=self.height_px, |
| 1901 | ) |
| 1902 | ) |
| 1903 | return cameras |
| 1904 | else: |
| 1905 | # chunk b and q |
| 1906 | cameras = [] |
| 1907 | for ib in range(b): |
| 1908 | chunk_dim = 1 |
| 1909 | chunks = math.ceil(q / N) |
| 1910 | H_c2w_list = torch.chunk(self.H_c2w[ib:ib + 1], chunks=chunks, dim=chunk_dim) |
| 1911 | intrinsic_list = torch.chunk(self.intrinsic[ib:ib + 1], chunks=chunks, dim=chunk_dim) |
| 1912 | for H, ins in zip(H_c2w_list, intrinsic_list): |
| 1913 | cameras.append( |
| 1914 | Camera( |
| 1915 | H_c2w=H, |
| 1916 | intrinsic=ins, |
| 1917 | width_px=self.width_px, |
| 1918 | height_px=self.height_px, |
| 1919 | ) |
| 1920 | ) |
| 1921 | return cameras |
| 1922 |
no test coverage detected