11 const std::vector<std::string>& availableVars)
29 std::vector<tensorflow::Session*> sessions;
35 LogDebug(
"EgammaDNNHelper") <<
"TF sessions started";
42 std::vector<ScalerConfiguration>
features;
45 if (inputfile_scaler.fail()) {
46 throw cms::Exception(
"MissingFile") <<
"Scaler file for PFid DNN not found";
52 while (inputfile_scaler >> varName >> type_str >>
par1 >>
par2) {
53 if (type_str ==
"stdscale")
55 else if (type_str ==
"minmax")
57 else if (type_str ==
"custom1")
63 auto match =
std::find(availableVars.begin(), availableVars.end(), varName);
64 if (match == std::end(availableVars)) {
66 <<
"Requested variable (" << varName <<
") not available between DNN inputs";
71 inputfile_scaler.close();
78 const std::map<std::string, float>&
variables)
const {
98 return std::make_pair(modelIndex,
inputs);
103 const std::vector<tensorflow::Session*>& sessions)
const {
118 std::vector<std::vector<uint>> indexMap(
nModels_);
119 std::vector<std::vector<float>> inputsVectors(nCandidates);
122 LogDebug(
"EgammaDNNHelper") <<
"Working on " << nCandidates <<
" candidates";
126 LogDebug(
"EgammaDNNHelper") <<
"Working on candidate: " << icand;
129 indexMap[model_index].push_back(icand);
130 inputsVectors[icand] =
inputs;
135 std::vector<tensorflow::Tensor> input_tensors(
nModels_);
137 std::vector<float*> input_tensors_pointer(
nModels_);
139 LogDebug(
"EgammaDNNHelper") <<
"Initializing TF input " <<
i <<
" with rows:" <<
counts[
i]
141 input_tensors[
i] = tensorflow::Tensor{tensorflow::DT_FLOAT, {
counts[
i],
nInputs_[
i]}};
142 input_tensors_pointer[
i] = input_tensors[
i].flat<
float>().
data();
147 LogDebug(
"EgammaDNNHelper") <<
"Loading TF input tensor for model: " <<
m;
148 float*
T = input_tensors_pointer[
m];
149 for (
size_t cand_index : indexMap[
m]) {
151 *
T = inputsVectors[cand_index][
k];
158 std::vector<std::pair<uint, std::pair<uint, std::vector<float>>>>
outputs;
163 std::vector<tensorflow::Tensor>
output;
164 LogDebug(
"EgammaDNNHelper") <<
"Run model: " <<
m <<
" with " <<
counts[
m] <<
"objects";
175 LogDebug(
"EgammaDNNHelper") <<
"For Object " <<
b + 1 <<
" : Node " <<
k + 1 <<
" score = " << r(
b,
k);
178 const auto cand_index = indexMap[
m][
b];
179 outputs.push_back(std::make_pair(cand_index, std::make_pair(
m,
result)));
184 std::vector<std::pair<uint, std::vector<float>>> final_outputs(
outputs.size());
187 return final_outputs;
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)
Session * createSession()
char data[epos_bytes_allocation]
const std::string & fullPath() const