CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
deep_tau::DeepTauCache Class Reference

#include <DeepTauBase.h>

Public Types

using GraphPtr = std::shared_ptr< tensorflow::GraphDef >
 

Public Member Functions

 DeepTauCache (const std::string &graph_name, bool mem_mapped)
 
const tensorflow::GraphDef & getGraph () const
 
tensorflow::Session & getSession () const
 
 ~DeepTauCache ()
 

Private Attributes

GraphPtr graph_
 
std::unique_ptr< tensorflow::MemmappedEnv > memmappedEnv_
 
tensorflow::Session * session_
 

Detailed Description

Definition at line 40 of file DeepTauBase.h.

Member Typedef Documentation

using deep_tau::DeepTauCache::GraphPtr = std::shared_ptr<tensorflow::GraphDef>

Definition at line 42 of file DeepTauBase.h.

Constructor & Destructor Documentation

deep_tau::DeepTauCache::DeepTauCache ( const std::string &  graph_name,
bool  mem_mapped 
)

Definition at line 120 of file DeepTauBase.cc.

References tensorflow::createSession(), Default, tensorflow::loadGraphDef(), AlcaSiPixelAliHarvester0T_cff::options, tensorflow::setThreading(), and btagGenBb_cfi::Status.

121 {
122  tensorflow::SessionOptions options;
123  tensorflow::setThreading(options, 1, "no_threads");
124 
125  if(mem_mapped) {
126  memmappedEnv_ = std::make_unique<tensorflow::MemmappedEnv>(tensorflow::Env::Default());
127  const tensorflow::Status mmap_status = memmappedEnv_.get()->InitializeFromFile(graph_name);
128  if(!mmap_status.ok())
129  throw cms::Exception("DeepTauCache: unable to initalize memmapped environment for ") << graph_name << ". \n"
130  << mmap_status.ToString();
131 
132  graph_ = std::make_unique<tensorflow::GraphDef>();
133  const tensorflow::Status load_graph_status = ReadBinaryProto(memmappedEnv_.get(),
134  tensorflow::MemmappedFileSystem::kMemmappedPackageDefaultGraphDef,
135  graph_.get());
136  if(!load_graph_status.ok())
137  throw cms::Exception("DeepTauCache: unable to load graph_ from ") << graph_name << ". \n"
138  << mmap_status.ToString();
139  options.config.mutable_graph_options()->mutable_optimizer_options()->set_opt_level(::tensorflow::OptimizerOptions::L0);
140  options.env = memmappedEnv_.get();
141 
143 
144  } else {
145  graph_.reset(tensorflow::loadGraphDef(graph_name));
147  }
148 }
Session * createSession(SessionOptions &sessionOptions)
Definition: TensorFlow.cc:87
#define Default
Definition: vmac.h:110
std::unique_ptr< tensorflow::MemmappedEnv > memmappedEnv_
Definition: DeepTauBase.h:55
GraphDef * loadGraphDef(const std::string &pbFile)
Definition: TensorFlow.cc:68
tensorflow::Session * session_
Definition: DeepTauBase.h:54
void setThreading(SessionOptions &sessionOptions, int nThreads, const std::string &singleThreadPool="no_threads")
Definition: TensorFlow.cc:19
deep_tau::DeepTauCache::~DeepTauCache ( )

Definition at line 150 of file DeepTauBase.cc.

References tensorflow::closeSession().

151 {
153 }
tensorflow::Session * session_
Definition: DeepTauBase.h:54
bool closeSession(Session *&session)
Definition: TensorFlow.cc:193

Member Function Documentation

const tensorflow::GraphDef& deep_tau::DeepTauCache::getGraph ( ) const
inline

Definition at line 50 of file DeepTauBase.h.

Referenced by DPFIsolation::DPFIsolation().

50 { return *graph_; }
tensorflow::Session& deep_tau::DeepTauCache::getSession ( ) const
inline

Definition at line 49 of file DeepTauBase.h.

Referenced by DPFIsolation::getPredictions().

49 { return *session_; }
tensorflow::Session * session_
Definition: DeepTauBase.h:54

Member Data Documentation

GraphPtr deep_tau::DeepTauCache::graph_
private

Definition at line 53 of file DeepTauBase.h.

std::unique_ptr<tensorflow::MemmappedEnv> deep_tau::DeepTauCache::memmappedEnv_
private

Definition at line 55 of file DeepTauBase.h.

tensorflow::Session* deep_tau::DeepTauCache::session_
private

Definition at line 54 of file DeepTauBase.h.