Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpSchema major rework #5740

Merged
merged 20 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dali/operators/generic/roi_random_crop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ either specified with `roi_start`/`roi_end` or `roi_start`/`roi_shape`.

The operator produces an output representing the cropping window start coordinates.
)code")
.AddRandomSeedArg()
.AddArg("crop_shape",
R"code(Cropping window dimensions.)code", DALI_INT_VEC, true)
.AddArg("roi_start",
Expand Down
1 change: 1 addition & 0 deletions dali/operators/image/crop/bbox_crop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ associated with each of the bounding boxes.)code")
return spec.NumRegularInput() - 1 + // +1 if labels are provided
spec.GetArgument<bool>("output_bbox_indices"); // +1 if output_bbox_indices=True
})
.AddRandomSeedArg()
.AddOptionalArg(
"thresholds",
R"code(Minimum IoU or a different metric, if specified by `threshold_type`, of the
Expand Down
5 changes: 3 additions & 2 deletions dali/operators/image/crop/random_crop_attr.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
// Copyright (c) 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,7 @@ The cropped image's area will be equal to ``A`` * original image's area.)code",
std::vector<float>{0.08, 1.0})
.AddOptionalArg("num_attempts",
R"code(Maximum number of attempts used to choose random area and aspect ratio.)code",
10);
10)
.AddRandomSeedArg();

} // namespace dali
1 change: 1 addition & 0 deletions dali/operators/image/remap/jitter.cu
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ and bounded by half of the `nDegree` parameter.)code")
R"code(Each pixel is moved by a random amount in the ``[-nDegree/2, nDegree/2]`` range)code",
2)
.InputLayout(0, "HWC")
.AddRandomSeedArg()
.AddParent("DisplacementFilter");

DALI_REGISTER_OPERATOR(Jitter, Jitter<GPUBackend>, GPU);
Expand Down
3 changes: 2 additions & 1 deletion dali/operators/random/batch_permutation.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,7 @@ indexing samples in the batch.)")
R"(If true, the output can contain repetitions and omissions.)", false)
.AddOptionalArg("no_fixed_points", R"(If true, the the output permutation cannot contain fixed
points, that is ``out[i] != i``. This argument is ignored when batch size is 1.)", false)
.AddRandomSeedArg()
.AddParent("ImplicitScopeAttr");

void BatchPermutation::RunImpl(Workspace &ws) {
Expand Down
3 changes: 2 additions & 1 deletion dali/operators/random/choice_cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ that is: :meth:`nvidia.dali.types.DALIDataType`, :meth:`nvidia.dali.types.DALIIm
"Distribution of the probabilities. "
"If not specified, uniform distribution is assumed.",
nullptr, true)
.AddOptionalArg<std::vector<int>>("shape", "Shape of the output data.", nullptr, true);
.AddOptionalArg<std::vector<int>>("shape", "Shape of the output data.", nullptr, true)
.AddRandomSeedArg();

DALI_REGISTER_OPERATOR(random__Choice, Choice<CPUBackend>, CPU);

Expand Down
3 changes: 2 additions & 1 deletion dali/operators/random/noise/gaussian_noise.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
// Copyright (c) 2021-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@ The shape and data type of the output will match the input.
)code")
.NumInput(1)
.NumOutput(1)
.AddRandomSeedArg()
.AddOptionalArg<float>("mean",
R"code(Mean of the distribution.)code",
0.f, true)
Expand Down
3 changes: 2 additions & 1 deletion dali/operators/random/noise/salt_and_pepper_noise.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
// Copyright (c) 2021-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@ The shape and data type of the output will match the input.
)code")
.NumInput(1)
.NumOutput(1)
.AddRandomSeedArg()
.AddOptionalArg<float>("prob",
R"code(Probability of an output value to take a salt or pepper value.)code",
0.05f, true)
Expand Down
1 change: 1 addition & 0 deletions dali/operators/random/noise/shot_noise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The shape and data type of the output will match the input.
)code")
.NumInput(1)
.NumOutput(1)
.AddRandomSeedArg()
.AddOptionalArg<float>("factor",
R"code(Factor parameter.)code",
20.0f, true);
Expand Down
4 changes: 3 additions & 1 deletion dali/operators/random/rng_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ It should be added as parent to all RNG operators.)code")

.. note::
The generated numbers are converted to the output data type, rounding and clamping if necessary.
)code", nullptr);
)code", nullptr)
.AddRandomSeedArg();


} // namespace dali
1 change: 1 addition & 0 deletions dali/operators/reader/loader/loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace dali {

DALI_SCHEMA(LoaderBase)
.AddRandomSeedArg()
.AddOptionalArg("random_shuffle",
R"code(Determines whether to randomly shuffle data.

Expand Down
1 change: 1 addition & 0 deletions dali/operators/reader/tfrecord_reader_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ DALI_REGISTER_OPERATOR(readers___TFRecord, TFRecordReader, CPU);
// Common part of schema for internal readers._tfrecord and public readers.tfrecord schema.
DALI_SCHEMA(readers___TFRecordBase)
.DocStr(R"code(Read sample data from a TensorFlow TFRecord file.)code")
.AddRandomSeedArg()
.AddArg("path",
R"code(List of paths to TFRecord files.)code",
DALI_STRING_VEC)
Expand Down
3 changes: 2 additions & 1 deletion dali/operators/segmentation/random_mask_pixel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ This argument is mutually exclusive with `value` argument.
If 0, the pixel position is sampled uniformly from all available pixels.)code",
0, true)
.NumInput(1)
.NumOutput(1);
.NumOutput(1)
.AddRandomSeedArg();

class RandomMaskPixelCPU : public rng::OperatorWithRng<CPUBackend> {
public:
Expand Down
1 change: 1 addition & 0 deletions dali/operators/segmentation/random_object_bbox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ With probability 1-foreground_prob, the entire area of the input is returned.)")
int output_class = spec.GetArgument<bool>("output_class");
return 1 + separate_corners + output_class;
})
.AddRandomSeedArg()
.AddOptionalArg("ignore_class", R"(If True, all objects are picked with equal probability,
regardless of the class they belong to. Otherwise, a class is picked first and then an object is
randomly selected from this class.
Expand Down
1 change: 1 addition & 0 deletions dali/operators/ssd/random_crop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ cropped and valid bounding boxes and valid labels are returned.)code")
.NumInput(3) // [img, bbox, label]
.NumOutput(3) // [img, bbox, label]
.AddOptionalArg("num_attempts", R"code(Number of attempts.)code", 1)
.AddRandomSeedArg()
.Deprecate("RandomBBoxCrop"); // deprecated in DALI 0.30

/*
Expand Down
10 changes: 5 additions & 5 deletions dali/pipeline/operator/argument.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class Argument {
return has_name_;
}

inline const string get_name() const {
return has_name() ? name_ : "<no name>";
inline std::string_view get_name() const & {
return has_name() ? std::string_view(name_) : "<no name>";
}

inline void set_name(string name) {
Expand All @@ -126,7 +126,7 @@ class Argument {
}

virtual std::string ToString() const {
return get_name();
return std::string(get_name());
}

virtual DALIDataType GetTypeId() const = 0;
Expand Down Expand Up @@ -230,8 +230,8 @@ template <typename T>
T Argument::Get() {
ArgumentInst<T>* self = dynamic_cast<ArgumentInst<T>*>(this);
if (self == nullptr) {
DALI_FAIL("Invalid type of argument \"" + this->get_name() + "\". Expected " +
typeid(T).name());
DALI_FAIL(make_string("Invalid type of argument \"", get_name(), "\". Expected ",
typeid(T).name()));
}
return self->Get();
}
Expand Down
2 changes: 1 addition & 1 deletion dali/pipeline/operator/builtin/input_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ class InputOperator : public Operator<Backend>, virtual public BatchSizeProvider
* Checks, if the Operator defined by provided Schema is an InputOperator
*/
inline bool IsInputOperator(const OpSchema &schema) {
const auto &parents = schema.GetParents();
const auto &parents = schema.GetParentNames();
return std::any_of(parents.begin(), parents.end(),
[](const std::string &p) { return p == "InputOperatorBase"; });
}
Expand Down
Loading
Loading