Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _pipeline_function(op_list: Sequence, layout: str = "HWC", input_device: str
"""
input_node = fn.external_source(name="input_data", layout=layout, device=input_device)
for op in op_list:
input_node = op(input_node)
input_node = op._invoke(input_node)
return input_node


Expand Down
12 changes: 12 additions & 0 deletions dali/python/nvidia/dali/experimental/torchvision/v2/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,19 @@ def _kernel(self, data_input):
pass

def __call__(self, data_input):
"""
Torchvision creates callable objects, but DALI Torchvision needs to implement a pipeline.
The pipeline is implemented in Compose class and uses _invoke to execute operators' logic.
"""
raise RuntimeError(
f"Operator {self!r} is not directly callable. Use it only inside Compose pipeline."
)

def _invoke(self, data_input):
"""
Private method is used to execute operator from a Compose pipeline
Note: Do not call directly
"""
type(self).verify_data(data_input)

# Original input is transfered to GPU, before being preprocess_data.
Expand Down
9 changes: 9 additions & 0 deletions dali/test/python/torchvision/test_tv_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,12 @@ def test_compose_non_uint8_dtype_resize(dtype):
else:
with assert_raises(RuntimeError):
_ = dali_pipeline(test_tensor)


def test_error_in_isolated_operators():
"""Operators must not be called outside of Compose"""

test_tensor = torch.ones(5, 3, 10, 10, dtype=torch.uint8)
dali_resize = Resize(size=(7, 7))
with assert_raises(RuntimeError, glob="*is not directly callable*"):
_ = dali_resize(test_tensor)