Skip to content
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

Add Custom DepthToSpace Op for CRD Mode #2745

Merged
merged 1 commit into from
Feb 19, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

""" Custom modules for functional operations defined under torch and torch.nn.functional packages """

from typing import Callable, Any, Tuple, Union
from typing import Callable, Any, Tuple, Union, List
import itertools
import torchvision
import torch
Expand Down Expand Up @@ -278,6 +278,24 @@ def forward(data: torch.Tensor, indices: torch.Tensor, axis: int = 0) -> torch.T
return torch.index_select(data, axis, indices.flatten()).reshape(target_shape)


class DepthToSpaceCRDMode(torch.nn.Module):
""" Depthtospace op implementation in CRD mode """

def __init__(self, block_size: List):
super().__init__()
self.block_size_h = block_size[0]
self.block_size_w = block_size[1]

def forward(self, x: torch.Tensor) -> Any:
"""
Forward-pass routine for DepthToSpace op in CRD mode
"""
b, c, h, w = x.shape
tmp = torch.reshape(x, (b, c // (self.block_size_h * self.block_size_w), self.block_size_h, self.block_size_w, h, w))
tmp = torch.permute(tmp, (0, 1, 4, 2, 5, 3))
out = torch.reshape(tmp, (b, c // (self.block_size_h * self.block_size_w), h * self.block_size_h, w * self.block_size_w))
return out

class DepthToSpaceDCRMode(torch.nn.Module):
""" Depthtospace op implementation in DCR mode """

Expand Down
Loading