blace.ai
types.h
Go to the documentation of this file.
1#pragma once
2
3#include "library_defines.h"
4#include <cstdint>
5#include <iosfwd> // for ostream
6#include <optional>
7#include <string>
8#include <vector>
9
15namespace blace {
16namespace ml_core {
17
21typedef std::vector<int64_t> TensorSizes;
22
26constexpr int BYTE_MAX = 255;
30constexpr float SHORT_MAX = 32768.;
34constexpr float BYTE_MAX_FLOAT = 255.;
35
41enum DeviceEnum : int { CPU = 0, CUDA = 1, MPS = 2 };
42
46enum ValueRangeEnum : int {
47 ZERO_TO_ONE = 0,
48 MINUS_ONE_TO_ONE = 1,
49 IMAGENET = 2,
50 UNKNOWN_VALUE_RANGE = 3,
51 ZERO_TO_255 = 4,
52 MINUS_0_5_TO_0_5 = 5,
53 ZERO_TO_32768 = 6
54};
55
59enum DataTypeEnum : int {
60 INT_32 = 0,
61 FLOAT_32 = 1,
62 BLACE_BYTE = 2,
63 BLACE_BOOL = 3,
64 FLOAT_32_16 = 4,
65 FLOAT_16 = 5,
66 SHORT = 6,
67 INT_64 = 7,
68 FLOAT_64 = 8
69};
70
74enum OrderEnum : int {
75 BTCHW = 0,
76 BCHW = 1,
77 CHW = 2,
78 HWC = 3,
79 BHWC = 4,
80 HW = 5,
81 W = 6,
82 WC = 7,
83 C = 8,
84 BC = 9,
85 BWCH = 10,
86 BHW = 11,
87 BCH = 12,
88 CH = 13,
89 TBCHW = 14,
90 BCWH = 15,
91 BWHC = 16,
92 NO_DIMS = 17,
93 UNKNOWN_ORDER = 18,
94 BOUNDING_BOX_WITH_DIMS = 19,
95 THWC = 20,
96 TCHW = 21
97
98};
99
103enum ColorFormatEnum : int {
104 RGB = 0,
105 R = 1,
106 A = 2,
107 ARGB = 3,
108 ARBITRARY_CHANNELS = 4,
109 BGRA = 5,
110 BGR = 6,
111 LAB = 7,
112 AB = 8,
113 L = 9,
114 XYZ = 10,
115 YCBCR = 11,
116 Y = 12,
117 BRG = 13,
118 UV = 14
119};
120
124enum ModelDataType { tFloat = 0, tHalf };
125
129struct LAB_NORMS {
133 double l_norm;
137 double l_cent;
141 double ab_norm;
142
149 bool operator==(const LAB_NORMS &other) const;
150};
151
155enum FORWARD_MODE { SIMPLE = 0, MULTIPASS, SLICED };
156
161 NEAREST = 0,
162 LINEAR,
163 BILINEAR,
164 BICUBIC,
165 TRILINEAR,
166 AREA,
167 PIL_BICUBIC
168};
169
173enum PADDING_MODE { REPLICATION = 0, REFLECTION };
174
178enum DIRECTION { LEFT, TOP, RIGHT, BOTTOM };
179
183struct EXPORT_OR_IMPORT BlaceHash {
187 uint64_t hash[4];
188
195 bool operator==(const BlaceHash &rhs) const;
196
203 bool operator!=(const BlaceHash &rhs) const;
204
210 long long to_long_long();
211
218 std::string to_hex(int len = 8);
219
223 friend std::ostream &operator<<(std::ostream &os, const BlaceHash &obj);
224
230
236 BlaceHash(int seed);
237
243 BlaceHash(std::string str);
244
253 BlaceHash(int64_t a, int64_t b, int64_t c, int64_t d);
254
260 std::string print() {
261 std::string returnstring = "";
262 for (int temp = 0; temp < 4; temp++)
263 returnstring += std::to_string(hash[temp]) + "\n";
264 return returnstring;
265 }
266
273 static void mix_string_into_hash(BlaceHash &hash, std::string str);
274
281 static void mix_float_into_hash(BlaceHash &hash, float data);
282};
283
291 DeviceEnum device = DeviceEnum::CPU;
295 int use_half = true;
299 int seed = 0;
304 int run_threaded = false;
308 int plot_inputs = false;
313 int gpu_mem_opti = false;
319
324
331
338 bool operator==(const ModelInferenceArgs &other) const;
339
346 bool operator!=(const ModelInferenceArgs &other) const {
347 return !(*this == other);
348 }
349};
350
358 int parallel = true;
362 int samples = 1;
370 int jitter_keep_size = false;
378 PADDING_MODE padding_mode = PADDING_MODE::REFLECTION;
387
394
401 bool operator==(const MultisampleInferenceArgs &other) const;
402
409 bool operator!=(const MultisampleInferenceArgs &other) const {
410 return !(*this == other);
411 }
412};
413
421 int parallel = true;
425 int slices = 1;
429 int overlap = 32;
438
445
452 bool operator==(const SlicedInferenceArgs &other) const;
453
460 bool operator!=(const SlicedInferenceArgs &other) const {
461 return !(*this == other);
462 }
463};
464
469public:
479 ml_core::FORWARD_MODE mode = FORWARD_MODE::SIMPLE;
483 std::optional<MultisampleInferenceArgs> multi_args = std::nullopt;
487 std::optional<SlicedInferenceArgs> sliced_args = std::nullopt;
488
495
502 bool operator==(const InferenceArgsCollection &other) const;
503
510 bool operator!=(const InferenceArgsCollection &other) const {
511 return !(*this == other);
512 }
513};
514
518class ModelIdent : public std::string {
519public:
520 using std::string::string;
521
527 ModelIdent(const std::string &str) : std::string(str) {
528 // Additional initialization or processing can be done here
529 }
530};
531
532} // namespace ml_core
533} // namespace blace
ml_core::FORWARD_MODE mode
Definition: types.h:479
bool operator!=(const InferenceArgsCollection &other) const
Definition: types.h:510
ModelInferenceArgs inference_args
Definition: types.h:473
bool operator==(const InferenceArgsCollection &other) const
std::optional< SlicedInferenceArgs > sliced_args
Definition: types.h:487
std::optional< MultisampleInferenceArgs > multi_args
Definition: types.h:483
Definition: types.h:518
ModelIdent(const std::string &str)
Definition: types.h:527
Definition: types.h:183
BlaceHash(int64_t a, int64_t b, int64_t c, int64_t d)
friend std::ostream & operator<<(std::ostream &os, const BlaceHash &obj)
static void mix_string_into_hash(BlaceHash &hash, std::string str)
BlaceHash(std::string str)
std::string to_hex(int len=8)
static void mix_float_into_hash(BlaceHash &hash, float data)
bool operator==(const BlaceHash &rhs) const
std::string print()
Definition: types.h:260
bool operator!=(const BlaceHash &rhs) const
Definition: types.h:129
bool operator==(const LAB_NORMS &other) const
double l_cent
Definition: types.h:137
double ab_norm
Definition: types.h:141
double l_norm
Definition: types.h:133
Definition: types.h:287
int run_threaded
Definition: types.h:304
bool operator==(const ModelInferenceArgs &other) const
int seed
Definition: types.h:299
int experimental_torchscript_autocast
Definition: types.h:323
DeviceEnum device
Definition: types.h:291
int gpu_mem_opti
Definition: types.h:313
int empty_cache_after_inference
Definition: types.h:318
int use_half
Definition: types.h:295
int plot_inputs
Definition: types.h:308
bool operator!=(const ModelInferenceArgs &other) const
Definition: types.h:346
bool operator==(const MultisampleInferenceArgs &other) const
int parallel
Definition: types.h:358
int result_to_input_num
Definition: types.h:382
int samples
Definition: types.h:362
int max_extension
Definition: types.h:374
Interpolation jitter_interpolation
Definition: types.h:366
bool operator!=(const MultisampleInferenceArgs &other) const
Definition: types.h:409
int jitter_keep_size
Definition: types.h:370
int result_to_input_denum
Definition: types.h:386
PADDING_MODE padding_mode
Definition: types.h:378
int slices
Definition: types.h:425
int result_to_input_num
Definition: types.h:433
int parallel
Definition: types.h:421
int result_to_input_denum
Definition: types.h:437
bool operator!=(const SlicedInferenceArgs &other) const
Definition: types.h:460
int overlap
Definition: types.h:429
bool operator==(const SlicedInferenceArgs &other) const
DIRECTION
Definition: types.h:178
constexpr float BYTE_MAX_FLOAT
Definition: types.h:34
FORWARD_MODE
Definition: types.h:155
std::vector< int64_t > TensorSizes
Definition: types.h:21
DataTypeEnum
Definition: types.h:59
PADDING_MODE
Definition: types.h:173
constexpr float SHORT_MAX
Definition: types.h:30
Interpolation
Definition: types.h:160
OrderEnum
Definition: types.h:74
constexpr int BYTE_MAX
Definition: types.h:26
ColorFormatEnum
Definition: types.h:103
DeviceEnum
Definition: types.h:41
ModelDataType
Definition: types.h:124
ValueRangeEnum
Definition: types.h:46