Describes the dimensions that a layer consumes/produces. This is a matrix (height, width), its "depth" (feature_map_count), how many of these matrices are present (count), and the maximum and minimum values expected in the matrix (value_max, value_min). If input is quantized, all values greater than value_max will be clipped to value_max and all values less than value_min will be clipped to value
| 285 | // |
| 286 | // If unspecified, layout defaults to kYXDepthBatch. |
| 287 | class BatchDescriptor { |
| 288 | public: |
| 289 | // Creates a "blank" batch descriptor, which should be initialized via the |
| 290 | // named argument helpers. |
| 291 | BatchDescriptor(); |
| 292 | explicit BatchDescriptor(int ndims); |
| 293 | |
| 294 | // Clones values from 'other' for initialization. |
| 295 | void CloneFrom(const BatchDescriptor& other); |
| 296 | |
| 297 | string ToString() const; |
| 298 | string ToShortString() const; |
| 299 | |
| 300 | // Pre-condition: |
| 301 | // value_max_ == 0 |
| 302 | // value_min_ == 0 |
| 303 | // quantized_activation_mode_ == QuantizedActivationMode::k8Bit |
| 304 | TensorDescriptorProto ToProto(DataType data_type) const; |
| 305 | |
| 306 | // Accessors. |
| 307 | int64 count() const { return tensor_.dimensions(0); } |
| 308 | int64 feature_map_count() const { return tensor_.dimensions(1); } |
| 309 | int64 height() const { return GetDim(spatial_size(), DimIndex::Y); } |
| 310 | int64 width() const { return GetDim(spatial_size(), DimIndex::X); } |
| 311 | int64 spatial_dim(DimIndex dim) const { return GetDim(spatial_size(), dim); } |
| 312 | int ndims() const { return spatial_size().size(); } |
| 313 | float value_max() const { return value_max_; } |
| 314 | float value_min() const { return value_min_; } |
| 315 | DataLayout layout() const { return tensor_.data_layout(); } |
| 316 | QuantizedActivationMode quantized_activation_mode() const { |
| 317 | return quantized_activation_mode_; |
| 318 | } |
| 319 | // Full dimensions of the underlying data, ordered according to a specific |
| 320 | // layout. |
| 321 | std::vector<int64> full_dims(const DataLayout& layout) const; |
| 322 | |
| 323 | // Full strides of the underlying data, ordered according to a specific |
| 324 | // layout. |
| 325 | std::vector<int64> full_strides(const DataLayout& layout) const; |
| 326 | |
| 327 | // Named-argument helpers for avoiding user error during construction. |
| 328 | BatchDescriptor& set_count(int64 value) { |
| 329 | tensor_.set_dimensions(0, value); |
| 330 | return *this; |
| 331 | } |
| 332 | BatchDescriptor& set_feature_map_count(int64 value) { |
| 333 | tensor_.set_dimensions(1, value); |
| 334 | return *this; |
| 335 | } |
| 336 | BatchDescriptor& set_height(int64 value) { |
| 337 | SetDim(spatial_size(), DimIndex::Y, value); |
| 338 | return *this; |
| 339 | } |
| 340 | BatchDescriptor& set_width(int64 value) { |
| 341 | SetDim(spatial_size(), DimIndex::X, value); |
| 342 | return *this; |
| 343 | } |
| 344 | BatchDescriptor& set_spatial_dim(DimIndex dim, int64 value) { |
no test coverage detected