From c42443f6f9b8173d20173eaedf41b4e30f37f4ef Mon Sep 17 00:00:00 2001 From: gineshidalgo99 Date: Fri, 13 Oct 2017 11:51:30 -0400 Subject: [PATCH] Profiler working again --- include/openpose/pose/poseParameters.hpp | 34 +++++++++++++---------- src/openpose/core/netCaffe.cpp | 4 +-- src/openpose/filestream/cocoJsonSaver.cpp | 9 ++++-- src/openpose/utilities/profiler.cpp | 12 ++++---- 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/include/openpose/pose/poseParameters.hpp b/include/openpose/pose/poseParameters.hpp index ab2424f7..0035f77b 100644 --- a/include/openpose/pose/poseParameters.hpp +++ b/include/openpose/pose/poseParameters.hpp @@ -7,7 +7,7 @@ namespace op { - // #define when needed in CUDA code + // All #define are for CUDA code // Constant Global Parameters const unsigned int POSE_MAX_PEOPLE = 96u; @@ -206,31 +206,35 @@ namespace op {22, "LEar"}, {23, "Background"} }; - const unsigned int POSE_BODY_23_NUMBER_PARTS = 22u; // Equivalent to size of std::map POSE_BODY_23_BODY_PARTS - 1 (removing background) + const unsigned int POSE_BODY_23_NUMBER_PARTS = 23u; // Equivalent to size of std::map POSE_BODY_23_BODY_PARTS - 1 (removing background) const std::vector POSE_BODY_23_MAP_IDX {24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71}; - #define POSE_BODY_23_PAIRS_RENDER_GPU { 0,1, 0,4, 1,2, 2,3, 4,5, 5,6, 0,7, 7,8, 7,13, 8,9, 9,10,10,11,10,12,13,14,14,15,15,16,15,17, 0,18,18,19,18,21,19,20,21,22} + #define POSE_BODY_23_PAIRS_RENDER_GPU { 0,1, 0,4, 1,2, 2,3, 4,5, 5,6, 0,7, 7,8, 7,13, 8,9, 9,10,10,11,11,12,13,14,14,15,15,16,16,17, 0,18,18,19,18,21,19,20,21,22} const std::vector POSE_BODY_23_PAIRS_RENDER {POSE_BODY_23_PAIRS_RENDER_GPU}; const std::vector POSE_BODY_23_PAIRS { 0,1, 0,4, 1,2, 2,3, 4,5, 5,6, 0,7, 7,8, 7,13, 8,9, 9,10,10,11,10,12,13,14,14,15,15,16,15,17, 0,18,18,19,18,21,19,20,21,22, 1,20, 4,22}; #define POSE_BODY_23_COLORS_RENDER_GPU \ - 255.f, 0.f, 85.f, \ 255.f, 0.f, 0.f, \ - 255.f, 85.f, 0.f, \ - 255.f, 170.f, 0.f, \ + 255.f, 55.f, 0.f, \ + 255.f, 110.f, 0.f, \ + 255.f, 165.f, 0.f, \ + 255.f, 215.f, 0.f, \ + 255.f, 235.f, 0.f, \ 255.f, 255.f, 0.f, \ - 170.f, 255.f, 0.f, \ + 255.f, 0.f, 0.f, \ + 175.f, 255.f, 0.f, \ 85.f, 255.f, 0.f, \ 0.f, 255.f, 0.f, \ - 255.f, 0.f, 0.f, \ 0.f, 255.f, 85.f, \ 0.f, 255.f, 170.f, \ - 0.f, 255.f, 255.f, \ - 0.f, 170.f, 255.f, \ + 25.f, 25.f, 128.f, \ 0.f, 85.f, 255.f, \ - 0.f, 0.f, 255.f, \ - 255.f, 0.f, 170.f, \ - 170.f, 0.f, 255.f, \ + 0.f, 170.f, 255.f, \ + 0.f, 212.5f, 255.f, \ + 0.f, 255.f, 255.f, \ + 255.f, 0.f, 0.f, \ 255.f, 0.f, 255.f, \ - 85.f, 0.f, 255.f + 238.f, 130.f, 238.f, \ + 138.f, 43.f, 226.f, \ + 75.f, 0.f, 130.f const std::vector POSE_BODY_23_COLORS_RENDER{POSE_BODY_23_COLORS_RENDER_GPU}; // Constant Array Parameters @@ -269,7 +273,7 @@ namespace op "pose/mpi/pose_iter_160000.caffemodel", "pose/body_18/pose_iter_XXXXXX.caffemodel", "pose/body_19/pose_iter_XXXXXX.caffemodel", - "pose/body_23/pose_iter_42000.caffemodel" + "pose/body_23/pose_iter_XXXXXX.caffemodel" }; // POSE_BODY_PART_MAPPING crashes on Windows at dynamic initialization, to avoid this crash: // POSE_BODY_PART_MAPPING has been moved to poseParameters.cpp and getPoseBodyPartMapping() wraps it diff --git a/src/openpose/core/netCaffe.cpp b/src/openpose/core/netCaffe.cpp index 8a1c2f62..7a9d7aa7 100644 --- a/src/openpose/core/netCaffe.cpp +++ b/src/openpose/core/netCaffe.cpp @@ -11,7 +11,7 @@ namespace op { - std::mutex sMutex; + std::mutex sMutexNetCaffe; std::atomic sGoogleLoggingInitialized{false}; struct NetCaffe::ImplNetCaffe @@ -51,7 +51,7 @@ namespace op // Double if condition in order to speed up the program if it is called several times if (enableGoogleLogging && !sGoogleLoggingInitialized) { - std::lock_guard lock{sMutex}; + std::lock_guard lock{sMutexNetCaffe}; if (enableGoogleLogging && !sGoogleLoggingInitialized) { google::InitGoogleLogging("OpenPose"); diff --git a/src/openpose/filestream/cocoJsonSaver.cpp b/src/openpose/filestream/cocoJsonSaver.cpp index 32ad8516..0b1ab3f4 100644 --- a/src/openpose/filestream/cocoJsonSaver.cpp +++ b/src/openpose/filestream/cocoJsonSaver.cpp @@ -64,11 +64,14 @@ namespace op mJsonOfstream.arrayOpen(); std::vector indexesInCocoOrder; if (numberBodyParts == 18) - indexesInCocoOrder = std::vector{0, 15, 14, 17, 16, 5, 2, 6, 3, 7, 4, 11, 8, 12, 9, 13, 10}; + indexesInCocoOrder = std::vector{0, 15,14,17,16, 5,2,6,3,7, 4,11,8,12, 9, 13,10}; else if (numberBodyParts == 19) - indexesInCocoOrder = std::vector{0, 16, 15, 18, 17, 5, 2, 6, 3, 7, 4, 12, 9, 13, 10, 14, 11}; + indexesInCocoOrder = std::vector{0, 16,15,18,17, 5,2,6,3,7, 4,12,9,13,10, 14,11}; + else if (numberBodyParts == 23) + indexesInCocoOrder = std::vector{18,21,19,22,20, 4,1,5,2,6, 3,13,8,14, 9, 15,10}; else - error("Unvalid number of body parts (" + std::to_string(numberBodyParts) + ").", __LINE__, __FUNCTION__, __FILE__); + error("Unvalid number of body parts (" + std::to_string(numberBodyParts) + ").", + __LINE__, __FUNCTION__, __FILE__); for (auto bodyPart = 0u ; bodyPart < indexesInCocoOrder.size() ; bodyPart++) { const auto finalIndex = 3*(person*numberBodyParts + indexesInCocoOrder.at(bodyPart)); diff --git a/src/openpose/utilities/profiler.cpp b/src/openpose/utilities/profiler.cpp index a72443f5..af6cc8ae 100644 --- a/src/openpose/utilities/profiler.cpp +++ b/src/openpose/utilities/profiler.cpp @@ -17,7 +17,7 @@ namespace op std::map> sProfilerTuple{ std::map>() }; - std::mutex sMutex{}; + std::mutex sMutexProfiler{}; std::string getKey(const int line, const std::string& function, const std::string& file) { @@ -37,7 +37,7 @@ namespace op { #ifdef PROFILER_ENABLED const auto key = getKey(line, function, file); - std::unique_lock lock{sMutex}; + std::unique_lock lock{sMutexProfiler}; if (sProfilerTuple.count(key) > 0) std::get<2>(sProfilerTuple[key]) = std::chrono::high_resolution_clock::now(); else @@ -55,7 +55,7 @@ namespace op void Profiler::timerEnd(const std::string& key) { #ifdef PROFILER_ENABLED - const std::lock_guard lock{sMutex}; + const std::lock_guard lock{sMutexProfiler}; if (sProfilerTuple.count(key) > 0) { auto tuple = sProfilerTuple[key]; @@ -77,7 +77,7 @@ namespace op void Profiler::printAveragedTimeMsOnIterationX(const std::string& key, const int line, const std::string& function, const std::string& file, const unsigned long long x) { #ifdef PROFILER_ENABLED - std::unique_lock lock{sMutex}; + std::unique_lock lock{sMutexProfiler}; if (sProfilerTuple.count(key) > 0) { const auto tuple = sProfilerTuple[key]; @@ -101,7 +101,7 @@ namespace op void Profiler::printAveragedTimeMsEveryXIterations(const std::string& key, const int line, const std::string& function, const std::string& file, const unsigned long long x) { #ifdef PROFILER_ENABLED - std::unique_lock lock{sMutex}; + std::unique_lock lock{sMutexProfiler}; if (sProfilerTuple.count(key) > 0) { const auto tuple = sProfilerTuple[key]; @@ -111,7 +111,7 @@ namespace op printAveragedTimeMsCommon(std::get<0>(tuple), std::get<1>(tuple), line, function, file); // Reset - const std::lock_guard lock{sMutex}; + const std::lock_guard lock{sMutexProfiler}; auto& tuple = sProfilerTuple[key]; std::get<0>(tuple) = 0.; std::get<1>(tuple) = 0;