Public Member Functions | Private Attributes | List of all members
PointIdAlgTools::PointIdAlgSonicTriton Class Reference
Inheritance diagram for PointIdAlgTools::PointIdAlgSonicTriton:
PointIdAlgTools::IPointIdAlg img::DataProviderAlg

Public Member Functions

 PointIdAlgSonicTriton (fhicl::Table< Config > const &table)
 
std::vector< float > Run (std::vector< std::vector< float >> const &inp2d) const override
 
std::vector< std::vector< float > > Run (std::vector< std::vector< std::vector< float >>> const &inps, int samples=-1) const override
 
- Public Member Functions inherited from PointIdAlgTools::IPointIdAlg
virtual ~IPointIdAlg () noexcept=default
 
float predictIdValue (unsigned int wire, float drift, size_t outIdx=0)
 
std::vector< float > predictIdVector (unsigned int wire, float drift)
 
std::vector< std::vector< float > > predictIdVectors (const std::vector< std::pair< unsigned int, float >> &points)
 
std::vector< std::string > const & outputLabels (void) const
 
bool isInsideFiducialRegion (unsigned int wire, float drift) const
 
- Public Member Functions inherited from img::DataProviderAlg
 DataProviderAlg (const fhicl::ParameterSet &pset)
 
 DataProviderAlg (const Config &config)
 
virtual ~DataProviderAlg ()
 
bool setWireDriftData (const detinfo::DetectorClocksData &clock_data, const detinfo::DetectorPropertiesData &det_prop, const std::vector< recob::Wire > &wires, unsigned int plane, unsigned int tpc, unsigned int cryo)
 
std::vector< float > const & wireData (size_t widx) const
 
std::vector< std::vector< float > > getPatch (size_t wire, float drift, size_t patchSizeW, size_t patchSizeD) const
 
float getPixelOrZero (int wire, int drift) const
 
double getAdcSum () const
 
size_t getAdcArea () const
 
float poolMax (int wire, int drift, size_t r=0) const
 Pool max value in a patch around the wire/drift pixel. More...
 
unsigned int Cryo () const
 Pool sum of pixels in a patch around the wire/drift pixel. More...
 
unsigned int TPC () const
 
unsigned int Plane () const
 
unsigned int NWires () const
 
unsigned int NScaledDrifts () const
 
unsigned int NCachedDrifts () const
 
unsigned int DriftWindow () const
 
float ZeroLevel () const
 Level of zero ADC after scaling. More...
 
double LifetimeCorrection (detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double tick) const
 

Private Attributes

std::string fTritonModelName
 
std::string fTritonURL
 
bool fTritonVerbose
 
std::string fTritonModelVersion
 
unsigned fTritonTimeout
 
unsigned fTritonAllowedTries
 
std::unique_ptr< lartriton::TritonClienttriton_client
 

Additional Inherited Members

- Public Types inherited from img::DataProviderAlg
enum  EDownscaleMode { kMax = 1, kMaxMean = 2, kMean = 3 }
 
- Protected Member Functions inherited from PointIdAlgTools::IPointIdAlg
bool bufferPatch (size_t wire, float drift, std::vector< std::vector< float >> &patch)
 
bool bufferPatch (size_t wire, float drift)
 
void resizePatch (void)
 
- Protected Member Functions inherited from img::DataProviderAlg
std::vector< float > downscaleMax (std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
 
std::vector< float > downscaleMaxMean (std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
 
std::vector< float > downscaleMean (std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
 
std::vector< float > downscale (std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
 
size_t getDriftIndex (float drift) const
 
std::optional< std::vector< float > > setWireData (std::vector< float > const &adc, size_t wireIdx) const
 
bool patchFromDownsampledView (size_t wire, float drift, size_t size_w, size_t size_d, std::vector< std::vector< float >> &patch) const
 
bool patchFromOriginalView (size_t wire, float drift, size_t size_w, size_t size_d, std::vector< std::vector< float >> &patch) const
 
virtual DataProviderAlgView resizeView (detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, size_t wires, size_t drifts)
 
- Protected Attributes inherited from PointIdAlgTools::IPointIdAlg
std::vector< std::stringfNNetOutputs
 
size_t fPatchSizeW
 
size_t fPatchSizeD
 
std::vector< std::vector< float > > fWireDriftPatch
 
size_t fCurrentWireIdx
 
size_t fCurrentScaledDrift
 
- Protected Attributes inherited from img::DataProviderAlg
DataProviderAlgView fAlgView
 
EDownscaleMode fDownscaleMode
 
size_t fDriftWindow
 
bool fDownscaleFullView
 
float fDriftWindowInv
 
calo::CalorimetryAlg fCalorimetryAlg
 
geo::GeometryCore const * fGeometry
 

Detailed Description

Definition at line 12 of file PointIdAlgSonicTriton_tool.cc.

Constructor & Destructor Documentation

PointIdAlgTools::PointIdAlgSonicTriton::PointIdAlgSonicTriton ( fhicl::Table< Config > const &  table)
explicit

Definition at line 32 of file PointIdAlgSonicTriton_tool.cc.

33  : img::DataProviderAlg(table())
34  {
35  // ... Get common config vars
36  fNNetOutputs = table().NNetOutputs();
37  fPatchSizeW = table().PatchSizeW();
38  fPatchSizeD = table().PatchSizeD();
39  fCurrentWireIdx = 99999;
40  fCurrentScaledDrift = 99999;
41 
42  // ... Get "optional" config vars specific to tRTis interface
43  fTritonModelName = table().TritonModelName();
44  fTritonURL = table().TritonURL();
45  fTritonVerbose = table().TritonVerbose();
46  fTritonModelVersion = table().TritonModelVersion();
47  fTritonAllowedTries = table().TritonAllowedTries();
48 
49  // ... Create parameter set for Triton inference client
50  fhicl::ParameterSet TritonPset;
51  TritonPset.put("serverURL",fTritonURL);
52  TritonPset.put("verbose",fTritonVerbose);
53  TritonPset.put("modelName",fTritonModelName);
54  TritonPset.put("modelVersion",fTritonModelVersion);
55  TritonPset.put("timeout",fTritonTimeout);
56  TritonPset.put("allowedTries",fTritonAllowedTries);
57  TritonPset.put("outputs","[]");
58 
59  // ... Create the Triton inference client
60  triton_client = std::make_unique<lartriton::TritonClient>(TritonPset);
61 
62  mf::LogInfo("PointIdAlgSonicTriton") << "url: " << fTritonURL;
63  mf::LogInfo("PointIdAlgSonicTriton") << "model name: " << fTritonModelName;
64  mf::LogInfo("PointIdAlgSonicTriton") << "model version: " << fTritonModelVersion;
65  mf::LogInfo("PointIdAlgSonicTriton") << "verbose: " << fTritonVerbose;
66 
67  mf::LogInfo("PointIdAlgSonicTriton") << "tensorRT inference context created.";
68 
69  resizePatch();
70  }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::vector< std::string > fNNetOutputs
Definition: IPointIdAlg.h:152
std::unique_ptr< lartriton::TritonClient > triton_client
void put(std::string const &key)

Member Function Documentation

std::vector< float > PointIdAlgTools::PointIdAlgSonicTriton::Run ( std::vector< std::vector< float >> const &  inp2d) const
overridevirtual

Implements PointIdAlgTools::IPointIdAlg.

Definition at line 74 of file PointIdAlgSonicTriton_tool.cc.

75  {
76  size_t nrows = inp2d.size();
77 
78  triton_client->setBatchSize(1); // set batch size
79 
80  // ~~~~ Initialize the inputs
81  auto& triton_input = triton_client->input().begin()->second;
82 
83  auto data1 = std::make_shared<lartriton::TritonInput<float>>();
84  data1->reserve(1);
85 
86  // ~~~~ Prepare image for sending to server
87  auto& img = data1->emplace_back();
88  // ..first flatten the 2d array into contiguous 1d block
89  for (size_t ir = 0; ir < nrows; ++ir) {
90  img.insert(img.end(), inp2d[ir].begin(), inp2d[ir].end());
91  }
92 
93  triton_input.toServer(data1); // convert to server format
94 
95  // ~~~~ Send inference request
96  triton_client->dispatch();
97 
98  // ~~~~ Retrieve inference results
99  const auto& triton_output0 = triton_client->output().at("em_trk_none_netout/Softmax");
100  const auto& prob0 = triton_output0.fromServer<float>();
101  auto ncat0 = triton_output0.sizeDims();
102 
103  const auto& triton_output1 = triton_client->output().at("michel_netout/Sigmoid");
104  const auto& prob1 = triton_output1.fromServer<float>();
105  auto ncat1 = triton_output1.sizeDims();
106 
107  std::vector<float> out;
108  out.reserve(ncat0+ncat1);
109  out.insert(out.end(), prob0[0].begin(), prob0[0].end());
110  out.insert(out.end(), prob1[0].begin(), prob1[0].end());
111 
112  triton_client->reset();
113 
114  return out;
115  }
std::unique_ptr< lartriton::TritonClient > triton_client
unsigned nrows(sqlite3 *db, std::string const &tablename)
Definition: helpers.cc:82
std::vector< std::vector< float > > PointIdAlgTools::PointIdAlgSonicTriton::Run ( std::vector< std::vector< std::vector< float >>> const &  inps,
int  samples = -1 
) const
overridevirtual

Implements PointIdAlgTools::IPointIdAlg.

Definition at line 119 of file PointIdAlgSonicTriton_tool.cc.

120  {
121  if ((samples == 0) || inps.empty() || inps.front().empty() || inps.front().front().empty()) {
122  return std::vector<std::vector<float>>();
123  }
124 
125  if ((samples == -1) || (samples > (long long int)inps.size())) { samples = inps.size(); }
126 
127  size_t usamples = samples;
128  size_t nrows = inps.front().size();
129 
130  triton_client->setBatchSize(usamples); // set batch size
131 
132  // ~~~~ Initialize the inputs
133  auto& triton_input = triton_client->input().begin()->second;
134 
135  auto data1 = std::make_shared<lartriton::TritonInput<float>>();
136  data1->reserve(usamples);
137 
138  // ~~~~ For each sample, prepare images for sending to server
139  for (size_t idx = 0; idx < usamples; ++idx) {
140  auto& img = data1->emplace_back();
141  // ..first flatten the 2d array into contiguous 1d block
142  for (size_t ir = 0; ir < nrows; ++ir) {
143  img.insert(img.end(), inps[idx][ir].begin(), inps[idx][ir].end());
144  }
145  }
146  triton_input.toServer(data1); // convert to server format
147 
148  // ~~~~ Send inference request
149  triton_client->dispatch();
150 
151  // ~~~~ Retrieve inference results
152  const auto& triton_output0 = triton_client->output().at("em_trk_none_netout/Softmax");
153  const auto& prob0 = triton_output0.fromServer<float>();
154  auto ncat0 = triton_output0.sizeDims();
155 
156  const auto& triton_output1 = triton_client->output().at("michel_netout/Sigmoid");
157  const auto& prob1 = triton_output1.fromServer<float>();
158  auto ncat1 = triton_output1.sizeDims();
159 
160  std::vector<std::vector<float>> out;
161  out.reserve(usamples);
162  for(unsigned i = 0; i < usamples; i++) {
163  out.emplace_back();
164  auto& img = out.back();
165  img.reserve(ncat0+ncat1);
166  img.insert(img.end(), prob0[i].begin(), prob0[i].end());
167  img.insert(img.end(), prob1[i].begin(), prob1[i].end());
168  }
169 
170  triton_client->reset();
171 
172  return out;
173  }
std::unique_ptr< lartriton::TritonClient > triton_client
unsigned nrows(sqlite3 *db, std::string const &tablename)
Definition: helpers.cc:82

Member Data Documentation

unsigned PointIdAlgTools::PointIdAlgSonicTriton::fTritonAllowedTries
private

Definition at line 26 of file PointIdAlgSonicTriton_tool.cc.

std::string PointIdAlgTools::PointIdAlgSonicTriton::fTritonModelName
private

Definition at line 21 of file PointIdAlgSonicTriton_tool.cc.

std::string PointIdAlgTools::PointIdAlgSonicTriton::fTritonModelVersion
private

Definition at line 24 of file PointIdAlgSonicTriton_tool.cc.

unsigned PointIdAlgTools::PointIdAlgSonicTriton::fTritonTimeout
private

Definition at line 25 of file PointIdAlgSonicTriton_tool.cc.

std::string PointIdAlgTools::PointIdAlgSonicTriton::fTritonURL
private

Definition at line 22 of file PointIdAlgSonicTriton_tool.cc.

bool PointIdAlgTools::PointIdAlgSonicTriton::fTritonVerbose
private

Definition at line 23 of file PointIdAlgSonicTriton_tool.cc.

std::unique_ptr<lartriton::TritonClient> PointIdAlgTools::PointIdAlgSonicTriton::triton_client
private

Definition at line 28 of file PointIdAlgSonicTriton_tool.cc.


The documentation for this class was generated from the following file: