forked from frankyeh/UNet-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluate.hpp
More file actions
80 lines (75 loc) · 2.09 KB
/
Copy pathevaluate.hpp
File metadata and controls
80 lines (75 loc) · 2.09 KB
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
75
76
77
78
79
#ifndef EVALUATE_HPP
#define EVALUATE_HPP
#include <string>
#include <vector>
#include "zlib.h"
#include "unet.hpp"
#include "TIPL/tipl.hpp"
struct EvaluateParam{
std::vector<std::string> image_file_name;
torch::Device device = torch::kCPU;
};
struct ProcStrategy{
// preproc
unsigned char output_format = 0;
};
class evaluate_unet{
public:
EvaluateParam param;
public:
ProcStrategy proc_strategy;
std::vector<tipl::ml3d::evalution_set<tipl::image<3>>> eval;
std::vector<bool> data_ready;
std::shared_ptr<std::thread> read_file_thread;
void read_file(void);
void get_result(size_t index);
public:
std::vector<std::string> tissue_names = {"background","white matter","gray matter","cerebellar gray matter","subcortical"};
tipl::image<3,unsigned char> template_I;
tipl::image<3,unsigned short> atlas_I;
tipl::matrix<4,4,float> template_R;
tipl::vector<3> template_vs;
size_t atlas_region_count = 0;
bool load_template(const std::string& file_name)
{
if(!(tipl::io::gz_nifti(file_name,std::ios::in) >> template_I >> template_R >> template_vs
>> [&](const std::string& e){error_msg = e;}))
return false;
// remove csf region
std::replace_if(template_I.begin(),template_I.end(),[](auto v){return v >= 5;},0);
return true;
}
bool load_atlas(const std::string& file_name);
public:
bool aborted = false;
bool running = false;
std::string status,error_msg;
private:
size_t cur_prog = 0;
std::shared_ptr<std::thread> evaluate_thread;
void evaluate(void);
private:
std::shared_ptr<std::thread> output_thread;
void output(void);
public:
size_t cur_output = 0;
void proc_actions(const char* cmd,float param1 = 0.0f,float param2 = 0.0f);
void clear(void)
{
stop();
cur_output = 0;
eval.clear();
}
public:
UNet3d model;
public:
~evaluate_unet(void)
{
stop();
}
void start(void);
void join(void);
void stop(void);
bool save_to_file(size_t index,const char* file_name);
};
#endif // EVALUATE_HPP