NVIDIA / DALI

A GPU-accelerated library containing highly optimized building blocks and an execution engine for data processing to accelerate deep learning training and inference applications.
https://docs.nvidia.com/deeplearning/dali/user-guide/docs/index.html
Apache License 2.0
5.1k stars 615 forks source link

DataNode to integer #3418

Open Sumered opened 3 years ago

Sumered commented 3 years ago

I'm trying to implement somehow more complicated pipeline using Dali and Triton, I want for it to look like this:

Is it possible to do this in such way? Right now I'm stuck at trying to get number of bboxes from first neural network predictions so I can iterate over those bboxes. It seems that it is impossible to get DataNode as int, and use it in for loop. Code for the second Dali element looks like this:

@dali.pipeline_def(batch_size=1, num_threads=64, device_id=0)
def pipe():
    detections = dali.fn.external_source(
        device="gpu", name="DETECTIONS", batch=False)
    image = dali.fn.external_source(
        device="gpu", name="preprocess_output", batch=False)
    batch = []
    number = dali.fn.cast(detections[0], dtype=dali.types.INT64)
    for i in range(0, number, 6):
        x = detections[i+1]
        y = detections[i+2]
        width = detections[i+3]
        height = detections[i+4]
        batch.append(dali.fn.resize(
            image[y:y+height, x:x+width], resize_x=640,
            resize_y=640, dtype=dali.types.FLOAT))
    batch_result = dali.fn.expand_dims(batch[0], axes=[0])
    for i in range(1, len(batch)):
        dali.fn.cat(batch_result, batch[i], axis=0)
    return batch_result

pipe().serialize(filename="/home/somewhere/model.dali")

Error that I'm getting is:

Traceback (most recent call last):
  File "1_test.py", line 26, in <module>
    pipe().serialize(filename="/home/somewhere/model.dali")
  File "/home/user/.local/lib/python3.8/site-packages/nvidia/dali/pipeline.py", line 1346, in create_pipeline
    pipe_outputs = func(*args, **fn_kwargs)
  File "1_test.py", line 12, in pipe
    for i in range(0, number, 6):
TypeError: 'DataNode' object cannot be interpreted as an integer
JanuszL commented 3 years ago

Hi @Sumered,

Batch in DALI is implicit and you cannot iterate over samples inside the pipeline definition and simply create a batch appending samples. DALI doesn't support changing the batch size inside the pipeline, however, long term this could be a case for you:

Now what I could advise you is to try out python TRITON backend.