@@ -58,10 +58,10 @@ func newSession(backend string, opts ...options.WithOption) (*Session, error) {
5858
5959type pipelineMap [T backends.Pipeline ] map [string ]T
6060
61- func (m pipelineMap [T ]) GetStats () []string {
62- var stats []string
61+ func (m pipelineMap [T ]) GetStatistics () []backends. PipelineStatistics {
62+ var stats []backends. PipelineStatistics
6363 for _ , p := range m {
64- stats = append (stats , p .GetStats () ... )
64+ stats = append (stats , p .GetStatistics () )
6565 }
6666 return stats
6767}
@@ -379,24 +379,33 @@ func (e *pipelineNotFoundError) Error() string {
379379 return fmt .Sprintf ("Pipeline with name %s not found" , e .pipelineName )
380380}
381381
382- // GetStats returns runtime statistics for all initialized pipelines for profiling purposes. We currently record for each pipeline:
382+ // GetStatistics returns runtime statistics for all initialized pipelines for profiling purposes. We currently record for each pipeline:
383383// the total runtime of the tokenization step
384384// the number of batch calls to the tokenization step
385385// the average time per tokenization batch call
386386// the total runtime of the inference (i.e. onnxruntime) step
387387// the number of batch calls to the onnxruntime inference
388388// the average time per onnxruntime inference batch call.
389- func (s * Session ) GetStats () []string {
389+ func (s * Session ) GetStatistics () []backends. PipelineStatistics {
390390 return slices .Concat (
391- s .tokenClassificationPipelines .GetStats (),
392- s .textClassificationPipelines .GetStats (),
393- s .featureExtractionPipelines .GetStats (),
394- s .zeroShotClassificationPipelines .GetStats (),
395- s .crossEncoderPipelines .GetStats (),
396- s .textGenerationPipelines .GetStats (),
391+ s .tokenClassificationPipelines .GetStatistics (),
392+ s .textClassificationPipelines .GetStatistics (),
393+ s .featureExtractionPipelines .GetStatistics (),
394+ s .imageClassificationPipelines .GetStatistics (),
395+ s .zeroShotClassificationPipelines .GetStatistics (),
396+ s .crossEncoderPipelines .GetStatistics (),
397+ s .textGenerationPipelines .GetStatistics (),
397398 )
398399}
399400
401+ // Print prints runtime statistics for all initialized pipelines to stdout.
402+ func (s * Session ) PrintStatistics () {
403+ stats := s .GetStatistics ()
404+ for _ , v := range stats {
405+ v .Print ()
406+ }
407+ }
408+
400409// Destroy deletes the hugot session and onnxruntime environment and all initialized pipelines, freeing memory.
401410// A hugot session should be destroyed when not neeeded any more, preferably with a defer() call.
402411func (s * Session ) Destroy () error {
@@ -408,6 +417,7 @@ func (s *Session) Destroy() error {
408417 s .featureExtractionPipelines = nil
409418 s .tokenClassificationPipelines = nil
410419 s .textClassificationPipelines = nil
420+ s .imageClassificationPipelines = nil
411421 s .zeroShotClassificationPipelines = nil
412422 s .textGenerationPipelines = nil
413423 s .crossEncoderPipelines = nil
0 commit comments