From 7d66a8e3f603f2cd363f04a750847e3f9eabdfd4 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Tue, 17 Jul 2018 12:28:42 +0100 Subject: COMPMID-1386: Add support for converting weights for CL. Change-Id: I62e3ead903366baeeb1488f233a9b8b0c388c9de Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/140403 Tested-by: Jenkins Reviewed-by: Giorgio Arena Reviewed-by: Anthony Barbier --- utils/GraphUtils.cpp | 4 +++- utils/GraphUtils.h | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'utils') diff --git a/utils/GraphUtils.cpp b/utils/GraphUtils.cpp index 0ce6076f6e..46b748bce6 100644 --- a/utils/GraphUtils.cpp +++ b/utils/GraphUtils.cpp @@ -85,9 +85,11 @@ void CaffePreproccessor::preprocess(ITensor &tensor) Window window; window.use_tensor_dimensions(tensor.info()->tensor_shape()); + const int channel_idx = get_data_layout_dimension_index(tensor.info()->data_layout(), DataLayoutDimension::CHANNEL); + execute_window_loop(window, [&](const Coordinates & id) { - const float value = *reinterpret_cast(tensor.ptr_to_element(id)) - _mean[id.z()]; + const float value = *reinterpret_cast(tensor.ptr_to_element(id)) - _mean[id[channel_idx]]; *reinterpret_cast(tensor.ptr_to_element(id)) = value; }); } diff --git a/utils/GraphUtils.h b/utils/GraphUtils.h index 8558b9066c..6d537865ba 100644 --- a/utils/GraphUtils.h +++ b/utils/GraphUtils.h @@ -474,6 +474,24 @@ inline std::unique_ptr get_npy_output_accessor(const std } } +/** Permutes a given tensor shape given the input and output data layout + * + * @param[in] tensor_shape Tensor shape to permute + * @param[in] in_data_layout Input tensor shape data layout + * @param[in] out_data_layout Output tensor shape data layout + * + * @return Permuted tensor shape + */ +inline TensorShape permute_shape(TensorShape tensor_shape, DataLayout in_data_layout, DataLayout out_data_layout) +{ + if(in_data_layout != out_data_layout) + { + arm_compute::PermutationVector perm_vec = (in_data_layout == DataLayout::NCHW) ? arm_compute::PermutationVector(2U, 0U, 1U) : arm_compute::PermutationVector(1U, 2U, 0U); + arm_compute::permute(tensor_shape, perm_vec); + } + return tensor_shape; +} + /** Utility function to return the TargetHint * * @param[in] target Integer value which expresses the selected target. Must be 0 for NEON or 1 for OpenCL or 2 (OpenCL with Tuner) -- cgit v1.2.1