Skip to content
Open
Changes from all commits
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: 5 additions & 0 deletions keras_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ keras::DataChunk* keras::LayerActivation::compute_output(keras::DataChunk* dc) {
if(y[k] < 0) y[k] = 0;
}
} else if(m_activation_type == "softmax") {
// avoid overflows
auto max_y = *std::max_element(y.begin(), y.end());
for (auto &num : y) {
num -= max_y;
}
float sum = 0.0;
for(unsigned int k = 0; k < y.size(); ++k) {
y[k] = exp(y[k]);
Expand Down