提交 03e0ce2b 编写于 作者: G gineshidalgo99

Added prototxt_path and caffemodel_path flags

上级 4cd459af
......@@ -713,7 +713,7 @@ if (UNIX OR APPLE)
-DCPU_ONLY=${CAFFE_CPU_ONLY}
-DCMAKE_BUILD_TYPE=Release
-DBUILD_docs=OFF
-DBUILD_python=OFF
-DBUILD_python=${BUILD_PYTHON}
-DBUILD_python_layer=OFF
-DUSE_LEVELDB=OFF
-DUSE_LMDB=OFF
......@@ -731,7 +731,7 @@ if (UNIX OR APPLE)
-DCPU_ONLY=${CAFFE_CPU_ONLY}
-DCMAKE_BUILD_TYPE=Release
-DBUILD_docs=OFF
-DBUILD_python=OFF
-DBUILD_python=${BUILD_PYTHON}
-DBUILD_python_layer=OFF
-DUSE_LEVELDB=OFF
-DUSE_LMDB=OFF
......
......@@ -155,6 +155,8 @@ Each flag is divided into flag name, default value, and description.
3. OpenPose
- DEFINE_string(model_folder, "models/", "Folder path (absolute or relative) where the models (pose, face, ...) are located.");
- DEFINE_string(prototxt_path, "", "The combination `--model_folder` + `--prototxt_path` represents the whole path to the prototxt file. If empty, it will use the default OpenPose ProtoTxt file.");
- DEFINE_string(caffemodel_path, "", "The combination `--model_folder` + `--caffemodel_path` represents the whole path to the caffemodel file. If empty, it will use the default OpenPose CaffeModel file.");
- DEFINE_string(output_resolution, "-1x-1", "The image resolution (display and output). Use \"-1x-1\" to force the program to use the input image resolution.");
- DEFINE_int32(num_gpu, -1, "The number of GPU devices to use. If negative, it will use all the available GPUs in your machine.");
- DEFINE_int32(num_gpu_start, 0, "GPU device start number.");
......
......@@ -303,6 +303,7 @@ OpenPose Library - Release Notes
29. Added documentation for Nvidia TX2 with JetPack 3.3.
30. Added Travis build check for several configurations: Ubuntu (14/16)/Mac/Windows and CPU/CUDA/OpenCL and with/without Python.
31. Assigned 755 access to all sh scripts (some of them were only 644).
32. Added the flags `--prototxt_path` and `--caffemodel_path` to allow custom ProtoTxt and CaffeModel paths.
2. Functions or parameters renamed:
1. By default, python example `tutorial_developer/python_2_pose_from_heatmaps.py` was using 2 scales starting at -1x736, changed to 1 scale at -1x368.
2. WrapperStructPose default parameters changed to match those of the OpenPose demo binary.
......
......@@ -73,7 +73,7 @@ int openPoseDemo()
poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScale, FLAGS_part_candidates,
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
enableGoogleLogging};
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
opWrapper.configure(wrapperStructPose);
// Face configuration (use op::WrapperStructFace{} to disable it)
const op::WrapperStructFace wrapperStructFace{
......
......@@ -86,7 +86,7 @@ int tutorialAddModule1()
poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScale, FLAGS_part_candidates,
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
enableGoogleLogging};
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
opWrapperT.configure(wrapperStructPose);
// Face configuration (use op::WrapperStructFace{} to disable it)
const op::WrapperStructFace wrapperStructFace{
......
......@@ -92,7 +92,7 @@ int tutorialApiCpp3()
poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScale, FLAGS_part_candidates,
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
enableGoogleLogging};
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
opWrapper.configure(wrapperStructPose);
// Face configuration (use op::WrapperStructFace{} to disable it)
const op::WrapperStructFace wrapperStructFace{
......
......@@ -227,7 +227,7 @@ int tutorialApiCpp4()
poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScale, FLAGS_part_candidates,
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
enableGoogleLogging};
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
opWrapperT.configure(wrapperStructPose);
// Face configuration (use op::WrapperStructFace{} to disable it)
const op::WrapperStructFace wrapperStructFace{
......
......@@ -169,7 +169,7 @@ int tutorialApiCpp5()
poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScale, FLAGS_part_candidates,
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
enableGoogleLogging};
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
opWrapperT.configure(wrapperStructPose);
// Face configuration (use op::WrapperStructFace{} to disable it)
const op::WrapperStructFace wrapperStructFace{
......
......@@ -137,7 +137,7 @@ int tutorialApiCpp6()
poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScale, FLAGS_part_candidates,
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
enableGoogleLogging};
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
opWrapperT.configure(wrapperStructPose);
// Face configuration (use op::WrapperStructFace{} to disable it)
const op::WrapperStructFace wrapperStructFace{
......
......@@ -173,7 +173,7 @@ int tutorialApiCpp7()
poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScale, FLAGS_part_candidates,
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
enableGoogleLogging};
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
opWrapperT.configure(wrapperStructPose);
// Face configuration (use op::WrapperStructFace{} to disable it)
const op::WrapperStructFace wrapperStructFace{
......
......@@ -185,7 +185,7 @@ int tutorialApiCpp8()
poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScale, FLAGS_part_candidates,
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
enableGoogleLogging};
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
opWrapperT.configure(wrapperStructPose);
// Face configuration (use op::WrapperStructFace{} to disable it)
const op::WrapperStructFace wrapperStructFace{
......
......@@ -284,7 +284,7 @@ int tutorialApiCpp9()
poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScale, FLAGS_part_candidates,
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
enableGoogleLogging};
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
opWrapperT.configure(wrapperStructPose);
// Face configuration (use op::WrapperStructFace{} to disable it)
const op::WrapperStructFace wrapperStructFace{
......
......@@ -60,6 +60,10 @@ DEFINE_bool(frame_undistort, false, "If false (default), it
#endif // OPENPOSE_FLAGS_DISABLE_PRODUCER
// OpenPose
DEFINE_string(model_folder, "models/", "Folder path (absolute or relative) where the models (pose, face, ...) are located.");
DEFINE_string(prototxt_path, "", "The combination `--model_folder` + `--prototxt_path` represents the whole path to the"
" prototxt file. If empty, it will use the default OpenPose ProtoTxt file.");
DEFINE_string(caffemodel_path, "", "The combination `--model_folder` + `--caffemodel_path` represents the whole path to the"
" caffemodel file. If empty, it will use the default OpenPose CaffeModel file.");
DEFINE_string(output_resolution, "-1x-1", "The image resolution (display and output). Use \"-1x-1\" to force the program to use the"
" input image resolution.");
DEFINE_int32(num_gpu, -1, "The number of GPU devices to use. If negative, it will use all the available GPUs in your"
......
......@@ -10,12 +10,13 @@ namespace op
class OP_API PoseExtractorCaffe : public PoseExtractorNet
{
public:
PoseExtractorCaffe(const PoseModel poseModel, const std::string& modelFolder, const int gpuId,
const std::vector<HeatMapType>& heatMapTypes = {},
const ScaleMode heatMapScale = ScaleMode::ZeroToOne,
const bool addPartCandidates = false,
const bool maximizePositives = false,
const bool enableGoogleLogging = true);
PoseExtractorCaffe(
const PoseModel poseModel, const std::string& modelFolder, const int gpuId,
const std::vector<HeatMapType>& heatMapTypes = {},
const ScaleMode heatMapScale = ScaleMode::ZeroToOne,
const bool addPartCandidates = false, const bool maximizePositives = false,
const std::string& protoTxtPath = "", const std::string& caffeModelPath = "",
const bool enableGoogleLogging = true);
virtual ~PoseExtractorCaffe();
......
......@@ -9,33 +9,33 @@ namespace op
return (tPointerContainer != nullptr && tPointerContainer->size() > 0);
}
template<typename TDatums>
template<typename TDatumsSP>
class PointerContainerGreater
{
public:
bool operator() (TDatums& a, TDatums& b)
bool operator() (const TDatumsSP& a, const TDatumsSP& b)
{
if (!b || b->empty())
return true;
else if (!a || a->empty())
return false;
else
return (*a)[0] > (*b)[0];
return *(*a)[0] > *(*b)[0];
}
};
template<typename TDatums>
template<typename TDatumsSP>
class PointerContainerLess
{
public:
bool operator() (TDatums& a, TDatums& b)
bool operator() (const TDatumsSP& a, const TDatumsSP& b)
{
if (!b || b->empty())
return false;
else if (!a || a->empty())
return true;
else
return (*a)[0] < (*b)[0];
return *(*a)[0] < *(*b)[0];
}
};
}
......
......@@ -263,6 +263,7 @@ namespace op
wrapperStructPose.poseModel, modelFolder, gpuId + gpuNumberStart,
wrapperStructPose.heatMapTypes, wrapperStructPose.heatMapScale,
wrapperStructPose.addPartCandidates, wrapperStructPose.maximizePositives,
wrapperStructPose.protoTxtPath, wrapperStructPose.caffeModelPath,
wrapperStructPose.enableGoogleLogging
));
......
......@@ -173,6 +173,20 @@ namespace op
*/
double fpsMax;
/**
* Final path where the pose Caffe ProtoTxt file is located.
* The combination modelFolder + protoTxtPath represents the whole path to the prototxt file.
* If empty, it will use the default OpenPose ProtoTxt file.
*/
std::string protoTxtPath;
/**
* Final path where the pose Caffe CaffeModel is located.
* The combination modelFolder + caffeModelPath represents the whole path to the caffemodel file.
* If empty, it will use the default OpenPose CaffeModel file.
*/
std::string caffeModelPath;
/**
* Whether to internally enable Google Logging.
* This option is only applicable if Caffe is used.
......@@ -198,7 +212,8 @@ namespace op
const std::string& modelFolder = "models/", const std::vector<HeatMapType>& heatMapTypes = {},
const ScaleMode heatMapScale = ScaleMode::ZeroToOne, const bool addPartCandidates = false,
const float renderThreshold = 0.05f, const int numberPeopleMax = -1, const bool maximizePositives = false,
const double fpsMax = -1., const bool enableGoogleLogging = true);
const double fpsMax = -1., const std::string& protoTxtPath = "",
const std::string& caffeModelPath = "", const bool enableGoogleLogging = true);
};
}
......
......@@ -32,6 +32,8 @@ namespace op
const PoseModel mPoseModel;
const int mGpuId;
const std::string mModelFolder;
const std::string mProtoTxtPath;
const std::string mCaffeModelPath;
const bool mEnableGoogleLogging;
// General parameters
std::vector<std::shared_ptr<Net>> spNets;
......@@ -47,11 +49,15 @@ namespace op
std::shared_ptr<caffe::Blob<float>> spPeaksBlob;
std::shared_ptr<caffe::Blob<float>> spMaximumPeaksBlob;
ImplPoseExtractorCaffe(const PoseModel poseModel, const int gpuId,
const std::string& modelFolder, const bool enableGoogleLogging) :
ImplPoseExtractorCaffe(
const PoseModel poseModel, const int gpuId, const std::string& modelFolder,
const std::string& protoTxtPath, const std::string& caffeModelPath,
const bool enableGoogleLogging) :
mPoseModel{poseModel},
mGpuId{gpuId},
mModelFolder{modelFolder},
mProtoTxtPath{protoTxtPath},
mCaffeModelPath{caffeModelPath},
mEnableGoogleLogging{enableGoogleLogging},
spResizeAndMergeCaffe{std::make_shared<ResizeAndMergeCaffe<float>>()},
spNmsCaffe{std::make_shared<NmsCaffe<float>>()},
......@@ -119,23 +125,24 @@ namespace op
}
}
void addCaffeNetOnThread(std::vector<std::shared_ptr<Net>>& net,
std::vector<boost::shared_ptr<caffe::Blob<float>>>& caffeNetOutputBlob,
const PoseModel poseModel, const int gpuId,
const std::string& modelFolder, const bool enableGoogleLogging)
void addCaffeNetOnThread(
std::vector<std::shared_ptr<Net>>& net,
std::vector<boost::shared_ptr<caffe::Blob<float>>>& caffeNetOutputBlob,
const PoseModel poseModel, const int gpuId, const std::string& modelFolder,
const std::string& protoTxtPath, const std::string& caffeModelPath, const bool enableGoogleLogging)
{
try
{
// Add Caffe Net
net.emplace_back(
std::make_shared<NetCaffe>(
modelFolder + getPoseProtoTxt(poseModel),
modelFolder + getPoseTrainedModel(poseModel),
modelFolder + (protoTxtPath.empty() ? getPoseProtoTxt(poseModel) : protoTxtPath),
modelFolder + (caffeModelPath.empty() ? getPoseTrainedModel(poseModel) : caffeModelPath),
gpuId, enableGoogleLogging));
// net.emplace_back(
// std::make_shared<NetOpenCv>(
// modelFolder + getPoseProtoTxt(poseModel),
// modelFolder + getPoseTrainedModel(poseModel),
// modelFolder + (protoTxtPath.empty() ? getPoseProtoTxt(poseModel) : protoTxtPath),
// modelFolder + (caffeModelPath.empty() ? getPoseTrainedModel(poseModel) : caffeModelPath),
// gpuId));
// UNUSED(enableGoogleLogging);
// Initializing them on the thread
......@@ -157,13 +164,15 @@ namespace op
}
#endif
PoseExtractorCaffe::PoseExtractorCaffe(const PoseModel poseModel, const std::string& modelFolder,
const int gpuId, const std::vector<HeatMapType>& heatMapTypes,
const ScaleMode heatMapScale, const bool addPartCandidates,
const bool maximizePositives, const bool enableGoogleLogging) :
PoseExtractorCaffe::PoseExtractorCaffe(
const PoseModel poseModel, const std::string& modelFolder, const int gpuId,
const std::vector<HeatMapType>& heatMapTypes, const ScaleMode heatMapScale, const bool addPartCandidates,
const bool maximizePositives, const std::string& protoTxtPath, const std::string& caffeModelPath,
const bool enableGoogleLogging) :
PoseExtractorNet{poseModel, heatMapTypes, heatMapScale, addPartCandidates, maximizePositives}
#ifdef USE_CAFFE
, upImpl{new ImplPoseExtractorCaffe{poseModel, gpuId, modelFolder, enableGoogleLogging}}
, upImpl{new ImplPoseExtractorCaffe{poseModel, gpuId, modelFolder, protoTxtPath, caffeModelPath,
enableGoogleLogging}}
#endif
{
try
......@@ -201,8 +210,9 @@ namespace op
// Logging
log("Starting initialization on thread.", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// Initialize Caffe net
addCaffeNetOnThread(upImpl->spNets, upImpl->spCaffeNetOutputBlobs, upImpl->mPoseModel,
upImpl->mGpuId, upImpl->mModelFolder, upImpl->mEnableGoogleLogging);
addCaffeNetOnThread(
upImpl->spNets, upImpl->spCaffeNetOutputBlobs, upImpl->mPoseModel, upImpl->mGpuId,
upImpl->mModelFolder, upImpl->mProtoTxtPath, upImpl->mCaffeModelPath, upImpl->mEnableGoogleLogging);
#ifdef USE_CUDA
cudaCheck(__LINE__, __FUNCTION__, __FILE__);
#endif
......@@ -245,8 +255,9 @@ namespace op
const auto numberScales = inputNetData.size();
upImpl->mNetInput4DSizes.resize(numberScales);
while (upImpl->spNets.size() < numberScales)
addCaffeNetOnThread(upImpl->spNets, upImpl->spCaffeNetOutputBlobs, upImpl->mPoseModel,
upImpl->mGpuId, upImpl->mModelFolder, false);
addCaffeNetOnThread(
upImpl->spNets, upImpl->spCaffeNetOutputBlobs, upImpl->mPoseModel, upImpl->mGpuId,
upImpl->mModelFolder, upImpl->mProtoTxtPath, upImpl->mCaffeModelPath, false);
// Process each image
for (auto i = 0u ; i < inputNetData.size(); i++)
......
......@@ -10,7 +10,7 @@ namespace op
const int defaultPartToRender_, const std::string& modelFolder_, const std::vector<HeatMapType>& heatMapTypes_,
const ScaleMode heatMapScale_, const bool addPartCandidates_, const float renderThreshold_,
const int numberPeopleMax_, const bool maximizePositives_, const double fpsMax_,
const bool enableGoogleLogging_) :
const std::string& protoTxtPath_, const std::string& caffeModelPath_, const bool enableGoogleLogging_) :
enable{enable_},
netInputSize{netInputSize_},
outputSize{outputSize_},
......@@ -33,6 +33,8 @@ namespace op
numberPeopleMax{numberPeopleMax_},
maximizePositives{maximizePositives_},
fpsMax{fpsMax_},
protoTxtPath{protoTxtPath_},
caffeModelPath{caffeModelPath_},
enableGoogleLogging{enableGoogleLogging_}
{
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册