Merge pull request #42330 from danielyou0230:tflite_softmax

PiperOrigin-RevId: 327741784
Change-Id: Id00bdcb9c3e985a3660ebe0ce0d35ab3013ee5d8
This commit is contained in:
TensorFlower Gardener 2020-08-20 19:32:01 -07:00
commit c37ef0c195

View File

@ -49,15 +49,15 @@ inline void Softmax(const SoftmaxParams& params,
// Compute sum.
float sum = 0.f;
for (int c = 0; c < depth; ++c) {
sum += std::exp((input_data[i * depth + c] - max) *
static_cast<float>(params.beta));
const float exp_c = std::exp((input_data[i * depth + c] - max) *
static_cast<float>(params.beta));
output_data[i * depth + c] = exp_c;
sum += exp_c;
}
// Compute result.
for (int c = 0; c < depth; ++c) {
output_data[i * depth + c] = std::exp((input_data[i * depth + c] - max) *
static_cast<float>(params.beta)) /
sum;
output_data[i * depth + c] = output_data[i * depth + c] / sum;
}
}
}