MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / ResizedTensorShape

Function ResizedTensorShape

python/mod_cvcuda/operators/OpHQResize.cpp:216–270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214};
215
216inline Shape ResizedTensorShape(const nvcv::TensorLayout &srcLayout, const nvcv::TensorShape &srcShape,
217 const Shape &outShape)
218{
219 int resizeNDim = outShape.size();
220 if (resizeNDim != 2 && resizeNDim != 3)
221 {
222 throw std::runtime_error(
223 "The `out_shape` must be a tuple of 2 or 3 integers (for 2D or 3D resampling respectively).");
224 }
225
226 bool hasDepth = srcLayout.find('D') >= 0;
227 int expectedNDim = hasDepth ? 3 : 2;
228
229 if (expectedNDim != resizeNDim)
230 {
231 if (hasDepth)
232 {
233 throw std::runtime_error(
234 "The input tensor contains depth extent (`D`) in the layout. For 3D resize, please specify the resized "
235 "shape for 3 extents: depth, height, and width. Got 2 extents.");
236 }
237 else
238 {
239 throw std::runtime_error(
240 "Expected the resized shape to consists of 2 integers: for resized height and width. Got 3 integers.");
241 }
242 }
243
244 char shapeArgLayout[4] = "DHW";
245 int shapeArg[3];
246 for (int d = 0; d < resizeNDim; d++)
247 {
248 shapeArg[d] = outShape[d].cast<int>();
249 }
250
251 Shape resizedShape(srcShape.rank());
252 for (int i = 0; i < srcShape.rank(); i++)
253 {
254 resizedShape[i] = srcShape[i];
255 }
256
257 assert(srcShape.rank() == srcLayout.rank());
258 for (int d = 0; d < resizeNDim; d++)
259 {
260 int axis = srcLayout.find(shapeArgLayout[d + 3 - resizeNDim]);
261 if (axis < 0)
262 {
263 throw std::runtime_error(
264 "The layout of an input tensor to the resize operator must contain HW extents in the layout (for "
265 "images) or DHW extents (for 3D resampling). Some extents are missing in the input tensor.");
266 }
267 resizedShape[axis] = shapeArg[d];
268 }
269 return resizedShape;
270}
271
272class PyOpHQResize : public nvcvpy::Container
273{

Callers 2

TensorHQResizeFunction · 0.85
TensorBatchHQResizeFunction · 0.85

Calls 3

findMethod · 0.80
sizeMethod · 0.45
rankMethod · 0.45

Tested by

no test coverage detected