Giter VIP home page Giter VIP logo

Comments (6)

Voveka98 avatar Voveka98 commented on May 29, 2024 1

Currently not able to update and check, but your solution worked. Thanks a lot!

from dali.

mzient avatar mzient commented on May 29, 2024

Hello @Voveka98
You don't need to calculate the centerpoint - center crop is the default crop.

    images = fn.decoders.image(encoded)
    resized = fn.resize(images, size=(224, 224), mode="not_smaller")
    cropped = fn.crop(resized, crop=(224, 224))

Now, you can get more efficient by decoding only the interesting part - this way you won't need to resize the parts that are out of crop.

    shapes = fn.peek_image_shape(encoded)
    size = fn.cast(fn.reductions.min(shapes[0:2]), dtype=dali.types.FLOAT)
    images = fn.decoders.image_crop(encoded, crop=fn.stack(size, size))
    resized = fn.resize(images, size=(224, 224), mode="not_smaller")

from dali.

Voveka98 avatar Voveka98 commented on May 29, 2024

Thansk for answering, seems like first solution works for me.
When i try second one:

@pipeline_def(batch_size=1, num_threads=8,device_id=1)
def TritonLoadingPipeline():
    
    img_files = fn.external_source(name="DALI_INPUT_0")
    shapes = fn.peek_image_shape(img_files)
    size = fn.cast(fn.reductions.min(shapes[0:2]), dtype=types.FLOAT)
    images = fn.decoders.image_crop(img_files, crop=fn.stack(size, size))
    resized = fn.resize(images, size=(224, 224), mode="not_smaller")
    
    normalized_images = fn.normalize(
        resized, 
        mean=MEAN / SCALE,
        stddev=STD ,
        scale=SCALE,
        dtype=types.FLOAT,
        device="cpu",
    )
#     outputs_fp16 = fn.cast(normalized_images, dtype=types.FLOAT)
    
        
    return normalized_images 

I got an error:

TypeError                                 Traceback (most recent call last)
Input In [160], in <cell line: 1>()
----> 1 pipe = TritonLoadingPipeline()
      2 pipe.build()

File /opt/conda/lib/python3.8/site-packages/nvidia/dali/pipeline.py:1317, in pipeline_def.<locals>.actual_decorator.<locals>.create_pipeline(*args, **kwargs)
   1315 pipe = Pipeline(**{**pipeline_kwargs, **ctor_args})  # Merge and overwrite dict
   1316 with pipe:
-> 1317     pipe_outputs = func(*args, **fn_kwargs)
   1318     if isinstance(pipe_outputs, tuple):
   1319         po = pipe_outputs

Input In [159], in TritonLoadingPipeline()
      5 shapes = fn.peek_image_shape(img_files)
      6 size = fn.cast(fn.reductions.min(shapes[0:2]), dtype=types.FLOAT)
----> 7 images = fn.decoders.image_crop(img_files, crop=fn.stack(size, size))
      8 resized = fn.resize(images, size=(224, 224), mode="not_smaller")
     10 normalized_images = fn.normalize(
     11     resized, 
     12     mean=MEAN / SCALE,
   (...)
     16     device="cpu",
     17 )

File /opt/conda/lib/python3.8/site-packages/nvidia/dali/fn.py:84, in _wrap_op_fn.<locals>.fn_wrapper(*inputs, **kwargs)
     82     return current_pipeline._wrap_op_call(op_wrapper, inputs, kwargs)
     83 else:
---> 84     return op_wrapper(*inputs, **kwargs)

File /opt/conda/lib/python3.8/site-packages/nvidia/dali/fn.py:76, in _wrap_op_fn.<locals>.op_wrapper(*inputs, **kwargs)
     73 if "device" not in init_args:
     74     init_args["device"] = default_dev
---> 76 return op_class(**init_args)(*inputs, **call_args)

File /opt/conda/lib/python3.8/site-packages/nvidia/dali/ops.py:627, in python_op_factory.<locals>.Operator.__call__(self, *inputs, **kwargs)
    625 op_instances = []
    626 for input_set in input_sets:
--> 627     op_instances.append(_OperatorInstance(input_set, self, **kwargs))
    628     op_instances[-1].generate_outputs()
    630 # Tie the instances together

File /opt/conda/lib/python3.8/site-packages/nvidia/dali/ops.py:433, in _OperatorInstance.__init__(self, inputs, op, **kwargs)
    426     except Exception as e:
    427         raise TypeError(
    428                 ("Expected inputs of type " +
    429                 "`DataNode` or convertible to constant nodes. Received " +
    430                 "input `{}` of type '{}'.")
    431                 .format(k, type(arg_inp).__name__)) from e
--> 433 _check_arg_input(op._schema, type(self._op).__name__, k)
    435 self._spec.AddArgumentInput(k, arg_inp.name)
    436 self._inputs = list(self._inputs) + [arg_inp]

File /opt/conda/lib/python3.8/site-packages/nvidia/dali/ops.py:528, in _check_arg_input(schema, op_name, name)
    526     return
    527 if not schema.IsTensorArgument(name):
--> 528     raise TypeError("The argument `{}` for operator `{}` should not be a `DataNode` but a {}".format(
    529         name, op_name, _type_name_convert_to_string(schema.GetArgumentType(name), False)))

TypeError: The argument `crop` for operator `ImageCrop` should not be a `DataNode` but a float or list of float

Maybe i use some old version, will check

from dali.

jantonguirao avatar jantonguirao commented on May 29, 2024

Can you please check what NVIDIA DALI version are you using?:
python -m pip list | grep nvidia-dali

This feature was introduced in #4422, so this must be quite an old version.

from dali.

Voveka98 avatar Voveka98 commented on May 29, 2024

I use this version:
nvidia-dali-cuda110 1.11.1

from dali.

JanuszL avatar JanuszL commented on May 29, 2024

@Voveka98 - can you update to the latest version and check again?

from dali.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.