Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion RecoTauTag/HLTProducers/src/L2TauTagNNProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,10 @@ void L2TauNNProducer::fillPatatracks(tensorflow::Tensor& cellGridMatrix,

std::vector<float> L2TauNNProducer::getTauScore(const tensorflow::Tensor& cellGridMatrix) {
std::vector<tensorflow::Tensor> pred_tensor;
tensorflow::run(L2cacheData_->session, {{inputTensorName_, cellGridMatrix}}, {outputTensorName_}, &pred_tensor);
// Check for empty input
if (cellGridMatrix.NumElements() != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does cellGridMatrix.NumElements() == 0 guarantee that nTau is also 0, such that accessing pred_tensor[0] doesn't result in undefined behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is guaranteed because nTaus = cellGridMatrix.shape().dim_size(0), which is the same check, but I agree that it can be improved by wrapping all the snippet around a if (nTaus > 0).
If you wish I can rework it quickly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wish I can rework it quickly

perhaps leave a comment, if it's guaranteed let's not add more if branches.
Thank you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valsdav will you apply the suggestion above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I'm about to push a commit with improvements 👍

tensorflow::run(L2cacheData_->session, {{inputTensorName_, cellGridMatrix}}, {outputTensorName_}, &pred_tensor);
}
const int nTau = cellGridMatrix.shape().dim_size(0);
std::vector<float> pred_vector(nTau);
for (int tau_idx = 0; tau_idx < nTau; ++tau_idx) {
Expand Down
14 changes: 13 additions & 1 deletion RecoTauTag/RecoTau/plugins/DeepTauId.cc
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ class DeepTauId : public DeepTauIdBase<DeepTauIdWrapper> {
{"outer_all_dropout_4/Identity"},
&pred_vector);
}

return pred_vector.at(0);
}

Expand All @@ -547,8 +548,10 @@ class DeepTauId : public DeepTauIdBase<DeepTauIdWrapper> {
bool is_inner) {
if (debug_level >= 2) {
std::cout << "<DeepTauId::createConvFeatures (is_inner = " << is_inner << ")>:" << std::endl;
std::cout << "number of valid cells = " << grid.num_valid_cells() << std::endl;
}
tensorflow::Tensor& convTensor = *convTensor_.at(is_inner);

eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
tensorflow::DT_FLOAT,
tensorflow::TensorShape{
Expand Down Expand Up @@ -605,8 +608,17 @@ class DeepTauId : public DeepTauIdBase<DeepTauIdWrapper> {
}
}
}
tensorflow::Tensor predTensor;
//check if at least one input is there to
//avoid calling TF with empty grid #TODO understand why the grid is empty
if (idx != 0) {
predTensor = getPartialPredictions(is_inner);
} else {
if (debug_level >= 2) {
std::cout << " no valid cells found, skipped TF evaluation" << std::endl;
}
}

const auto predTensor = getPartialPredictions(is_inner);
idx = 0;
for (int eta = -grid.maxEtaIndex(); eta <= grid.maxEtaIndex(); ++eta) {
for (int phi = -grid.maxPhiIndex(); phi <= grid.maxPhiIndex(); ++phi) {
Expand Down