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

RMN PR #32

Merged
merged 6 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 amd_openvx_extensions/amd_rpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ list(APPEND SOURCES
source/Resizetensor.cpp
source/ResizeCropbatchPD.cpp
source/ResizeCropMirrorPD.cpp
source/ResizeMirrorNormalizeTensor.cpp
source/RotatebatchPD.cpp
source/SaturationbatchPD.cpp
source/ScalebatchPD.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ vx_status remap_Register(vx_context);
vx_status ResizebatchPD_Register(vx_context);
vx_status ResizeCropbatchPD_Register(vx_context);
vx_status ResizeCropMirrorPD_Register(vx_context);
vx_status ResizeMirrorNormalizeTensor_Register(vx_context);
vx_status RotatebatchPD_Register(vx_context);
vx_status SaturationbatchPD_Register(vx_context);
vx_status ScalebatchPD_Register(vx_context);
Expand Down Expand Up @@ -197,6 +198,7 @@ vx_status Resizetensor_Register(vx_context);
#define VX_KERNEL_RPP_CROPMIRRORNORMALIZEBATCHPD_NAME "org.rpp.CropMirrorNormalizebatchPD"
#define VX_KERNEL_RPP_CROPPD_NAME "org.rpp.CropPD"
#define VX_KERNEL_RPP_RESIZECROPMIRRORPD_NAME "org.rpp.ResizeCropMirrorPD"
#define VX_KERNEL_RPP_RESIZEMIRRORNORMALIZETENSOR_NAME "org.rpp.ResizeMirrorNormalizeTensor"
#define VX_KERNEL_RPP_SEQUENCEREARRANGE_NAME "org.rpp.SequenceRearrange"
#define VX_KERNEL_RPP_RESIZETENSOR_NAME "org.rpp.Resizetensor"

Expand Down
3 changes: 2 additions & 1 deletion amd_openvx_extensions/amd_rpp/include/kernels_rpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ extern "C"
VX_KERNEL_RPP_VIGNETTEBATCHPD = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x4f,
VX_KERNEL_RPP_WARPAFFINEBATCHPD = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x50,
VX_KERNEL_RPP_WARPPERSPECTIVEBATCHPD = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x51,
VX_KERNEL_RPP_RESIZETENSOR = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x52
VX_KERNEL_RPP_RESIZETENSOR = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x52,
VX_KERNEL_RPP_RESIZEMIRRORNORMALIZETENSOR = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x53,
};

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions amd_openvx_extensions/amd_rpp/include/vx_ext_rpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ extern "C" SHARED_PUBLIC vx_node VX_API_CALL vxExtrppNode_remap(vx_graph graph,
extern "C" SHARED_PUBLIC vx_node VX_API_CALL vxExtrppNode_ResizebatchPD(vx_graph graph,vx_image pSrc,vx_array srcImgWidth,vx_array srcImgHeight,vx_image pDst,vx_array dstImgWidth,vx_array dstImgHeight,vx_uint32 nbatchSize);
extern "C" SHARED_PUBLIC vx_node VX_API_CALL vxExtrppNode_ResizeCropbatchPD(vx_graph graph,vx_image pSrc,vx_array srcImgWidth,vx_array srcImgHeight,vx_image pDst,vx_array dstImgWidth,vx_array dstImgHeight,vx_array x1,vx_array y1,vx_array x2,vx_array y2,vx_uint32 nbatchSize);
extern "C" SHARED_PUBLIC vx_node VX_API_CALL vxExtrppNode_ResizeCropMirrorPD(vx_graph graph,vx_image pSrc,vx_array srcImgWidth,vx_array srcImgHeight,vx_image pDst,vx_array dstImgWidth,vx_array dstImgHeight,vx_array x1,vx_array y1,vx_array x2,vx_array y2, vx_array mirrorFlag, vx_uint32 nbatchSize);
extern "C" SHARED_PUBLIC vx_node VX_API_CALL vxExtrppNode_ResizeMirrorNormalizeTensor(vx_graph graph,vx_image pSrc,vx_array srcImgWidth,vx_array srcImgHeight,vx_image pDst,vx_array dstImgWidth,vx_array dstImgHeight,vx_array mean,vx_array std_dev,vx_array flip,vx_scalar chnShift,vx_uint32 nbatchSize);
extern "C" SHARED_PUBLIC vx_node VX_API_CALL vxExtrppNode_RotatebatchPD(vx_graph graph,vx_image pSrc,vx_array srcImgWidth,vx_array srcImgHeight,vx_image pDst,vx_array dstImgWidth,vx_array dstImgHeight,vx_array angle,vx_uint32 nbatchSize);
extern "C" SHARED_PUBLIC vx_node VX_API_CALL vxExtrppNode_SaturationbatchPD(vx_graph graph,vx_image pSrc,vx_array srcImgWidth,vx_array srcImgHeight,vx_image pDst,vx_array saturationFactor,vx_uint32 nbatchSize);
extern "C" SHARED_PUBLIC vx_node VX_API_CALL vxExtrppNode_ScalebatchPD(vx_graph graph,vx_image pSrc,vx_array srcImgWidth,vx_array srcImgHeight,vx_image pDst,vx_array dstImgWidth,vx_array dstImgHeight,vx_array percentage,vx_uint32 nbatchSize);
Expand Down
343 changes: 343 additions & 0 deletions amd_openvx_extensions/amd_rpp/source/ResizeMirrorNormalizeTensor.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ vx_status get_kernels_to_publish()
STATUS_ERROR_CHECK(ADD_KERENEL(ResizeCropMirrorPD_Register));
STATUS_ERROR_CHECK(ADD_KERENEL(Copy_Register));
STATUS_ERROR_CHECK(ADD_KERENEL(Nop_Register));
STATUS_ERROR_CHECK(ADD_KERENEL(ResizeMirrorNormalizeTensor_Register));
STATUS_ERROR_CHECK(ADD_KERENEL(SequenceRearrange_Register));
STATUS_ERROR_CHECK(ADD_KERENEL(Resizetensor_Register));
return status;
Expand Down
27 changes: 27 additions & 0 deletions amd_openvx_extensions/amd_rpp/source/kernel_rpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,33 @@ VX_API_ENTRY vx_node VX_API_CALL vxExtrppNode_ResizeCropMirrorPD(vx_graph graph,
return node;
}

VX_API_ENTRY vx_node VX_API_CALL vxExtrppNode_ResizeMirrorNormalizeTensor(vx_graph graph, vx_image pSrc, vx_array srcImgWidth, vx_array srcImgHeight,vx_image pDst,vx_array dstImgWidth,vx_array dstImgHeight,vx_array mean, vx_array std_dev, vx_array flip, vx_scalar chnShift, vx_uint32 nbatchSize)
{
vx_node node = NULL;
vx_context context = vxGetContext((vx_reference)graph);
if(vxGetStatus((vx_reference)context) == VX_SUCCESS) {
vx_uint32 dev_type = getGraphAffinity(graph);
vx_scalar DEV_TYPE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_UINT32, &dev_type);
vx_scalar NBATCHSIZE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_UINT32, &nbatchSize);
vx_reference params[] = {
(vx_reference) pSrc,
(vx_reference) srcImgWidth,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please align with other params

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some are in tab and some in space. Convert everything to tab/space.

(vx_reference) srcImgHeight,
(vx_reference) pDst,
(vx_reference) dstImgWidth,
(vx_reference) dstImgHeight,
(vx_reference) mean,
(vx_reference) std_dev,
(vx_reference) flip,
(vx_reference) chnShift,
(vx_reference) NBATCHSIZE,
(vx_reference) DEV_TYPE
};
node = createNode(graph, VX_KERNEL_RPP_RESIZEMIRRORNORMALIZETENSOR, params, 12);
}
return node;
}

VX_API_ENTRY vx_node VX_API_CALL vxExtrppNode_Copy(vx_graph graph, vx_image pSrc, vx_image pDst)
{
vx_node node = NULL;
Expand Down
15 changes: 15 additions & 0 deletions rocAL/rocAL/include/api/rocal_api_augmentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ extern "C" RocalImage ROCAL_API_CALL rocalResize(RocalContext context, RocalIm
unsigned resize_longer = 0,
RocalResizeInterpolationType interpolation_type = ROCAL_LINEAR_INTERPOLATION);

/// Accepts U8 and RGB24 input.
/// \param context
/// \param input
/// \param dest_width
/// \param dest_height
/// \param mean
/// \param std_dev
/// \param is_output
/// \param p_mirror
/// \return
extern "C" RocalImage ROCAL_API_CALL rocalResizeMirrorNormalize(RocalContext p_context, RocalImage p_input,
unsigned dest_width, unsigned dest_height,
std::vector<float> &mean, std::vector<float> &std_dev,
bool is_output, RocalIntParam p_mirror = NULL);

/// Accepts U8 and RGB24 input.
/// \param context
/// \param input
Expand Down
1 change: 1 addition & 0 deletions rocAL/rocAL/include/augmentations/augmentations_nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ THE SOFTWARE.
#include "node_hue.h"
#include "node_saturation.h"
#include "node_crop_mirror_normalize.h"
#include "node_resize_mirror_normalize.h"
#include "node_resize_crop_mirror.h"
#include "node_ssd_random_crop.h"
#include "node_crop.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
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 "node.h"
#include "parameter_factory.h"
#include "parameter_vx.h"

class ResizeMirrorNormalizeNode : public Node
{
public:
ResizeMirrorNormalizeNode(const std::vector<Image *> &inputs, const std::vector<Image *> &outputs);
ResizeMirrorNormalizeNode() = delete;
void init(std::vector<float>& mean, std::vector<float>& std_dev, IntParam *mirror);
vx_array get_dst_width() { return _dst_roi_width; }
vx_array get_dst_height() { return _dst_roi_height;}
vx_array get_src_width() { return _src_roi_width; }
vx_array get_src_height() { return _src_roi_height; }
vx_array return_mirror(){ return _mirror.default_array(); }
protected:
void create_node() override;
void update_node() override;
private:
vx_array _dst_roi_width, _dst_roi_height;
std::vector<uint> _dest_width_val, _dest_height_val;
vx_array _mean_array, _std_dev_array;
std::vector<float> _mean;
std::vector<float> _std_dev;
ParameterVX<int> _mirror;
constexpr static int MIRROR_RANGE [2] = {0, 1};
};
49 changes: 49 additions & 0 deletions rocAL/rocAL/source/api/rocal_api_augmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,55 @@ rocalResize(
return output;
}

RocalImage ROCAL_API_CALL
rocalResizeMirrorNormalize(
RocalContext p_context,
RocalImage p_input,
unsigned dest_width,
unsigned dest_height,
std::vector<float> &mean,
std::vector<float> &std_dev,
bool is_output,
RocalIntParam p_mirror)
{
if(!p_context || !p_input || dest_width == 0 || dest_height == 0 )
THROW("Null values passed as input")
Image* output = nullptr;
auto context = static_cast<Context*>(p_context);
auto input = static_cast<Image*>(p_input);
auto mirror = static_cast<IntParam *>(p_mirror);
for(unsigned i = 0; i < mean.size(); i++) {
mean[i] = 0;
std_dev[i] = 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we hardcoding mean and std_dev value?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current image pipeline, the mean and std values were not being passed to the RMN calls and instead 0 and 1 is being passed. In case of CMN, we directly pass 0 and 1 to the CMN node init. But RMN Tensor needs mean and std as vectors so we are storing 0 and 1 in the vectors being passed to the RMN node

}

try
{
// For the resize mirror normalize resize node, user can create an image with a different width and height
ImageInfo output_info = input->info();
output_info.width(dest_width);
output_info.height(dest_height);
output = context->master_graph->create_image(output_info, is_output);
// For the nodes that user provides the output size the dimension of all the images after this node will be fixed and equal to that size
output->reset_image_roi();

std::shared_ptr<ResizeMirrorNormalizeNode> rmn_node = context->master_graph->add_node<ResizeMirrorNormalizeNode>({input}, {output});
// RPP doesn't support returning float buffers so passing 0 and 1 as mean and std and doing normalization in rocAL
// TODO: To be removed with rocAL Tensor support
// rmn_node->init(0, 1, mirror);
rmn_node->init(mean, std_dev, mirror);
// TODO: Uncomment the below lines once RMN meta node is added to ToT
// if (context->master_graph->meta_data_graph())
// context->master_graph->meta_add_node<ResizeMirrorNormalizeMetaNode,ResizeMirrorNormalizeNode>(rmn_node);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the meta node support not added?
How we are we updating the meta data currently then?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is just for adding the RMN augmentation support. As of the current status of this PR, there is no support for reading metadata for RMN

}
catch(const std::exception& e)
{
context->capture_error(e.what());
ERR(e.what())
}
return output;
}

RocalImage ROCAL_API_CALL
rocalBrightness(
RocalContext p_context,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
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.
*/

#include <vx_ext_rpp.h>
#include <graph.h>
#include <cmath>
#include "node_resize_mirror_normalize.h"
#include "exception.h"

ResizeMirrorNormalizeNode::ResizeMirrorNormalizeNode(const std::vector<Image *> &inputs, const std::vector<Image *> &outputs) :
Node(inputs, outputs), _mirror(MIRROR_RANGE[0], MIRROR_RANGE[1])
{
}

void ResizeMirrorNormalizeNode::create_node()
{
if(_node)
return;

std::vector<vx_float32> mean_vx, std_dev_vx;
_dest_width_val.resize(_batch_size);
_dest_height_val.resize(_batch_size);
mean_vx.resize(_batch_size * 3);
std_dev_vx.resize(_batch_size * 3);
for (uint i = 0; i < _batch_size; i++) {
mean_vx[3 * i] = _mean[0];
mean_vx[3 * i + 1] = _mean[1];
mean_vx[3 * i + 2] = _mean[2];

std_dev_vx[3 * i] = _std_dev[0];
std_dev_vx[3 * i + 1] = _std_dev[1];
std_dev_vx[3 * i + 2] = _std_dev[2];
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to mem_copy?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mean_vx and std_dev_vx are vectors of size BS*3 while _mean and _std_dev are vectors of size 3. If we opt for memcpy it still needs to done over a loop so this seems to be the clean option

_mean_array = vxCreateArray(vxGetContext((vx_reference)_graph->get()), VX_TYPE_FLOAT32, _batch_size * 3);
_std_dev_array = vxCreateArray(vxGetContext((vx_reference)_graph->get()), VX_TYPE_FLOAT32, _batch_size * 3);
vx_status mean_status = VX_SUCCESS;
mean_status |= vxAddArrayItems(_mean_array,_batch_size * 3, mean_vx.data(), sizeof(vx_float32));
mean_status |= vxAddArrayItems(_std_dev_array,_batch_size * 3, std_dev_vx.data(), sizeof(vx_float32));
_mirror.create_array(_graph ,VX_TYPE_UINT32, _batch_size);
if(mean_status != 0)
THROW(" vxAddArrayItems failed in the resize mirror normalize node (vxExtrppNode_ResizeMirrorNormalizeCropbatchPD ) node: "+ TOSTR(mean_status) + " "+ TOSTR(mean_status))

unsigned int chnShift = 0;
vx_scalar chnToggle = vxCreateScalar(vxGetContext((vx_reference)_graph->get()), VX_TYPE_UINT32, &chnShift);

std::vector<uint32_t> dst_roi_width(_batch_size,_outputs[0]->info().width());
std::vector<uint32_t> dst_roi_height(_batch_size, _outputs[0]->info().height_single());

_dst_roi_width = vxCreateArray(vxGetContext((vx_reference)_graph->get()), VX_TYPE_UINT32, _batch_size);
_dst_roi_height = vxCreateArray(vxGetContext((vx_reference)_graph->get()), VX_TYPE_UINT32, _batch_size);
vx_status width_status, height_status;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra lines inbetween

width_status = vxAddArrayItems(_dst_roi_width, _batch_size, dst_roi_width.data(), sizeof(vx_uint32));
height_status = vxAddArrayItems(_dst_roi_height, _batch_size, dst_roi_height.data(), sizeof(vx_uint32));
if(width_status != 0 || height_status != 0)
THROW(" vxAddArrayItems failed in the resize mirror normalize node (vxExtrppNode_ResizeMirrorNormalizeCropbatchPD ) node: " + TOSTR(width_status) + " " + TOSTR(height_status))

_node = vxExtrppNode_ResizeMirrorNormalizeTensor(_graph->get(), _inputs[0]->handle(), _src_roi_width, _src_roi_height, _outputs[0]->handle(),
_dst_roi_width, _dst_roi_height, _mean_array, _std_dev_array,
_mirror.default_array(), chnToggle, _batch_size);

vx_status status;
if((status = vxGetStatus((vx_reference)_node)) != VX_SUCCESS)
THROW("Adding the resize mirror normalize node (vxExtrppNode_ResizeMirrorNormalizeCropbatchPD) node failed: "+ TOSTR(status))
}

void ResizeMirrorNormalizeNode::update_node()
{
std::vector<uint32_t> src_roi_width, src_roi_height;
src_roi_width = _inputs[0]->info().get_roi_width_vec();
src_roi_height = _inputs[0]->info().get_roi_height_vec();

for(uint i = 0; i < _batch_size; i++)
{
// Min size and max size used for MLPerf MaskRCNN resize augmentation
// TODO: Get the min_size and max_size as user arguments from python
int min_size = 800;
Copy link
Collaborator

@sampath1117 sampath1117 Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did we arrive at this min size and max size?
Please add a comment stating if this is needed explicitly for MaskRCNN

int max_size = 1333;
int src_width = src_roi_width[i];
int src_height = src_roi_height[i];
int size = min_size;
int output_width, output_height;

float min_original_size = static_cast<float>(std::min(src_width, src_height));
float max_original_size = static_cast<float>(std::max(src_width, src_height));
if(max_original_size / min_original_size * size > max_size)
size = static_cast<size_t>(round(max_size * min_original_size / max_original_size));

if (((src_width <= src_height) && (src_width == size)) || ((src_height <= src_width) && (src_height == size)))
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For if and else condition syntax please follow google coding guidelines, in this file

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this sorted out?

_dest_height_val[i] = src_height;
_dest_width_val[i] = src_width;
continue;
}

if(src_width < src_height) {
output_width = size;
output_height = static_cast<size_t>(size * src_height / src_width);
} else {
output_height = size;
output_width = static_cast<size_t>(size * src_width / src_height);
}
_dest_height_val[i] = output_height;
_dest_width_val[i] = output_width;
}
vxCopyArrayRange((vx_array)_dst_roi_width, 0, _batch_size, sizeof(uint), _dest_width_val.data(), VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST);
vxCopyArrayRange((vx_array)_dst_roi_height, 0, _batch_size, sizeof(uint), _dest_height_val.data(), VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST);

_outputs[0]->update_image_roi(_dest_width_val, _dest_height_val);
_mirror.update_array();
}

void ResizeMirrorNormalizeNode::init(std::vector<float>& mean, std::vector<float>& std_dev, IntParam *mirror)
{
_mean = mean;
_std_dev = std_dev;
_mirror.set_param(core(mirror));
}
24 changes: 24 additions & 0 deletions rocAL/rocAL_pybind/amd/rocal/fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,30 @@ def resize(*inputs, bytes_per_sample_hint=0, image_type=0, interp_type=1, mag_fi
resized_image = b.Resize(Pipeline._current_pipeline._handle ,*(kwargs_pybind.values()))
return (resized_image)

def resize_mirror_normalize(*inputs, bytes_per_sample_hint=0, resize_min=0, resize_max=0,
image_type=0, mean=[0.0], mirror=1, output_dtype=types.FLOAT, output_layout=types.NCHW, pad_output=False,
preserve=False, seed=1, std=[1.0], device=None):

#Set Seed
b.setSeed(seed)

if isinstance(mirror,int):
if(mirror == 0):
mirror = b.CreateIntParameter(0)
else:
mirror = b.CreateIntParameter(1)

# pybind call arguments
kwargs_pybind = {"input_image0": inputs[0], "resize_min":resize_min, "resize_max":resize_max, "mean":mean, "std_dev":std,
"is_output": False, "mirror": mirror}
b.setSeed(seed)
rmn = b.ResizeMirrorNormalize(Pipeline._current_pipeline._handle ,*(kwargs_pybind.values()))
Pipeline._current_pipeline._tensor_layout = output_layout
Pipeline._current_pipeline._tensor_dtype = output_dtype
Pipeline._current_pipeline._multiplier = list(map(lambda x: 1/x ,std))
Pipeline._current_pipeline._offset = list(map(lambda x,y: -(x/y), mean, std))
return (rmn)

def random_crop(*inputs, crop_area_factor=[0.08, 1], crop_aspect_ratio=[0.75, 1.333333],
crop_pox_x=0, crop_pox_y=0, device = None):
# pybind call arguments
Expand Down
Loading