forked from mingj2021/segment-anything-tensorrt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sam_utils.h
executable file
·74 lines (66 loc) · 2.14 KB
/
sam_utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef SAM_UTILS_H
#define SAM_UTILS_H
#include <NvInfer.h>
#include <NvOnnxConfig.h>
#include <NvOnnxParser.h>
using namespace nvinfer1;
using namespace nvonnxparser;
#undef CHECK
#define CHECK(status) \
do \
{ \
auto ret = (status); \
if (ret != 0) \
{ \
std::cerr << "Cuda failure: " << ret << std::endl; \
abort(); \
} \
} while (0)
void index2srt(nvinfer1::DataType dataType)
{
switch (dataType)
{
case nvinfer1::DataType::kFLOAT:
std::cout << "nvinfer1::DataType::kFLOAT" << std::endl;
break;
case nvinfer1::DataType::kHALF:
std::cout << "nvinfer1::DataType::kHALF" << std::endl;
break;
case nvinfer1::DataType::kINT8:
std::cout << "nvinfer1::DataType::kINT8" << std::endl;
break;
case nvinfer1::DataType::kINT32:
std::cout << "nvinfer1::DataType::kINT32" << std::endl;
break;
case nvinfer1::DataType::kBOOL:
std::cout << "nvinfer1::DataType::kBOOL" << std::endl;
break;
case nvinfer1::DataType::kUINT8:
std::cout << "nvinfer1::DataType::kUINT8" << std::endl;
break;
default:
break;
}
}
void dims2str(nvinfer1::Dims dims)
{
std::string o_s("[");
for (size_t i = 0; i < dims.nbDims; i++)
{
if (i > 0)
o_s += ", ";
o_s += std::to_string(dims.d[i]);
}
o_s += "]";
std::cout << o_s << std::endl;
}
class Logger : public nvinfer1::ILogger
{
void log(Severity severity, const char *msg) noexcept override
{
// suppress info-level messages
if (severity <= Severity::kWARNING)
std::cout << msg << std::endl;
}
} logger;
#endif