-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using dynamic number of labels #56
Open
RozDavid
wants to merge
5
commits into
MIT-SPARK:master
Choose a base branch
from
RozDavid:dynamic_labels
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -47,6 +47,7 @@ | |||||
|
||||||
#include <voxblox/integrator/tsdf_integrator.h> | ||||||
#include <voxblox/utils/timing.h> | ||||||
#include <iostream> | ||||||
|
||||||
#include "kimera_semantics/color.h" | ||||||
#include "kimera_semantics/common.h" | ||||||
|
@@ -105,20 +106,23 @@ void SemanticIntegratorBase::setSemanticProbabilities() { | |||||
<< "Your probabilities do not make sense... The likelihood of a " | ||||||
"label, knowing that we have measured that label, should not be" | ||||||
"smaller than the likelihood of seeing another label!"; | ||||||
semantic_log_likelihood_ = | ||||||
semantic_log_likelihood_.Constant(log_non_match_probability_); | ||||||
semantic_log_likelihood_.resize(semantic_config_.total_number_of_labels_, semantic_config_.total_number_of_labels_); | ||||||
semantic_log_likelihood_.setConstant(log_non_match_probability_); | ||||||
semantic_log_likelihood_.diagonal() = | ||||||
semantic_log_likelihood_.diagonal().Constant(log_match_probability_); | ||||||
semantic_log_likelihood_.diagonal().setConstant(log_match_probability_); | ||||||
|
||||||
// TODO(Toni): sanity checks, set as DCHECK_EQ. | ||||||
CHECK_NEAR(semantic_log_likelihood_.diagonal().sum(), | ||||||
kTotalNumberOfLabels * log_match_probability_, | ||||||
100 * vxb::kFloatEpsilon); | ||||||
semantic_config_.total_number_of_labels_ * log_match_probability_, | ||||||
10e-2); | ||||||
|
||||||
|
||||||
CHECK_NEAR( | ||||||
semantic_log_likelihood_.sum(), | ||||||
kTotalNumberOfLabels * log_match_probability_ + | ||||||
std::pow(kTotalNumberOfLabels, 2) * log_non_match_probability_ - | ||||||
kTotalNumberOfLabels * log_non_match_probability_, | ||||||
1000 * vxb::kFloatEpsilon); | ||||||
semantic_config_.total_number_of_labels_ * log_match_probability_ + | ||||||
std::pow(semantic_config_.total_number_of_labels_, 2) * log_non_match_probability_ - | ||||||
semantic_config_.total_number_of_labels_ * log_non_match_probability_, | ||||||
10e-2); | ||||||
} | ||||||
|
||||||
// TODO(Toni): Complete this function!! | ||||||
|
@@ -155,14 +159,17 @@ void SemanticIntegratorBase::updateSemanticVoxel( | |||||
updateSemanticVoxelProbabilities(measurement_frequencies, | ||||||
&semantic_voxel->semantic_priors); | ||||||
|
||||||
|
||||||
// Get MLE semantic label. | ||||||
calculateMaximumLikelihoodLabel(semantic_voxel->semantic_priors, | ||||||
&semantic_voxel->semantic_label); | ||||||
|
||||||
|
||||||
// Colorize according to current MLE semantic label. | ||||||
updateSemanticVoxelColor(semantic_voxel->semantic_label, | ||||||
&semantic_voxel->color); | ||||||
|
||||||
|
||||||
// Actually change the color of the TSDF voxel so we do not need to change a | ||||||
// single line for the meshing with respect to Voxblox. | ||||||
switch (semantic_config_.color_mode) { | ||||||
|
@@ -185,7 +192,8 @@ void SemanticIntegratorBase::updateSemanticVoxel( | |||||
} | ||||||
//////////////////////////////////////////////////////////////////////////// | ||||||
//} | ||||||
} | ||||||
|
||||||
} | ||||||
|
||||||
// Will return a pointer to a voxel located at global_voxel_idx in the tsdf | ||||||
// layer. Thread safe. | ||||||
|
@@ -198,6 +206,7 @@ void SemanticIntegratorBase::updateSemanticVoxel( | |||||
// updateLayerWithStoredBlocks() | ||||||
SemanticVoxel* SemanticIntegratorBase::allocateStorageAndGetSemanticVoxelPtr( | ||||||
const vxb::GlobalIndex& global_voxel_idx, | ||||||
size_t total_number_of_labels, | ||||||
vxb::Block<SemanticVoxel>::Ptr* last_block, | ||||||
vxb::BlockIndex* last_block_idx) { | ||||||
DCHECK(last_block != nullptr); | ||||||
|
@@ -235,14 +244,24 @@ SemanticVoxel* SemanticIntegratorBase::allocateStorageAndGetSemanticVoxelPtr( | |||||
<< block_idx.transpose(); | ||||||
|
||||||
*last_block = insert_status.first->second; | ||||||
|
||||||
SemanticProbabilities sem_probs; | ||||||
sem_probs.resize(total_number_of_labels,1); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
sem_probs.setConstant(std::log(1.0 /float(total_number_of_labels))); | ||||||
|
||||||
for (size_t voxel_index = 0; voxel_index<std::pow(semantic_voxels_per_side_,3); voxel_index++){ | ||||||
(*last_block)->getVoxelByLinearIndex(voxel_index).total_number_of_layers_ = total_number_of_labels; | ||||||
(*last_block)->getVoxelByLinearIndex(voxel_index).semantic_priors = sem_probs; | ||||||
} | ||||||
|
||||||
} | ||||||
} | ||||||
|
||||||
// Only used if someone calls the getAllUpdatedBlocks I believe. | ||||||
(*last_block)->updated() = true; | ||||||
|
||||||
const vxb::VoxelIndex local_voxel_idx = vxb::getLocalFromGlobalVoxelIndex( | ||||||
global_voxel_idx, semantic_voxels_per_side_); | ||||||
global_voxel_idx, semantic_voxels_per_side_); | ||||||
|
||||||
return &((*last_block)->getVoxelByVoxelIndex(local_voxel_idx)); | ||||||
} | ||||||
|
@@ -278,11 +297,11 @@ void SemanticIntegratorBase::updateSemanticVoxelProbabilities( | |||||
const SemanticProbabilities& measurement_frequencies, | ||||||
SemanticProbabilities* semantic_prior_probability) const { | ||||||
DCHECK(semantic_prior_probability != nullptr); | ||||||
DCHECK_EQ(semantic_prior_probability->size(), kTotalNumberOfLabels); | ||||||
DCHECK_EQ(semantic_prior_probability->size(), semantic_config_.total_number_of_labels_); | ||||||
DCHECK_LE((*semantic_prior_probability)[0], 0.0); | ||||||
DCHECK(std::isfinite((*semantic_prior_probability)[0])); | ||||||
DCHECK(!semantic_prior_probability->hasNaN()); | ||||||
DCHECK_EQ(measurement_frequencies.size(), kTotalNumberOfLabels); | ||||||
DCHECK_EQ(measurement_frequencies.size(), semantic_config_.total_number_of_labels_); | ||||||
DCHECK_GE(measurement_frequencies.sum(), 1.0) | ||||||
<< "We should at least have one measurement when calling this " | ||||||
"function."; | ||||||
|
@@ -325,9 +344,9 @@ void SemanticIntegratorBase::normalizeProbabilities( | |||||
if (normalization_factor != 0.0) { | ||||||
unnormalized_probs->normalize(); | ||||||
} else { | ||||||
CHECK_EQ(unnormalized_probs->size(), kTotalNumberOfLabels); | ||||||
CHECK_EQ(unnormalized_probs->size(), semantic_config_.total_number_of_labels_); | ||||||
static const SemanticProbability kUniformLogProbability = | ||||||
std::log(1 / kTotalNumberOfLabels); | ||||||
std::log(1.0 / semantic_config_.total_number_of_labels_); | ||||||
LOG(WARNING) << "Normalization Factor is " << normalization_factor | ||||||
<< ", all values are 0. Normalizing to log(1/n) = " | ||||||
<< kUniformLogProbability; | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!