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 };
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
185 TORCHSCRIPT_CUDA_FP32,
186 TORCHSCRIPT_CUDA_FP16,
187 TORCHSCRIPT_MPS_FP32,
188 ONNX_CUDA_FP32,
189 ONNX_CUDA_FP16,
190 ONNX_CPU_FP32,
191 TORCHSCRIPT_MPS_FP16,
192 TORCHSCRIPT_CPU_FP32,
193 ONNX_DML_FP32,
194 ONNX_DML_FP16
195};
196
200struct EXPORT_OR_IMPORT BlaceHash {
204 uint64_t hash[4];
205
212 bool operator==(const BlaceHash &rhs) const;
213
220 bool operator!=(const BlaceHash &rhs) const;
221
227 long long to_long_long();
228
235 std::string to_hex(int len = 8);
236
240 friend std::ostream &operator<<(std::ostream &os, const BlaceHash &obj);
241
247
253 BlaceHash(int seed);
254
260 BlaceHash(std::string str);
261
270 BlaceHash(int64_t a, int64_t b, int64_t c, int64_t d);
271
277 std::string print() {
278 std::string returnstring = "";
279 for (int temp = 0; temp < 4; temp++)
280 returnstring += std::to_string(hash[temp]) + "\n";
281 return returnstring;
282 }
283
290 static void mix_string_into_hash(BlaceHash &hash, std::string str);
291
298 static void mix_float_into_hash(BlaceHash &hash, float data);
299};
300
309 std::vector<Backend> backends;
313 int deprecated = true;
317 int seed = 0;
322 int run_threaded = false;
326 int plot_inputs = false;
331 int gpu_mem_opti = false;
337
342
349
356 bool operator==(const ModelInferenceArgs &other) const;
357
364 bool operator!=(const ModelInferenceArgs &other) const {
365 return !(*this == other);
366 }
367};
368
376 int parallel = true;
380 int samples = 1;
388 int jitter_keep_size = false;
396 PADDING_MODE padding_mode = PADDING_MODE::REFLECTION;
405
412
419 bool operator==(const MultisampleInferenceArgs &other) const;
420
427 bool operator!=(const MultisampleInferenceArgs &other) const {
428 return !(*this == other);
429 }
430};
431
439 int parallel = true;
443 int slices = 1;
447 int overlap = 32;
456
463
470 bool operator==(const SlicedInferenceArgs &other) const;
471
478 bool operator!=(const SlicedInferenceArgs &other) const {
479 return !(*this == other);
480 }
481};
482
487public:
497 ml_core::FORWARD_MODE mode = FORWARD_MODE::SIMPLE;
501 std::optional<MultisampleInferenceArgs> multi_args = std::nullopt;
505 std::optional<SlicedInferenceArgs> sliced_args = std::nullopt;
506
513
520 bool operator==(const InferenceArgsCollection &other) const;
521
528 bool operator!=(const InferenceArgsCollection &other) const {
529 return !(*this == other);
530 }
531};
532
536class ModelIdent : public std::string {
537public:
538 using std::string::string;
539
545 ModelIdent(const std::string &str) : std::string(str) {
546 // Additional initialization or processing can be done here
547 }
548};
549
550} // namespace ml_core
551} // namespace blace
ml_core::FORWARD_MODE mode
Definition types.h:497
bool operator!=(const InferenceArgsCollection &other) const
Definition types.h:528
ModelInferenceArgs inference_args
Definition types.h:491
bool operator==(const InferenceArgsCollection &other) const
std::optional< SlicedInferenceArgs > sliced_args
Definition types.h:505
std::optional< MultisampleInferenceArgs > multi_args
Definition types.h:501
Definition types.h:536
ModelIdent(const std::string &str)
Definition types.h:545
Definition types.h:200
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:277
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
int run_threaded
Definition types.h:322
bool operator==(const ModelInferenceArgs &other) const
int seed
Definition types.h:317
int experimental_torchscript_autocast
Definition types.h:341
int gpu_mem_opti
Definition types.h:331
int empty_cache_after_inference
Definition types.h:336
int deprecated
Definition types.h:313
std::vector< Backend > backends
Definition types.h:309
int plot_inputs
Definition types.h:326
bool operator!=(const ModelInferenceArgs &other) const
Definition types.h:364
bool operator==(const MultisampleInferenceArgs &other) const
int parallel
Definition types.h:376
int result_to_input_num
Definition types.h:400
int samples
Definition types.h:380
int max_extension
Definition types.h:392
Interpolation jitter_interpolation
Definition types.h:384
bool operator!=(const MultisampleInferenceArgs &other) const
Definition types.h:427
int jitter_keep_size
Definition types.h:388
int result_to_input_denum
Definition types.h:404
PADDING_MODE padding_mode
Definition types.h:396
int slices
Definition types.h:443
int result_to_input_num
Definition types.h:451
int parallel
Definition types.h:439
int result_to_input_denum
Definition types.h:455
bool operator!=(const SlicedInferenceArgs &other) const
Definition types.h:478
int overlap
Definition types.h:447
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
Backend
Definition types.h:184
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