12 : ModelName{pset.
get<std::string>(
"ModelName")}
13 ,
InputsName{pset.get<std::vector<std::string>>(
"InputsName")}
14 ,
OutputName{pset.get<std::string>(
"OutputName")}
22 std::cout <<
"Input name error! exit!" << std::endl;
25 std::string GraphFileWithPath;
26 cet::search_path sp(
"FW_SEARCH_PATH");
27 if (!sp.find_file(
ModelName, GraphFileWithPath)) {
29 <<
"In larrecodnn:phot::TFLoaderMLP: Failed to load SavedModel in : " << sp.to_string()
32 std::cout <<
"larrecodnn:phot::TFLoaderMLP Loading TF Model from: " << GraphFileWithPath
34 for (
int i = 0; i < num_input; ++i) {
37 std::cout <<
", Output Layer: " <<
OutputName <<
"\n";
40 modelbundle =
new tensorflow::SavedModelBundleLite();
42 status = tensorflow::LoadSavedModel(tensorflow::SessionOptions(),
43 tensorflow::RunOptions(),
45 {tensorflow::kSavedModelTagServe},
52 <<
"In larrecodnn:phot::TFLoaderMLP: Failed to load SavedModel, status: " 53 <<
status.ToString() << std::endl;
73 std::cout <<
"TF SavedModel loaded successfully." << std::endl;
81 std::cout <<
"Close TF session." << std::endl;
95 int num_input = int(pars.size());
97 std::cout <<
"Input parameter error! exit!" << std::endl;
104 tensorflow::Tensor pos_x(tensorflow::DT_FLOAT, tensorflow::TensorShape({1, 1}));
105 tensorflow::Tensor pos_y(tensorflow::DT_FLOAT, tensorflow::TensorShape({1, 1}));
106 tensorflow::Tensor pos_z(tensorflow::DT_FLOAT, tensorflow::TensorShape({1, 1}));
107 auto dst_x = pos_x.flat<
float>().data();
108 auto dst_y = pos_y.flat<
float>().data();
109 auto dst_z = pos_z.flat<
float>().data();
110 copy_n(pars.begin(), 1, dst_x);
111 copy_n(pars.begin() + 1, 1, dst_y);
112 copy_n(pars.begin() + 2, 1, dst_z);
113 std::vector<std::pair<std::string, tensorflow::Tensor>> inputs = {
116 std::vector<tensorflow::Tensor> outputs;
122 std::cout <<
status.ToString() << std::endl;
127 unsigned int pdr = outputs[0].shape().dim_size(1);
130 for (
unsigned int i = 0; i < pdr; i++) {
131 double value = outputs[0].flat<
float>()(i);
std::vector< double > prediction
T get(std::string const &key) const
TFLoaderMLP(fhicl::ParameterSet const &pset)
General LArSoft Utilities.
std::vector< std::string > InputsName
tensorflow::Status status
tensorflow::SavedModelBundleLite * modelbundle
void Predict(std::vector< double > pars)
cet::coded_exception< error, detail::translate > exception