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);
102 const std::vector<tensorflow::Session*>& sessions)
const {
117 std::vector<std::vector<uint>> indexMap(
nModels_);
118 std::vector<std::vector<float>> inputsVectors(nCandidates);
121 LogDebug(
"EgammaDNNHelper") <<
"Working on " << nCandidates <<
" candidates";
125 LogDebug(
"EgammaDNNHelper") <<
"Working on candidate: " << icand;
128 indexMap[model_index].push_back(icand);
129 inputsVectors[icand] =
inputs;
134 std::vector<tensorflow::Tensor> input_tensors(
nModels_);
136 std::vector<float*> input_tensors_pointer(
nModels_);
138 LogDebug(
"EgammaDNNHelper") <<
"Initializing TF input " <<
i <<
" with rows:" <<
counts[
i]
140 input_tensors[
i] = tensorflow::Tensor{tensorflow::DT_FLOAT, {
counts[
i],
nInputs_[
i]}};
141 input_tensors_pointer[
i] = input_tensors[
i].flat<
float>().
data();
146 LogDebug(
"EgammaDNNHelper") <<
"Loading TF input tensor for model: " <<
m;
147 float*
T = input_tensors_pointer[
m];
148 for (
size_t cand_index : indexMap[
m]) {
150 *
T = inputsVectors[cand_index][
k];
157 std::vector<std::pair<uint, std::pair<uint, std::vector<float>>>>
outputs;
162 std::vector<tensorflow::Tensor>
output;
163 LogDebug(
"EgammaDNNHelper") <<
"Run model: " <<
m <<
" with " <<
counts[
m] <<
"objects";
174 LogDebug(
"EgammaDNNHelper") <<
"For Object " <<
b + 1 <<
" : Node " <<
k + 1 <<
" score = " <<
r(
b,
k);
177 const auto cand_index = indexMap[
m][
b];
178 outputs.push_back(std::make_pair(cand_index, std::make_pair(
m,
result)));
183 std::vector<std::pair<uint, std::vector<float>>> final_outputs(
outputs.size());
186 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.