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 5D date_layout for video input #126

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Binary file added src/qonnx/.DS_Store
Binary file not shown.
10 changes: 7 additions & 3 deletions src/qonnx/core/data_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@
NCW = ["N", "C", "W"]
NWC = ["N", "W", "C"]
NC = ["N", "C"]
# 5-dimension video input, D for sequence depth
NCDHW = ["N", "C", "D", "H", "W"]
NDHWC = ["N", "D", "H", "W", "C"]

UNKNOWN = []


def is_channels_last(layout):
return layout[-1] == "C"


def get_channels_last_layout_for_ndims(ndims):
return {4: NHWC, 3: NWC, 2: NC}[ndims]
return {5: NDHWC, 4: NHWC, 3: NWC, 2: NC}[ndims]


def get_channels_first_layout_for_ndims(ndims):
return {4: NCHW, 3: NCW, 2: NC}[ndims]
return {5: NCDHW, 4: NCHW, 3: NCW, 2: NC}[ndims]

Binary file added src/qonnx/transformation/.DS_Store
Binary file not shown.
13 changes: 13 additions & 0 deletions src/qonnx/transformation/infer_data_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def _dims_to_layout(model, node, ndims):
return DataLayout.NWC
elif layout == "NC" and ndims == 2:
return DataLayout.NC
# 5D
elif layout == "NCDHW" and ndims == 5:
return DataLayout.NCDHW
elif layout == "NDHWC" and ndims == 5:
return DataLayout.NDHWC
else:
return DataLayout.UNKNOWN
else:
Expand All @@ -59,6 +64,9 @@ def _dims_to_layout(model, node, ndims):
return DataLayout.NWC
elif ndims == 2:
return DataLayout.NC
# 5D
elif ndims == 5:
return DataLayout.NCDHW
else:
return DataLayout.UNKNOWN
else:
Expand Down Expand Up @@ -135,6 +143,11 @@ def apply(self, model):
graph_modified = True
warnings.warn("Assuming 2D input is NC")
model.set_tensor_layout(inp_name, DataLayout.NC)
# 5D
elif len(inp_shape) == 5:
graph_modified = True
warnings.warn("Assuming 5D input is NCDHW")
model.set_tensor_layout(inp_name, DataLayout.NCDHW)
else:
raise Exception(
"""Unknown number of dims for input, don't know
Expand Down