blace.ai
Loading...
Searching...
No Matches
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, DML = 3 };
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 H = 22,
98 BAUDIO_MONO_44100HZ = 23
99
100};
101
105enum ColorFormatEnum : int {
106 RGB = 0,
107 R = 1,
108 A = 2,
109 ARGB = 3,
110 ARBITRARY_CHANNELS = 4,
111 BGRA = 5,
112 BGR = 6,
113 LAB = 7,
114 AB = 8,
115 L = 9,
116 XYZ = 10,
117 YCBCR = 11,
118 Y = 12,
119 BRG = 13,
120 UV = 14
121};
122
126enum ModelDataType { tFloat = 0, tHalf };
127
131struct LAB_NORMS {
135 double l_norm;
139 double l_cent;
143 double ab_norm;
144
151 bool operator==(const LAB_NORMS &other) const;
152};
153
157enum FORWARD_MODE { SIMPLE = 0, MULTIPASS, SLICED };
158
163 NEAREST = 0,
164 LINEAR,
165 BILINEAR,
166 BICUBIC,
167 TRILINEAR,
168 AREA,
169 PIL_BICUBIC
170};
171
175enum PADDING_MODE { REPLICATION = 0, REFLECTION, CONSTANT };
176
180enum DIRECTION { LEFT, TOP, RIGHT, BOTTOM };
181
187 TORCHSCRIPT_CUDA_FP32,
188 TORCHSCRIPT_CUDA_FP16,
189 TORCHSCRIPT_MPS_FP32,
190 ONNX_CUDA_FP32,
191 ONNX_CUDA_FP16,
192 ONNX_CPU_FP32,
193 TORCHSCRIPT_MPS_FP16,
194 TORCHSCRIPT_CPU_FP32,
195 ONNX_DML_FP32,
196 ONNX_DML_FP16
197};
198
202enum Framework { TORCHSCRIPT, ONNXRUNTIME };
203
207struct EXPORT_OR_IMPORT BlaceHash {
211 uint64_t hash[4];
212
219 bool operator==(const BlaceHash &rhs) const;
220
227 bool operator!=(const BlaceHash &rhs) const;
228
234 long long to_long_long();
235
242 std::string to_hex(int len = 8);
243
247 friend std::ostream &operator<<(std::ostream &os, const BlaceHash &obj);
248
254
260 BlaceHash(int seed);
261
267 BlaceHash(std::string str);
268
277 BlaceHash(int64_t a, int64_t b, int64_t c, int64_t d);
278
284 std::string print() {
285 std::string returnstring = "";
286 for (int temp = 0; temp < 4; temp++)
287 returnstring += std::to_string(hash[temp]) + "\n";
288 return returnstring;
289 }
290
297 static void mix_string_into_hash(BlaceHash &hash, std::string str);
298
305 static void mix_float_into_hash(BlaceHash &hash, float data);
306};
307
316 std::vector<Backend> backends;
320 int deprecated = true;
324 int seed = 0;
329 int run_threaded = false;
333 int plot_inputs = false;
338 int gpu_mem_opti = false;
344
349
356
363 bool operator==(const ModelInferenceArgs &other) const;
364
371 bool operator!=(const ModelInferenceArgs &other) const {
372 return !(*this == other);
373 }
374};
375
383 int parallel = true;
387 int samples = 1;
391 int allow_mirroring = true;
399 int jitter_keep_size = false;
407 PADDING_MODE padding_mode = PADDING_MODE::REFLECTION;
416
423
430 bool operator==(const MultisampleInferenceArgs &other) const;
431
438 bool operator!=(const MultisampleInferenceArgs &other) const {
439 return !(*this == other);
440 }
441};
442
450 int parallel = true;
454 int slices = 1;
458 int overlap = 32;
467
474
481 bool operator==(const SlicedInferenceArgs &other) const;
482
489 bool operator!=(const SlicedInferenceArgs &other) const {
490 return !(*this == other);
491 }
492};
493
498public:
508 ml_core::FORWARD_MODE mode = FORWARD_MODE::SIMPLE;
512 std::optional<MultisampleInferenceArgs> multi_args = std::nullopt;
516 std::optional<SlicedInferenceArgs> sliced_args = std::nullopt;
517
524
531 bool operator==(const InferenceArgsCollection &other) const;
532
539 bool operator!=(const InferenceArgsCollection &other) const {
540 return !(*this == other);
541 }
542};
543
547class ModelIdent : public std::string {
548public:
549 using std::string::string;
550
556 ModelIdent(const std::string &str) : std::string(str) {
557 // Additional initialization or processing can be done here
558 }
559};
560
564enum class ReturnCode {
565 OK = 0,
566 Error,
567 UserCancelled, // This will be returned if a callback passed to the evaluator
568 // signalled cancelation.
569 MissingData
570};
571
572} // namespace ml_core
573} // namespace blace
ml_core::FORWARD_MODE mode
Definition types.h:508
bool operator!=(const InferenceArgsCollection &other) const
Definition types.h:539
ModelInferenceArgs inference_args
Definition types.h:502
bool operator==(const InferenceArgsCollection &other) const
std::optional< SlicedInferenceArgs > sliced_args
Definition types.h:516
std::optional< MultisampleInferenceArgs > multi_args
Definition types.h:512
Definition types.h:547
ModelIdent(const std::string &str)
Definition types.h:556
Definition types.h:207
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:284
bool operator!=(const BlaceHash &rhs) const
Definition types.h:131
bool operator==(const LAB_NORMS &other) const
double l_cent
Definition types.h:139
double ab_norm
Definition types.h:143
double l_norm
Definition types.h:135
int run_threaded
Definition types.h:329
bool operator==(const ModelInferenceArgs &other) const
int seed
Definition types.h:324
int experimental_torchscript_autocast
Definition types.h:348
int gpu_mem_opti
Definition types.h:338
int empty_cache_after_inference
Definition types.h:343
int deprecated
Definition types.h:320
std::vector< Backend > backends
Definition types.h:316
int plot_inputs
Definition types.h:333
bool operator!=(const ModelInferenceArgs &other) const
Definition types.h:371
bool operator==(const MultisampleInferenceArgs &other) const
int parallel
Definition types.h:383
int result_to_input_num
Definition types.h:411
int samples
Definition types.h:387
int allow_mirroring
Definition types.h:391
int max_extension
Definition types.h:403
Interpolation jitter_interpolation
Definition types.h:395
bool operator!=(const MultisampleInferenceArgs &other) const
Definition types.h:438
int jitter_keep_size
Definition types.h:399
int result_to_input_denum
Definition types.h:415
PADDING_MODE padding_mode
Definition types.h:407
int slices
Definition types.h:454
int result_to_input_num
Definition types.h:462
int parallel
Definition types.h:450
int result_to_input_denum
Definition types.h:466
bool operator!=(const SlicedInferenceArgs &other) const
Definition types.h:489
int overlap
Definition types.h:458
bool operator==(const SlicedInferenceArgs &other) const
DIRECTION
Definition types.h:180
constexpr float BYTE_MAX_FLOAT
Definition types.h:34
FORWARD_MODE
Definition types.h:157
std::vector< int64_t > TensorSizes
Definition types.h:21
DataTypeEnum
Definition types.h:59
ReturnCode
Definition types.h:564
Backend
Definition types.h:186
Framework
Definition types.h:202
PADDING_MODE
Definition types.h:175
constexpr float SHORT_MAX
Definition types.h:30
Interpolation
Definition types.h:162
OrderEnum
Definition types.h:74
constexpr int BYTE_MAX
Definition types.h:26
ColorFormatEnum
Definition types.h:105
DeviceEnum
Definition types.h:41
ModelDataType
Definition types.h:126
ValueRangeEnum
Definition types.h:46