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

if I want to crop from different start point, how can I build pipe to do this? #207

Closed qihang720 closed 9 months ago

qihang720 commented 10 months ago

In my situation, I have to use yolo detected to crop different rect in original images, so how can I use dali to crop it.

szalpal commented 10 months ago

Hi @qihang720 ,

I'm not sure I've understood your question. I assume you'd like to put together a pipeline, where as input you have a batch of images and every such image will be cropped, but according to different position. Assuming it's for DALI Backend, here's the example:

W = 224
H = 224

@pipeline_def
def pipe():
    enc = fn.external_source(name="ENC_IMAGE")
    crop_x = fn.external_source(name="CROP_X")
    crop_y = fn.external_source(name="CROP_Y")
    dec = fn.decoders.image(enc)
    return fn.crop(dec, crop_pos_x=crop_x, crop_pos_y=crop_y, crop=(H, W))

The explanation of crop_pos_x and crop_pos_y arguments you can find in fn.crop documentation. In CROP_X and CROP_Y inputs, Client shall send a tensor with values determining cropping position. Please refer to documentation for the details.

Alternatively, you can use fn.crop_mirror_normalize operator, if you like to combine cropping with other operation.

qihang720 commented 9 months ago

Hi @qihang720 ,

I'm not sure I've understood your question. I assume you'd like to put together a pipeline, where as input you have a batch of images and every such image will be cropped, but according to different position. Assuming it's for DALI Backend, here's the example:

W = 224
H = 224

@pipeline_def
def pipe():
    enc = fn.external_source(name="ENC_IMAGE")
    crop_x = fn.external_source(name="CROP_X")
    crop_y = fn.external_source(name="CROP_Y")
    dec = fn.decoders.image(enc)
    return fn.crop(dec, crop_pos_x=crop_x, crop_pos_y=crop_y, crop=(H, W))

The explanation of crop_pos_x and crop_pos_y arguments you can find in fn.crop documentation. In CROP_X and CROP_Y inputs, Client shall send a tensor with values determining cropping position. Please refer to documentation for the details.

Alternatively, you can use fn.crop_mirror_normalize operator, if you like to combine cropping with other operation.

Thanks for your help, this is exactly the answer I want!