triton-inference-server / dali_backend

The Triton backend that allows running GPU-accelerated data pre-processing pipelines implemented in DALI's python API.
https://docs.nvidia.com/deeplearning/dali/user-guide/docs/index.html
MIT License
118 stars 28 forks source link

Could not serialize dali.fn.python_function #210

Closed omair18 closed 10 months ago

omair18 commented 10 months ago

Hi. I need help in serializing dali pipeline. I am trying to serialize a pipeline which uses dali.fn.python_function but I'm getting the following error.

RuntimeError: [/opt/dali/dali/pipeline/pipeline.cc:776] Assert on "spec.GetSchema().IsSerializable()" failed: Could not serialize the operator: DLTensorPythonFunctionImpl 

Here's my pipeline

def rectangular_pad(image, canvas, pad_x, pad_y):
        h, w, c = image.shape
        paste_x = int(pad_x/2)
        paste_y = int(pad_y/2)
        canvas[paste_y: paste_y + h, 
            paste_x: paste_x + w] = image
        return canvas
@dali.pipeline_def(batch_size=256, num_threads=4, device_id=0, exec_async=False, exec_pipelined=False)
def pipe():
    images = dali.fn.external_source(device="cpu", name="DALI_INPUT_0")
    images = dali.fn.decoders.image(images, device="cpu", output_type=types.BGR)
    orig_shape = dali.fn.shapes(images)
    orig_width = orig_shape[1]
    orig_height = orig_shape[0]

    scale_x = target_width / orig_width
    scale_y = target_height / orig_height
    scale_min = dali.math.min(left=scale_x, right=scale_y)

    new_width = orig_width * scale_min
    new_height = orig_height * scale_min

    pad_x = target_width - new_width
    pad_y = target_height - new_height
    resized_images = dali.fn.resize(images, resize_x=new_width, resize_y=new_height, 
                            dtype=types.FLOAT, interp_type=types.INTERP_LINEAR, antialias=False)
    canvas = dali.fn.constant(idata=128, shape=[target_height, target_width, 3])
    out_images = dali.fn.python_function(images, canvas, pad_x, pad_y, function=rectangular_pad, num_outputs=1, batch_processing=False)

    return out_images, images
JanuszL commented 10 months ago

Hi @omair18,

Let us move the discussion to https://github.com/NVIDIA/DALI/issues/5059.