diff --git a/dali/operators/generic/reshape.cc b/dali/operators/generic/reshape.cc index cdc1d919977..cddbdada462 100644 --- a/dali/operators/generic/reshape.cc +++ b/dali/operators/generic/reshape.cc @@ -26,13 +26,20 @@ namespace dali { inline std::optional ReshapeNDimFunc(const OpSpec &spec) { + // run-time shape is no-go + if (spec.NumRegularInput() > 1) + return std::nullopt; + if (spec.HasTensorArgument("shape") || spec.HasTensorArgument("rel_shape")) + return std::nullopt; + std::vector shape; if (spec.TryGetRepeatedArgument(shape, "shape")) return shape.size(); std::vector rel_shape; if (spec.TryGetRepeatedArgument(rel_shape, "rel_shape")) return rel_shape.size(); - return std::nullopt; + + return spec.InputDesc(0).ndim; } DALI_SCHEMA(Reshape) diff --git a/dali/python/nvidia/dali/experimental/dynamic/_invocation.py b/dali/python/nvidia/dali/experimental/dynamic/_invocation.py index edf3d2c5ea8..cb488f52c28 100644 --- a/dali/python/nvidia/dali/experimental/dynamic/_invocation.py +++ b/dali/python/nvidia/dali/experimental/dynamic/_invocation.py @@ -151,7 +151,7 @@ def dtype(self, result_index: int) -> DType: self.run(self._eval_context) return self._results[result_index].dtype - def layout(self, result_index: int) -> str: + def layout(self, result_index: int) -> str | None: if self._results is None: if init_spec := getattr(self._operator, "_init_spec", None): init_spec(self._inputs, self._args) @@ -160,7 +160,9 @@ def layout(self, result_index: int) -> str: layout = str(layout) return None if layout == "" else layout self.run(self._eval_context) - return self._results[result_index].layout() + + layout = self._results[result_index].layout() + return layout or None # this will override "" with None def __iter__(self): for index in range(len(self)): diff --git a/dali/test/python/experimental_mode/test_output_metadata.py b/dali/test/python/experimental_mode/test_output_metadata.py index 3a6cbc21d00..2db28da7dfa 100644 --- a/dali/test/python/experimental_mode/test_output_metadata.py +++ b/dali/test/python/experimental_mode/test_output_metadata.py @@ -56,6 +56,7 @@ def assert_correct_metadata( (ndd.brightness_contrast, dict(brightness=1.2)), (ndd.crop_mirror_normalize, dict(crop=(2, 2))), (ndd.crop_mirror_normalize, dict(crop=(2, 2), dtype=ndd.float32)), + (ndd.reshape, dict(layout="")), ) def test_image_ops(func, kwargs): tensor = ndd.zeros(shape=(4, 4, 3), dtype=ndd.uint8, layout="HWC") @@ -206,3 +207,15 @@ def test_gaussian_blur_fchw(): sigmas = ndd.per_frame(sigmas) assert_correct_metadata(ndd.gaussian_blur(input, sigma=sigmas)) + + +# --- Empty layout handling --- + + +@eval_modes(ndd.EvalMode.deferred) +def test_empty_layout(): + input = ndd.as_batch([ndd.zeros(shape=(3, 3)), ndd.zeros(shape=(4, 4))]) + reshaped = ndd.reshape(input, layout="") + assert reshaped._invocation_result.layout is None + reshaped.evaluate() + assert reshaped._invocation_result.layout is None