Skip to content
Open
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
67 changes: 65 additions & 2 deletions rocAL/include/api/rocal_api_augmentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ extern "C" RocalTensor ROCAL_API_CALL rocalContrastFixed(RocalContext context, R
* \return RocalTensor
*/
extern "C" RocalTensor ROCAL_API_CALL rocalFlip(RocalContext context, RocalTensor input, bool is_output,
RocalIntParam horizonal_flag = NULL, RocalIntParam vertical_flag = NULL,
RocalIntParam horizonal_flag = NULL, RocalIntParam vertical_flag = NULL, RocalIntParam depth_flag = NULL,
RocalTensorLayout output_layout = ROCAL_NONE,
RocalTensorOutputType output_datatype = ROCAL_UINT8);

Expand All @@ -323,7 +323,7 @@ extern "C" RocalTensor ROCAL_API_CALL rocalFlip(RocalContext context, RocalTenso
* \return RocalTensor
*/
extern "C" RocalTensor ROCAL_API_CALL rocalFlipFixed(RocalContext context, RocalTensor input,
int horizonal_flag, int vertical_flag, bool is_output,
int horizonal_flag, int vertical_flag, int depth_flag, bool is_output,
RocalTensorLayout output_layout = ROCAL_NONE,
RocalTensorOutputType output_datatype = ROCAL_UINT8);

Expand Down Expand Up @@ -565,6 +565,66 @@ extern "C" RocalTensor ROCAL_API_CALL rocalSnPNoiseFixed(RocalContext context, R
RocalTensorLayout output_layout = ROCAL_NONE,
RocalTensorOutputType output_datatype = ROCAL_UINT8);

/*! \brief Applies gaussian noise effect on images.
* \ingroup group_rocal_augmentations
* \param [in] context Rocal context
* \param [in] input Input Rocal tensor
* \param [in] is_output is the output tensor part of the graph output
* \param [in] mean Mean of the distribution
* \param [in] std_dev Standard deviation of the distribution
* \param [in] seed seed value for the random number generator
* \param [in] output_layout the layout of the output tensor
* \param [in] output_datatype the data type of the output tensor
* \return RocalTensor
*/
extern "C" RocalTensor ROCAL_API_CALL rocalGaussianNoise(RocalContext context, RocalTensor input,
bool is_output,
RocalFloatParam mean = NULL, RocalFloatParam std_dev = NULL,
int seed = 0,
RocalTensorLayout output_layout = ROCAL_NONE,
RocalTensorOutputType output_datatype = ROCAL_UINT8);

/*! \brief Applies gaussian noise effect on images with fixed parameters.
* \ingroup group_rocal_augmentations
* \param [in] context Rocal context
* \param [in] input Input Rocal tensor
* \param [in] is_output is the output tensor part of the graph output
* \param [in] mean Mean of the distribution
* \param [in] std_dev Standard deviation of the distribution
* \param [in] seed seed value for the random number generator
* \param [in] output_layout the layout of the output tensor
* \param [in] output_datatype the data type of the output tensor
* \return RocalTensor
*/
extern "C" RocalTensor ROCAL_API_CALL rocalGaussianNoiseFixed(RocalContext context, RocalTensor input,
float mean, float std_dev,
bool is_output, int seed = 0,
RocalTensorLayout output_layout = ROCAL_NONE,
RocalTensorOutputType output_datatype = ROCAL_UINT8);

/*! \brief Applies slice augmentation on images.
* \ingroup group_rocal_augmentations
* \param [in] context Rocal context
* \param [in] input Input Rocal tensor
* \param [in] is_output is the output tensor part of the graph output
* \param [in] anchor_tensor Anchor used for slice
* \param [in] shape_tensor Shape of the output slice
* \param [in] fill_values Fill value for the slice padding
* \param [in] policy Padding policy used for slice augmentation
* \param [in] output_layout the layout of the output tensor
* \param [in] output_datatype the data type of the output tensor
* \return RocalTensor
*/
extern "C" RocalTensor ROCAL_API_CALL rocalSlice(RocalContext context,
RocalTensor input,
bool is_output,
RocalTensor anchor_tensor,
std::vector<int> shape_tensor,
std::vector<float> fill_values,
RocalOutOfBoundsPolicy policy,
RocalTensorLayout output_layout = ROCAL_NONE,
RocalTensorOutputType output_datatype = ROCAL_UINT8);

/*! \brief Applies snow effect on images.
* \ingroup group_rocal_augmentations
* \param [in] context Rocal context
Expand Down Expand Up @@ -1098,4 +1158,7 @@ extern "C" RocalTensor ROCAL_API_CALL rocalSSDRandomCrop(RocalContext context, R
RocalTensorLayout output_layout = ROCAL_NONE,
RocalTensorOutputType output_datatype = ROCAL_UINT8);

extern "C" RocalTensor ROCAL_API_CALL rocalSetLayout(RocalContext context, RocalTensor input,
RocalTensorLayout output_layout = ROCAL_NONE);

#endif // MIVISIONX_ROCAL_API_AUGMENTATION_H
11 changes: 11 additions & 0 deletions rocAL/include/api/rocal_api_meta_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,15 @@ extern "C" void ROCAL_API_CALL rocalGetImageId(RocalContext p_context, int* buf)
*/
extern "C" void ROCAL_API_CALL rocalGetJointsDataPtr(RocalContext p_context, RocalJointsData** joints_data);

/*! \brief initialize the values required for ROI Random crop
* \ingroup group_rocal_meta_data
* \param [in] rocal_context rocal context
* \param [in] crop_shape_batch
* \param [in] roi_begin_batch
* \param [in] input_shape_batch
* \param [in] roi_end_batch
* \param [out] anchor The generated anchor tensor
*/
extern "C" RocalTensor ROCAL_API_CALL rocalROIRandomCrop(RocalContext p_context, RocalTensor p_input, std::vector<int> crop_shape, int remove_dim=-1);

#endif // MIVISIONX_ROCAL_API_META_DATA_H
12 changes: 12 additions & 0 deletions rocAL/include/api/rocal_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,16 @@ enum class RocalROICordsType {
ROCAL_XYWH = 1
};

/*! \brief Tensor padding types
* \ingroup group_rocal_types
*/
enum RocalOutOfBoundsPolicy {
/*! \brief TRIM_TO_SHAPE
*/
TRIMTOSHAPE = 0,
/*! \brief PAD
*/
PAD,
};

#endif // MIVISIONX_ROCAL_API_TYPES_H
2 changes: 2 additions & 0 deletions rocAL/include/augmentations/augmentations_nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ THE SOFTWARE.
#include "node_copy.h"
#include "node_nop.h"
#include "node_sequence_rearrange.h"
#include "node_gaussian_noise.h"
#include "node_slice.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright (c) 2019 - 2023 Advanced Micro Devices, Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#pragma once

#include "graph.h"
#include "node.h"
#include "parameter_factory.h"
#include "parameter_vx.h"

class GaussianNoiseNode : public Node {
public:
GaussianNoiseNode(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs);
GaussianNoiseNode() = delete;
void init(float mean, float std_dev, int seed);
void init(FloatParam *mean_param, FloatParam *stddev_param, int seed);

protected:
void create_node() override;
void update_node() override;

private:
ParameterVX<float> _mean, _stddev;
constexpr static float MEAN_RANGE[2] = {0, 5};
constexpr static float STDDEV_RANGE[2] = {1, 5};
int _seed;
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ class FlipNode : public Node {
public:
FlipNode(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs);
FlipNode() = delete;
void init(int h_flag, int v_flag);
void init(IntParam *h_flag_param, IntParam *v_flag_param);
void init(int h_flag, int v_flag, int d_flag);
void init(IntParam *h_flag_param, IntParam *v_flag_param, IntParam *d_flag_param);
vx_array get_horizontal_flip() { return _horizontal.default_array(); }
vx_array get_vertical_flip() { return _vertical.default_array(); }
vx_array get_depth_flip() { return _depth.default_array(); }

protected:
void create_node() override;
void update_node() override;

private:
ParameterVX<int> _horizontal, _vertical;
ParameterVX<int> _horizontal, _vertical, _depth;
constexpr static int HORIZONTAL_RANGE[2] = {0, 1};
constexpr static int VERTICAL_RANGE[2] = {0, 1};
constexpr static int DEPTH_RANGE[2] = {0, 1};
};
51 changes: 51 additions & 0 deletions rocAL/include/augmentations/geometry_augmentations/node_slice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#pragma once
#include "graph.h"
#include "node.h"
#include "parameter_factory.h"
#include "parameter_vx.h"
#include "rocal_api_types.h"

class SliceNode : public Node {
public:
SliceNode(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs);
SliceNode() = delete;
~SliceNode();
void init(Tensor *anchor_param, std::vector<int> shape_param, std::vector<float> &fill_values_param, RocalOutOfBoundsPolicy policy);

protected:
void create_node() override;
void update_node() override;
void create_shape_tensor();

private:
vx_array _fill_values_array;
void *_shape_array;
Tensor *_anchor;
vx_tensor _shape = nullptr;
std::vector<float> _fill_values, _fill_values_vec;
std::vector<int> _anchor_vec, _shape_vec;
std::vector<std::vector<uint32_t>> _slice_roi;
RocalOutOfBoundsPolicy _policy = RocalOutOfBoundsPolicy::PAD;
};
8 changes: 8 additions & 0 deletions rocAL/include/pipeline/master_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class MasterGraph {
void set_sequence_batch_size(size_t sequence_length) { _sequence_batch_size = _user_batch_size * sequence_length; }
std::vector<rocalTensorList *> get_bbox_encoded_buffers(size_t num_encoded_boxes);
size_t bounding_box_batch_count(pMetaDataBatch meta_data_batch);
Tensor* roi_random_crop(Tensor *input, int *crop_shape, int remove_dim=-1);
void update_roi_random_crop(int *crop_shape_batch, int *roi_begin_batch, int *roi_end_batch);
#if ENABLE_OPENCL
cl_command_queue get_ocl_cmd_q() { return _device.resources()->cmd_queue; }
#endif
Expand Down Expand Up @@ -205,6 +207,12 @@ class MasterGraph {
bool _offset; // Returns normalized offsets ((encoded_bboxes*scale - anchors*scale) - mean) / stds in EncodedBBoxes that use std and the mean and scale arguments if offset="True"
std::vector<float> _means, _stds; //_means: [x y w h] mean values for normalization _stds: [x y w h] standard deviations for offset normalization.
bool _augmentation_metanode = false;
bool _is_roi_random_crop = false;
uint _input_dims, _output_dims, _roi_dim_to_remove;
int *_crop_shape_batch = nullptr;
int *_roi_batch = nullptr;
Tensor *_roi_random_crop_tensor = nullptr;
void *_roi_random_crop_buf = nullptr;
#if ENABLE_HIP
BoxEncoderGpu *_box_encoder_gpu = nullptr;
#endif
Expand Down
34 changes: 29 additions & 5 deletions rocAL/include/pipeline/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,17 @@ class TensorInfo {
_channels = _dims.at(2);
} else if (_layout == RocalTensorlayout::NDHWC) {
_is_image = false;
_max_shape.resize(3);
_max_shape = {_dims.at(1), _dims.at(2), _dims.at(3)};
_max_shape.resize(4);
_max_shape.assign(_dims.begin() + 1, _dims.end());
_channels = _dims.at(4);
} else if (_layout == RocalTensorlayout::NCDHW) {
_is_image = false;
_max_shape.resize(3);
_max_shape = {_dims.at(2), _dims.at(3), _dims.at(4)};
_max_shape.resize(4);
_max_shape.assign(_dims.begin() + 1, _dims.end());
_channels = _dims.at(1);
}
} else {
if (!_max_shape.size()) _max_shape.resize(_num_of_dims - 1, 0); // Since 2 values will be stored in the vector
if (!_max_shape.size()) _max_shape.resize(_num_of_dims - 1, 0);
_max_shape.assign(_dims.begin() + 1, _dims.end());
}
reset_tensor_roi_buffers();
Expand Down Expand Up @@ -247,6 +247,29 @@ class TensorInfo {
set_tensor_layout(layout); // Modify the layout and dims based on the layout input
reset_tensor_roi_buffers(); // Reset ROI buffers to reflect the modified width and height
}
void modify_dims(RocalTensorlayout layout, std::vector<int> new_dims) {
switch (_layout) {
case RocalTensorlayout::NDHWC: {
_max_shape[0] = _dims[1] = new_dims[0];
_max_shape[1] = _dims[2] = new_dims[1];
_max_shape[2] = _dims[3] = new_dims[2];
break;
}
case RocalTensorlayout::NCDHW: {
_max_shape[1] = _dims[2] = new_dims[0];
_max_shape[2] = _dims[3] = new_dims[1];
_max_shape[3] = _dims[4] = new_dims[2];
break;
}
default: {
THROW("Invalid layout type specified")
}
}
modify_strides();
_data_size = _strides[0] * _dims[0]; // Modify data size wrt latest width and height
set_tensor_layout(layout); // Modify the layout and dims based on the layout input
reset_tensor_roi_buffers(); // Reset ROI buffers to reflect the modified width and height
}
void modify_strides() {
_strides[_num_of_dims - 1] = _data_type_size;
for (int i = _num_of_dims - 2; i >= 0; i--) {
Expand Down Expand Up @@ -345,6 +368,7 @@ class Tensor : public rocalTensor {
// create_from_handle() no internal memory allocation is done here since
// tensor's handle should be swapped with external buffers before usage
int create_from_handle(vx_context context);
int create_from_ptr(vx_context context, void *ptr);
int create_virtual(vx_context context, vx_graph graph);
bool is_handle_set() { return (_vx_handle != 0); }
void set_dims(std::vector<size_t> dims) { _info.set_dims(dims); }
Expand Down
Loading