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::map< std::string, std::string > &graph_names, bool mem_mapped)
 
const tensorflow::GraphDef & getGraph (const std::string &name="") const
 
tensorflow::Session & getSession (const std::string &name="") const
 
 ~DeepTauCache ()
 

Private Attributes

std::map< std::string, GraphPtrgraphs_
 
std::map< std::string, std::unique_ptr< tensorflow::MemmappedEnv > > memmappedEnv_
 
std::map< std::string, tensorflow::Session * > sessions_
 

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::map< std::string, std::string > &  graph_names,
bool  mem_mapped 
)

Definition at line 139 of file DeepTauBase.cc.

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

140 {
141  for(const auto& graph_entry : graph_names) {
142  tensorflow::SessionOptions options;
143  tensorflow::setThreading(options, 1, "no_threads");
144 
145  const std::string& entry_name = graph_entry.first;
146  const std::string& graph_file = graph_entry.second;
147  if(mem_mapped) {
148  memmappedEnv_[entry_name] = std::make_unique<tensorflow::MemmappedEnv>(tensorflow::Env::Default());
149  const tensorflow::Status mmap_status = memmappedEnv_.at(entry_name)->InitializeFromFile(graph_file);
150  if(!mmap_status.ok()) {
151  throw cms::Exception("DeepTauCache: unable to initalize memmapped environment for ")
152  << graph_file << ". \n" << mmap_status.ToString();
153  }
154 
155  graphs_[entry_name] = std::make_unique<tensorflow::GraphDef>();
156  const tensorflow::Status load_graph_status = ReadBinaryProto(memmappedEnv_.at(entry_name).get(),
157  tensorflow::MemmappedFileSystem::kMemmappedPackageDefaultGraphDef,
158  graphs_.at(entry_name).get());
159  if(!load_graph_status.ok())
160  throw cms::Exception("DeepTauCache: unable to load graph from ") << graph_file << ". \n"
161  << mmap_status.ToString();
162  options.config.mutable_graph_options()->mutable_optimizer_options()->set_opt_level(::tensorflow::OptimizerOptions::L0);
163  options.env = memmappedEnv_.at(entry_name).get();
164 
165  sessions_[entry_name] = tensorflow::createSession(graphs_.at(entry_name).get(), options);
166 
167  } else {
168  graphs_[entry_name].reset(tensorflow::loadGraphDef(graph_file));
169  sessions_[entry_name] = tensorflow::createSession(graphs_.at(entry_name).get(), options);
170  }
171  }
172 }
Session * createSession(SessionOptions &sessionOptions)
Definition: TensorFlow.cc:87
#define Default
Definition: vmac.h:110
std::map< std::string, tensorflow::Session * > sessions_
Definition: DeepTauBase.h:54
GraphDef * loadGraphDef(const std::string &pbFile)
Definition: TensorFlow.cc:68
void setThreading(SessionOptions &sessionOptions, int nThreads, const std::string &singleThreadPool="no_threads")
Definition: TensorFlow.cc:19
std::map< std::string, GraphPtr > graphs_
Definition: DeepTauBase.h:53
std::map< std::string, std::unique_ptr< tensorflow::MemmappedEnv > > memmappedEnv_
Definition: DeepTauBase.h:55
deep_tau::DeepTauCache::~DeepTauCache ( )

Definition at line 174 of file DeepTauBase.cc.

References tensorflow::closeSession().

175 {
176  for(auto& session_entry : sessions_)
177  tensorflow::closeSession(session_entry.second);
178 }
std::map< std::string, tensorflow::Session * > sessions_
Definition: DeepTauBase.h:54
bool closeSession(Session *&session)
Definition: TensorFlow.cc:193

Member Function Documentation

const tensorflow::GraphDef& deep_tau::DeepTauCache::getGraph ( const std::string &  name = "") const
inline

Definition at line 50 of file DeepTauBase.h.

References dataset::name.

50 { return *graphs_.at(name); }
std::map< std::string, GraphPtr > graphs_
Definition: DeepTauBase.h:53
tensorflow::Session& deep_tau::DeepTauCache::getSession ( const std::string &  name = "") const
inline

Definition at line 49 of file DeepTauBase.h.

References dataset::name.

49 { return *sessions_.at(name); }
std::map< std::string, tensorflow::Session * > sessions_
Definition: DeepTauBase.h:54

Member Data Documentation

std::map<std::string, GraphPtr> deep_tau::DeepTauCache::graphs_
private

Definition at line 53 of file DeepTauBase.h.

std::map<std::string, std::unique_ptr<tensorflow::MemmappedEnv> > deep_tau::DeepTauCache::memmappedEnv_
private

Definition at line 55 of file DeepTauBase.h.

std::map<std::string, tensorflow::Session*> deep_tau::DeepTauCache::sessions_
private

Definition at line 54 of file DeepTauBase.h.