Skip to content

Commit

Permalink
Disallow inf values in softmax, fixes #183
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobiasd committed Oct 29, 2019
1 parent 34e8e6e commit cc8efa8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/fdeep/layers/softmax_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class softmax_layer : public activation_layer
const auto log_sum_shifted = std::log(sum_shifted);
for (size_t z_class = 0; z_class < input.shape().depth_; ++z_class)
{
output.set(0, 0, y, x, z_class,
std::exp(inp_shifted.get(0, 0, y, x, z_class) - log_sum_shifted));
const auto result = std::exp(inp_shifted.get(0, 0, y, x, z_class) - log_sum_shifted);
output.set(0, 0, y, x, z_class, std::isinf(result) ? static_cast<float_type>(0) : result);
}
}
}
Expand Down

0 comments on commit cc8efa8

Please sign in to comment.