Skip to content

c2e & e2c batch support #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions pytorch360convert/pytorch360convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,25 +740,33 @@ def c2e(
NotImplementedError: If an unknown cube_format is provided.
"""

if cube_format == "stack":
assert (
isinstance(cubemap, torch.Tensor)
and len(cubemap.shape) == 4
and cubemap.shape[0] == 6
)
cubemap = [cubemap[i] for i in range(cubemap.shape[0])]
if cubemap[0].dim() == 4 or cubemap[0].dim() == 5:
if cubemap[0].dim() == 4:
assert (
isinstance(cubemap, torch.Tensor)
and len(cubemap.shape) == 4
and cubemap.shape[0] == 6
)
cubemap = [cubemap[i] for i in range(cubemap.shape[0])]
else:
assert (
isinstance(cubemap, torch.Tensor)
and len(cubemap.shape) == 5
and cubemap.shape[1] == 6
)
cubemap = [cubemap[:, i] for i in range(cubemap.shape[1])]
cube_format = "list"

# Ensure input is in HWC format for processing
if channels_first:
if cube_format == "list" and isinstance(cubemap, (list, tuple)):
cubemap = [r.permute(1, 2, 0) for r in cubemap]
cubemap = [_nchw2nhwc(r) for r in cubemap]
elif cube_format == "dict" and torch.jit.isinstance(
cubemap, Dict[str, torch.Tensor]
):
cubemap = {k: v.permute(1, 2, 0) for k, v in cubemap.items()} # type: ignore
cubemap = {k: _nchw2nhwc(v) for k, v in cubemap.items()} # type: ignore
elif cube_format in ["horizon", "dice"] and isinstance(cubemap, torch.Tensor):
cubemap = cubemap.permute(1, 2, 0)
cubemap = _nchw2nhwc(cubemap)
else:
raise NotImplementedError("unknown cube_format and cubemap type")

Expand Down