1 /**
2 * Copyright 2019-2021 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_INCLUDE_DATASET_CONSTANTS_H_
17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_INCLUDE_DATASET_CONSTANTS_H_
18
19 #include <cstdint>
20 #include <limits>
21 #include <random>
22
23 namespace mindspore {
24 namespace dataset {
25 // Various type defines for convenience
26 using uchar = unsigned char;
27 using dsize_t = int64_t;
28
29 /// \brief The color conversion code
30 enum class ConvertMode {
31 COLOR_BGR2BGRA = 0, ///< Add alpha channel to BGR image.
32 COLOR_RGB2RGBA = COLOR_BGR2BGRA, ///< Add alpha channel to RGB image.
33 COLOR_BGRA2BGR = 1, ///< Remove alpha channel to BGR image.
34 COLOR_RGBA2RGB = COLOR_BGRA2BGR, ///< Remove alpha channel to RGB image.
35 COLOR_BGR2RGBA = 2, ///< Convert BGR image to RGBA image.
36 COLOR_RGB2BGRA = COLOR_BGR2RGBA, ///< Convert RGB image to BGRA image.
37 COLOR_RGBA2BGR = 3, ///< Convert RGBA image to BGR image.
38 COLOR_BGRA2RGB = COLOR_RGBA2BGR, ///< Convert BGRA image to RGB image.
39 COLOR_BGR2RGB = 4, ///< Convert BGR image to RGB image.
40 COLOR_RGB2BGR = COLOR_BGR2RGB, ///< Convert RGB image to BGR image.
41 COLOR_BGRA2RGBA = 5, ///< Convert BGRA image to RGBA image.
42 COLOR_RGBA2BGRA = COLOR_BGRA2RGBA, ///< Convert RGBA image to BGRA image.
43 COLOR_BGR2GRAY = 6, ///< Convert BGR image to GRAY image.
44 COLOR_RGB2GRAY = 7, ///< Convert RGB image to GRAY image.
45 COLOR_GRAY2BGR = 8, ///< Convert GRAY image to BGR image.
46 COLOR_GRAY2RGB = COLOR_GRAY2BGR, ///< Convert GRAY image to RGB image.
47 COLOR_GRAY2BGRA = 9, ///< Convert GRAY image to BGRA image.
48 COLOR_GRAY2RGBA = COLOR_GRAY2BGRA, ///< Convert GRAY image to RGBA image.
49 COLOR_BGRA2GRAY = 10, ///< Convert BGRA image to GRAY image.
50 COLOR_RGBA2GRAY = 11 ///< Convert RGBA image to GRAY image.
51 };
52
53 /// \brief Target devices to perform map operation.
54 enum class MapTargetDevice {
55 kCpu, ///< CPU Device.
56 kGpu, ///< Gpu Device.
57 kAscend310 ///< Ascend310 Device.
58 };
59
60 /// \brief The initial type of tensor implementation.
61 enum class TensorImpl {
62 kNone, ///< None type tensor.
63 kFlexible, ///< Flexible type tensor, can be converted to any type.
64 kCv, ///< CV type tensor.
65 kNP ///< Numpy type tensor.
66 };
67
68 /// \brief The mode for shuffling data.
69 enum class ShuffleMode {
70 kFalse = 0, ///< No shuffling is performed.
71 kFiles = 1, ///< Shuffle files only.
72 kGlobal = 2, ///< Shuffle both the files and samples.
73 kInfile = 3 ///< Shuffle data within each file.
74 };
75
76 /// \brief Possible scale for input audio.
77 enum class ScaleType {
78 kMagnitude = 0, ///< Audio scale is magnitude.
79 kPower = 1, ///< Audio scale is power.
80 };
81
82 /// \brief The scale for gain type.
83 enum class GainType {
84 kAmplitude = 0, ///< Audio gain type is amplitude.
85 kPower = 1, ///< Audio gain type is power.
86 kDb = 2, ///< Audio gain type is db.
87 };
88
89 /// \brief The method of padding.
90 enum class BorderType {
91 kConstant = 0, ///< Fill the border with constant values.
92 kEdge = 1, ///< Fill the border with the last value on the edge.
93 kReflect = 2, ///< Reflect the values on the edge omitting the last value of edge.
94 kSymmetric = 3 ///< Reflect the values on the edge repeating the last value of edge.
95 };
96
97 /// \brief Possible fix rotation angle for Rotate Op.
98 enum class FixRotationAngle {
99 k0Degree = 1, ///< Rotate 0 degree.
100 k0DegreeAndMirror = 2, ///< Rotate 0 degree and apply horizontal flip.
101 k180Degree = 3, ///< Rotate 180 degree.
102 k180DegreeAndMirror = 4, ///< Rotate 180 degree and apply horizontal flip.
103 k90DegreeAndMirror = 5, ///< Rotate 90 degree and apply horizontal flip.
104 k90Degree = 6, ///< Rotate 90 degree.
105 k270DegreeAndMirror = 7, ///< Rotate 270 degree and apply horizontal flip.
106 k270Degree = 8, ///< Rotate 270 degree.
107 };
108
109 /// \brief Possible options for Image format types in a batch.
110 enum class ImageBatchFormat {
111 kNHWC = 0, ///< Indicate the input batch is of NHWC format.
112 kNCHW = 1 ///< Indicate the input batch is of NCHW format.
113 };
114
115 /// \brief Possible options for Image format types.
116 enum class ImageFormat {
117 HWC = 0, ///< Indicate the input batch is of NHWC format
118 CHW = 1, ///< Indicate the input batch is of NHWC format
119 HW = 2 ///< Indicate the input batch is of NHWC format
120 };
121
122 /// \brief Possible options for interpolation method.
123 enum class InterpolationMode {
124 kLinear = 0, ///< Interpolation method is linear interpolation.
125 kNearestNeighbour = 1, ///< Interpolation method is nearest-neighbor interpolation.
126 kCubic = 2, ///< Interpolation method is bicubic interpolation.
127 kArea = 3, ///< Interpolation method is pixel area interpolation.
128 kCubicPil = 4 ///< Interpolation method is bicubic interpolation like implemented in pillow.
129 };
130
131 /// \brief Possible tokenize modes for JiebaTokenizer.
132 enum class JiebaMode {
133 kMix = 0, ///< Tokenize with MPSegment algorithm.
134 kMp = 1, ///< Tokenize with Hiddel Markov Model Segment algorithm.
135 kHmm = 2 ///< Tokenize with a mix of MPSegment and HMMSegment algorithm.
136 };
137
138 /// \brief Possible options for SPieceTokenizerOutType.
139 enum class SPieceTokenizerOutType {
140 kString = 0, ///< Output of sentencepiece tokenizer is string type.
141 kInt = 1 ///< Output of sentencepiece tokenizer is int type.
142 };
143
144 /// \brief Possible options for SPieceTokenizerLoadType.
145 enum class SPieceTokenizerLoadType {
146 kFile = 0, ///< Load sentencepiece tokenizer from local sentencepiece vocab file.
147 kModel = 1 ///< Load sentencepiece tokenizer from sentencepiece vocab instance.
148 };
149
150 /// \brief Type options for SentencePiece Model.
151 enum class SentencePieceModel {
152 kUnigram = 0, ///< Based on Unigram model.
153 kBpe = 1, ///< Based on Byte Pair Encoding (BPE) model.
154 kChar = 2, ///< Based on Char model.
155 kWord = 3 ///< Based on Word model.
156 };
157
158 /// \brief Possible options to specify a specific normalize mode.
159 enum class NormalizeForm {
160 kNone = 0, ///< Keep the input string tensor unchanged.
161 kNfc, ///< Normalize with Normalization Form C.
162 kNfkc, ///< Normalize with Normalization Form KC.
163 kNfd, ///< Normalize with Normalization Form D.
164 kNfkd, ///< Normalize with Normalization Form KD.
165 };
166
167 /// \brief Possible options for Mask.
168 enum class RelationalOp {
169 kEqual = 0, ///< equal to `==`
170 kNotEqual, ///< equal to `!=`
171 kLess, ///< equal to `<`
172 kLessEqual, ///< equal to `<=`
173 kGreater, ///< equal to `>`
174 kGreaterEqual, ///< equal to `>=`
175 };
176
177 /// \brief Possible modes for slice patches.
178 enum class SliceMode {
179 kPad = 0, ///< Pad some pixels before slice to patches.
180 kDrop = 1, ///< Drop remainder pixels before slice to patches.
181 };
182
183 /// \brief Possible options for SamplingStrategy.
184 enum class SamplingStrategy {
185 kRandom = 0, ///< Random sampling with replacement.
186 kEdgeWeight = 1 ///< Sampling with edge weight as probability.
187 };
188
189 /// \brief Possible values for output format in get all neighbors function of gnn dataset
190 enum class OutputFormat {
191 kNormal = 0, ///< Normal format.
192 kCoo = 1, ///< COO format.
193 kCsr = 2 ///< CSR format.
194 };
195
196 /// \brief Possible options for fade shape.
197 enum class FadeShape {
198 kLinear = 0, ///< Fade shape is linear mode.
199 kExponential = 1, ///< Fade shape is exponential mode.
200 kLogarithmic = 2, ///< Fade shape is logarithmic mode.
201 kQuarterSine = 3, ///< Fade shape is quarter_sine mode.
202 kHalfSine = 4, ///< Fade shape is half_sine mode.
203 };
204
205 /// \brief Convenience function to check bitmask for a 32bit int
206 /// \param[in] bits a 32bit int to be tested
207 /// \param[in] bitMask a 32bit int representing bit mask
208 /// \return bool Result for the check
BitTest(uint32_t bits,uint32_t bitMask)209 inline bool BitTest(uint32_t bits, uint32_t bitMask) { return (bits & bitMask) == bitMask; }
210
211 /// \brief Convenience function to set bitmask for a 32bit int
212 /// \param[in] bits a 32bit int to deal with
213 /// \param[in] bitMask a 32bit int representing bit mask
BitSet(uint32_t * bits,uint32_t bitMask)214 inline void BitSet(uint32_t *bits, uint32_t bitMask) {
215 if (bits == nullptr) {
216 return;
217 }
218 *bits |= bitMask;
219 }
220
221 /// \brief Convenience function to clear bitmask from a 32bit int
222 /// \param[in] bits a 32bit int to deal with
223 /// \param[in] bitMask a 32bit int representing bit mask
BitClear(uint32_t * bits,uint32_t bitMask)224 inline void BitClear(uint32_t *bits, uint32_t bitMask) {
225 if (bits == nullptr) {
226 return;
227 }
228 *bits &= (~bitMask);
229 }
230
231 constexpr int64_t kDeMaxDim = std::numeric_limits<int64_t>::max();
232 constexpr int32_t kDeMaxRank = std::numeric_limits<int32_t>::max();
233 constexpr int64_t kDeMaxFreq = std::numeric_limits<int64_t>::max(); // 9223372036854775807 or 2^(64-1)
234 constexpr int64_t kDeMaxTopk = std::numeric_limits<int64_t>::max();
235
236 constexpr uint32_t kCfgRowsPerBuffer = 1;
237 constexpr uint32_t kCfgParallelWorkers = 8;
238 constexpr uint32_t kCfgWorkerConnectorSize = 16;
239 constexpr uint32_t kCfgOpConnectorSize = 16;
240 constexpr uint32_t kCfgSendingBatch = 0;
241 constexpr int32_t kCfgDefaultRankId = -1;
242 constexpr uint32_t kCfgDefaultSeed = std::mt19937::default_seed;
243 constexpr uint32_t kCfgMonitorSamplingInterval = 1000; // timeout value for sampling interval in milliseconds
244 constexpr uint32_t kCfgCallbackTimeout = 60; // timeout value for callback in seconds
245 constexpr int32_t kCfgDefaultCachePort = 50052;
246 constexpr char kCfgDefaultCacheHost[] = "127.0.0.1";
247 constexpr int32_t kDftPrefetchSize = 20;
248 constexpr int32_t kDftNumConnections = 12;
249 constexpr int32_t kDftAutoNumWorkers = false;
250 constexpr char kDftMetaColumnPrefix[] = "_meta-";
251 constexpr int32_t kDecimal = 10; // used in strtol() to convert a string value according to decimal numeral system
252 constexpr int32_t kMinLegalPort = 1025;
253 constexpr int32_t kMaxLegalPort = 65535;
254
255 // Invalid OpenCV type should not be from 0 to 7 (opencv4/opencv2/core/hal/interface.h)
256 constexpr uint8_t kCVInvalidType = 255;
257
258 using connection_id_type = uint64_t;
259 using session_id_type = uint32_t;
260 using row_id_type = int64_t;
261 } // namespace dataset
262 } // namespace mindspore
263
264 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_INCLUDE_DATASET_CONSTANTS_H_
265