-
Notifications
You must be signed in to change notification settings - Fork 67
/
tf_inference.h
66 lines (55 loc) · 1.79 KB
/
tf_inference.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
#ifndef TF_INFERENCE_H
#define TF_INFERENCE_H
#include "itkImage.h"
#include "itkIntensityWindowingImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkResampleImageFilter.h"
#include "itkExtractImageFilter.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkDivideImageFilter.h"
#include "itkBSplineInterpolateImageFunction.h"
#include "itkNearestNeighborInterpolateImageFunction.h"
#include "itkCastImageFilter.h"
#include "itkAddImageFilter.h"
#include "tensorflow/core/public/session.h"
#include "tensorflow/core/public/session_options.h"
#include "tensorflow/core/protobuf/meta_graph.pb.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include <thread>
#include <future>
#include <mutex>
#include "ThreadPool.h"
#include <sstream>
#include <iostream>
typedef itk::Image<float, 3> ImageType;
typedef itk::Image<short, 3> LabelImageType;
class TF_Inference
{
public:
TF_Inference();
~TF_Inference();
void SetImage(ImageType::Pointer);
LabelImageType::Pointer GetOutput();
void SetGraphPath(std::string);
void SetCheckpointPath(std::string);
void SetNumberOfThreads(unsigned int);
void SetBufferPoolSize(unsigned int);
void Inference();
private:
std::string m_graphPath;
std::string m_checkpointPath;
ImageType::Pointer m_inputImage;
LabelImageType::Pointer m_outputImage;
tensorflow::Session* m_sess;
tensorflow::SessionOptions m_options;
tensorflow::GraphDef* m_graphDef;
int m_patchSize[3] = { 64,64,32 };
int m_stride[3] = { 64,64,32 };
int m_batchSize = 1;
void BatchInference(ImageType::Pointer, LabelImageType::Pointer, std::vector<std::shared_ptr<int>>);
//void CropWithIndicies(ImageType::Pointer, ImageType::Pointer, int*);
// threaded batch inference
int m_numberOfThreads = std::thread::hardware_concurrency();
int m_bufferPoolSize = 6;
};
#endif