MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / crop_and_resize

Function crop_and_resize

tests/validation/reference/CropResize.cpp:172–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170
171template <typename T>
172SimpleTensor<float> crop_and_resize(const SimpleTensor<T> &src,
173 const SimpleTensor<float> &boxes,
174 SimpleTensor<int32_t> box_ind,
175 Coordinates2D crop_size,
176 InterpolationPolicy method,
177 float extrapolation_value)
178{
179 ARM_COMPUTE_ERROR_ON(src.shape().num_dimensions() > 4);
180 ARM_COMPUTE_ERROR_ON(src.data_layout() != DataLayout::NHWC);
181
182 const TensorShape out_shape(src.shape()[0], crop_size.x, crop_size.y, boxes.shape()[1]);
183 SimpleTensor<float> out{out_shape, DataType::F32, 1, QuantizationInfo(), DataLayout::NHWC};
184
185 const TensorShape scaled_image_shape(src.shape()[0], crop_size.x, crop_size.y);
186
187 for (uint32_t i = 0; i < boxes.shape()[1]; ++i)
188 {
189 Coordinates start = Coordinates(
190 std::floor((*reinterpret_cast<const float *>(boxes(Coordinates(1, i)))) * (src.shape()[1] - 1) + 0.5f),
191 std::floor((*reinterpret_cast<const float *>(boxes(Coordinates(0, i)))) * (src.shape()[2] - 1) + 0.5f));
192 Coordinates end = Coordinates(
193 std::floor((*reinterpret_cast<const float *>(boxes(Coordinates(3, i)))) * (src.shape()[1] - 1) + 0.5f),
194 std::floor((*reinterpret_cast<const float *>(boxes(Coordinates(2, i)))) * (src.shape()[2] - 1) + 0.5f));
195 SimpleTensor<float> cropped = crop_image(src, start, end, box_ind[i], extrapolation_value);
196 SimpleTensor<float> scaled = scale_image(cropped, scaled_image_shape, method, extrapolation_value);
197 std::copy_n(reinterpret_cast<float *>(scaled.data()), scaled.num_elements(),
198 reinterpret_cast<float *>(out(Coordinates(0, 0, 0, i))));
199 }
200 return out;
201}
202
203template SimpleTensor<float> crop_and_resize(const SimpleTensor<float> &src,
204 const SimpleTensor<float> &boxes,

Callers 1

compute_referenceMethod · 0.85

Calls 10

floorFunction · 0.85
crop_imageFunction · 0.85
scale_imageFunction · 0.85
QuantizationInfoClass · 0.50
CoordinatesClass · 0.50
num_dimensionsMethod · 0.45
shapeMethod · 0.45
data_layoutMethod · 0.45
dataMethod · 0.45
num_elementsMethod · 0.45

Tested by

no test coverage detected