1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

Merge pull request #28752 from abhishek-gola:net_profiling

Added net profiling support #28752

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Abhishek Gola
2026-05-14 17:17:38 +05:30
committed by GitHub
parent 851e0196b4
commit 873a4635c6
12 changed files with 361 additions and 2 deletions
+42
View File
@@ -545,6 +545,33 @@ CV__DNN_INLINE_NS_BEGIN
virtual void setProg(const std::vector<Ptr<Layer> >& newprog) = 0;
};
/** @brief Single entry in a @ref PerfProfile.
*
* In DNN_PROFILE_DETAILED mode, @p label is "layer_name (type)" and @p count is 1.
* In DNN_PROFILE_SUMMARY mode, @p label is the layer type and @p count is the
* number of layers of that type that contributed to @p timeMs.
*/
struct CV_EXPORTS_W_SIMPLE PerfProfileEntry
{
CV_WRAP PerfProfileEntry() : timeMs(0.0), count(0) {}
CV_PROP_RW String label;
CV_PROP_RW double timeMs;
CV_PROP_RW int count;
};
/** @brief Self-describing snapshot of profiling data from one inference.
*
* Carries the @ref ProfilingMode it was captured in so it can be saved, kept across
* runs (e.g. best-of-N by total time), and printed later via @ref Net::printPerfProfile
* without needing access to the originating @ref Net.
*/
struct CV_EXPORTS_W_SIMPLE PerfProfile
{
CV_WRAP PerfProfile() : mode(DNN_PROFILE_NONE) {}
CV_PROP_RW ProfilingMode mode;
CV_PROP_RW std::vector<PerfProfileEntry> entries;
};
/** @brief This class allows to create and manipulate comprehensive artificial neural networks.
*
* Neural network is presented as directed acyclic graph (DAG), where vertices are Layer instances,
@@ -1027,6 +1054,21 @@ CV__DNN_INLINE_NS_BEGIN
*/
CV_WRAP int64 getPerfProfile(CV_OUT std::vector<double>& timings);
/** @brief Returns profiling data captured during the last forward pass.
*
* Entries are sorted by time in descending order. Empty vectors are returned
* if profiling is disabled (DNN_PROFILE_NONE).
*/
CV_WRAP void getPerfProfile(CV_OUT std::vector<std::string>& names, CV_OUT std::vector<std::string>& timems, CV_OUT std::vector<std::string>& counts) const;
/** @brief Prints the profile captured during the last forward pass in a formatted table using CV_LOG_INFO.
*
* In DNN_PROFILE_DETAILED mode, prints per-layer label, time, and percentage.
* In DNN_PROFILE_SUMMARY mode, prints per-type count, time, and percentage.
* Does nothing if profiling is disabled (DNN_PROFILE_NONE) or all timings are zero.
*/
CV_WRAP void printPerfProfile() const;
// Get the main model graph
Ptr<Graph> getMainGraph() const;