Skip to content

Commit

Permalink
Adding an option to control the smoothing weights for each model para…
Browse files Browse the repository at this point in the history
…meter (#188)

Summary: Pull Request resolved: #188

Reviewed By: jeongseok-meta

Differential Revision: D68493913

fbshipit-source-id: 480f99dbf01e3e579a9c759fccb2f2bf310f1664
  • Loading branch information
Sanjeev Kumar authored and facebook-github-bot committed Jan 24, 2025
1 parent a67e3f1 commit d53c1d5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
12 changes: 11 additions & 1 deletion momentum/marker_tracking/marker_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,17 @@ Eigen::MatrixXf trackSequence(
}

// add a smoothness constraint in parameter space
if (config.smoothing != 0) {
if (!config.smoothingWeights.cols()) {
// If per parameter weights are provided override the default weight
MT_CHECK(
config.smoothingWeights.cols() == character.parameterTransform.numAllModelParameters(),
"Smoothing weights vector should be equal to the number of model parameters {} vs {}",
config.smoothingWeights.cols(),
character.parameterTransform.numAllModelParameters());
auto smoothConstrFunc = std::make_shared<ModelParametersSequenceErrorFunction>(character);
smoothConstrFunc->setTargetWeights(config.smoothingWeights);
solverFunc.addSequenceErrorFunction(kAllFrames, smoothConstrFunc);
} else if (config.smoothing != 0) {
auto smoothConstrFunc = std::make_shared<ModelParametersSequenceErrorFunction>(character);
smoothConstrFunc->setWeight(config.smoothing);
solverFunc.addSequenceErrorFunction(kAllFrames, smoothConstrFunc);
Expand Down
3 changes: 3 additions & 0 deletions momentum/marker_tracking/marker_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ struct TrackingConfig : public BaseConfig {
float smoothing = 0;
/// The weight for the collision error function.
float collisionErrorWeight = 0.0;
/// Smoothing weights per model parameter. The size of this vector should be equal to number of
/// model parameters and this overrides the value specific in smoothing
Eigen::VectorXf smoothingWeights{};
};

/// Configuration for refining an already tracked motion, eg. add smoothing and/or collision
Expand Down
14 changes: 11 additions & 3 deletions pymomentum/marker_tracking/marker_tracking_pybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,27 @@ PYBIND11_MODULE(marker_tracking, m) {

trackingConfig.def(py::init<>())
.def(
py::init<float, float, size_t, bool, float, float>(),
py::init<float, float, size_t, bool, float, float, Eigen::VectorXf>(),
py::arg("min_vis_percent") = 0.0,
py::arg("loss_alpha") = 2.0,
py::arg("max_iter") = 30,
py::arg("debug") = false,
py::arg("smoothing") = 0.0,
py::arg("collision_error_weight") = 0.0)
py::arg("collision_error_weight") = 0.0,
py::arg("smoothing_weights") = Eigen::VectorXf())
.def_readwrite(
"smoothing",
&marker_tracking::TrackingConfig::smoothing,
"Smoothing weight; 0 to disable")
.def_readwrite(
"collision_error_weight",
&marker_tracking::TrackingConfig::collisionErrorWeight,
"Collision error weight; 0 to disable");
"Collision error weight; 0 to disable")
.def_readwrite(
"smoothing_weights",
&marker_tracking::TrackingConfig::smoothingWeights,
R"(Smoothing weights per model parameter. The size of this vector should be
equal to number of model parameters and this overrides the value specific in smoothing)");

auto refineConfig = py::
class_<marker_tracking::RefineConfig, marker_tracking::TrackingConfig>(
Expand All @@ -125,6 +131,7 @@ PYBIND11_MODULE(marker_tracking, m) {
bool,
float,
float,
Eigen::VectorXf,
float,
bool,
bool>(),
Expand All @@ -134,6 +141,7 @@ PYBIND11_MODULE(marker_tracking, m) {
py::arg("debug") = false,
py::arg("smoothing") = 0.0,
py::arg("collision_error_weight") = 0.0,
py::arg("smoothing_weights") = Eigen::VectorXf(),
py::arg("regularizer") = 0.0,
py::arg("calib_id") = false,
py::arg("calib_locators") = false)
Expand Down

0 comments on commit d53c1d5

Please sign in to comment.