MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ShapeFromFormat

Function ShapeFromFormat

tensorflow/core/util/tensor_format.h:521–548  ·  view source on GitHub ↗

Returns a tensor shape for the specified format and dimension sizes. Works for both 2D and 3D operations. The output shapes are as follows: FORMAT_NHWC: (N, spatial, C); rank = spatial.size() + 2 FORMAT_NCHW: (N, C, spatial); rank = spatial.size() + 2 FORMAT_NCHW_VECT_C: (N, C, spatial, InnerC); rank = spatial.size() + 3 FORMAT_NHWC_VECT_W: (N, spatial, C, InnerW); rank = spatial.siz

Source from the content-addressed store, hash-verified

519// FORMAT_NCHW_VECT_C: (N, C, spatial, InnerC); rank = spatial.size() + 3
520// FORMAT_NHWC_VECT_W: (N, spatial, C, InnerW); rank = spatial.size() + 3
521inline TensorShape ShapeFromFormat(TensorFormat format, int64 N,
522 gtl::ArraySlice<int64> spatial, int64 C) {
523 const int dims = GetTensorDimsFromSpatialDims(spatial.size(), format);
524 gtl::InlinedVector<int64, 6> dim_sizes(dims);
525 dim_sizes[GetTensorBatchDimIndex(dims, format)] = N;
526 for (int dim = 0; static_cast<size_t>(dim) < spatial.size(); dim++) {
527 auto dim_size = spatial[dim];
528 if (format == FORMAT_NHWC_VECT_W &&
529 static_cast<size_t>(dim) == spatial.size() - 1) {
530 CHECK_EQ(0, dim_size % 4)
531 << "FORMAT_NHWC_VECT_W requires W to be a multiple of 4, but W="
532 << dim_size;
533 dim_sizes[GetTensorInnerWidthDimIndex(dims, format)] = 4;
534 dim_size /= 4;
535 }
536 dim_sizes[GetTensorSpatialDimIndex(dims, format, dim)] = dim_size;
537 }
538
539 int feature_index = GetTensorFeatureDimIndex(dims, format);
540 if (format == FORMAT_NCHW_VECT_C) {
541 CHECK_EQ(0, C % 4) << "NCHW_VECT_C requires C to be a multiple of 4, but C="
542 << C;
543 C /= 4;
544 dim_sizes[GetTensorInnerFeatureDimIndex(dims, format)] = 4;
545 }
546 dim_sizes[feature_index] = C;
547 return TensorShape(dim_sizes);
548}
549
550// Return a tensor shape of the specified 'format', and dimensions.
551// Works for both 2D and 3D operations. If 'format' is OIHW_VECT_I,

Callers 15

ComputeMethod · 0.85
TransformNHWCToNCHWFunction · 0.85
launchMethod · 0.85
operator()Method · 0.85
ComputeMethod · 0.85
ComputeMethod · 0.85
ComputeMethod · 0.85
operator()Method · 0.85
operator()Method · 0.85
operator()Method · 0.85
operator()Method · 0.85
operator()Method · 0.85

Calls 12

GetTensorBatchDimIndexFunction · 0.85
GetTensorSpatialDimIndexFunction · 0.85
GetTensorFeatureDimIndexFunction · 0.85
GetTensorDimFunction · 0.85
GetTensorSpatialDimsFunction · 0.85
TensorShapeClass · 0.50
sizeMethod · 0.45
dimsMethod · 0.45
dim_sizesMethod · 0.45

Tested by

no test coverage detected