11 const std::vector<std::string>& availableVars)
29 std::vector<tensorflow::Session*> sessions;
34 LogDebug(
"EgammaDNNHelper") <<
"TF sessions started";
41 std::vector<ScalerConfiguration>
features;
44 if (inputfile_scaler.fail()) {
45 throw cms::Exception(
"MissingFile") <<
"Scaler file for PFid DNN not found";
51 while (inputfile_scaler >> varName >> type_str >>
par1 >>
par2) {
52 if (type_str ==
"stdscale")
54 else if (type_str ==
"minmax")
56 else if (type_str ==
"custom1")
62 auto match =
std::find(availableVars.begin(), availableVars.end(), varName);
65 <<
"Requested variable (" << varName <<
") not available between DNN inputs";
70 inputfile_scaler.close();
77 const std::map<std::string, float>&
variables)
const {
97 return std::make_pair(modelIndex,
inputs);
101 const std::vector<tensorflow::Session*>& sessions)
const {
116 std::vector<std::vector<int>> indexMap(
nModels_);
117 std::vector<std::vector<float>> inputsVectors(nCandidates);
120 LogDebug(
"EgammaDNNHelper") <<
"Working on " << nCandidates <<
" candidates";
124 LogDebug(
"EgammaDNNHelper") <<
"Working on candidate: " << icand;
127 indexMap[model_index].push_back(icand);
128 inputsVectors[icand] =
inputs;
133 std::vector<tensorflow::Tensor> input_tensors(
nModels_);
135 std::vector<float*> input_tensors_pointer(
nModels_);
137 LogDebug(
"EgammaDNNHelper") <<
"Initializing TF input " <<
i <<
" with rows:" <<
counts[
i]
139 input_tensors[
i] = tensorflow::Tensor{tensorflow::DT_FLOAT, {
counts[
i],
nInputs_[
i]}};
140 input_tensors_pointer[
i] = input_tensors[
i].flat<
float>().
data();
145 LogDebug(
"EgammaDNNHelper") <<
"Loading TF input tensor for model: " <<
m;
146 float*
T = input_tensors_pointer[
m];
147 for (
size_t cand_index : indexMap[
m]) {
149 *
T = inputsVectors[cand_index][
k];
156 std::vector<std::pair<int, std::vector<float>>>
outputs;
161 std::vector<tensorflow::Tensor>
output;
162 LogDebug(
"EgammaDNNHelper") <<
"Run model: " <<
m <<
" with " <<
counts[
m] <<
"objects";
173 LogDebug(
"EgammaDNNHelper") <<
"For Object " <<
b + 1 <<
" : Node " <<
k + 1 <<
" score = " <<
r(
b,
k);
176 const auto cand_index = indexMap[
m][
b];
182 std::vector<std::vector<float>> final_outputs(
outputs.size());
185 return final_outputs;
Session * createSession(SessionOptions &sessionOptions)
std::string fullPath() const
GraphDef * loadGraphDef(const std::string &pbFile)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< float > features(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
char data[epos_bytes_allocation]
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.