![]() |
AIfES 2 2.0.0
|
Default implementation of the Cross-Entropy loss . More...
Go to the source code of this file.
Typedefs | |
typedef struct ailoss_crossentropy | ailoss_crossentropy_f32_t |
Functions | |
ailoss_t * | ailoss_crossentropy_f32_default (ailoss_crossentropy_f32_t *loss, ailayer_t *input_layer) |
Initializes and connect a Cross-Entropy loss with the F32 default implementation. More... | |
ailoss_t * | ailoss_crossentropy_sparse8_f32_default (ailoss_crossentropy_f32_t *loss, ailayer_t *input_layer) |
Initializes and connect a Cross-Entropy loss with the F32 default implementation for sparse labels. More... | |
Default implementation of the Cross-Entropy loss .
AIfES is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
Hardware independent implementations of the Cross-Entropy loss in F32 data-type. For more information about the Cross-Entropy loss refer to ailoss_mse.h.
ailoss_t * ailoss_crossentropy_f32_default | ( | ailoss_crossentropy_f32_t * | loss, |
ailayer_t * | input_layer | ||
) |
Initializes and connect a Cross-Entropy loss with the F32 default implementation.
The labels must me either binary (when the output layer is a Sigmoid layer), for example
\[ \left( \begin{array}{ccc} 1 & 0 & 0 & 1 \\ 1 & 1 & 1 & 0 \\ 0 & 0 & 1 & 0 \end{array}\right) \]
or row wise one-hot encoded (when the output layer is a Softmax layer), for example
\[ \left( \begin{array}{ccc} 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \end{array}\right) \]
If you want to provide labels as integers, please use ailoss_crossentropy_sparse8_f32_default() loss.
Example: Create the loss structure:
Example: Initialize and connect the loss to the layer structure:
*loss | The loss structure to initialize. |
*input_layer | The output layer of the model (Must be either a Sigmoid or a Softmax layer!). |
ailoss_t * ailoss_crossentropy_sparse8_f32_default | ( | ailoss_crossentropy_f32_t * | loss, |
ailayer_t * | input_layer | ||
) |
Initializes and connect a Cross-Entropy loss with the F32 default implementation for sparse labels.
This loss is meant for single label classification purposes. It expects the target data / labels to be an 8-bit integer tensor (U8 ) with the true-class index.
For example the matrix
\[ \left( \begin{array}{ccc} 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \end{array}\right) \]
in sparse representation is
\[ \left( \begin{array}{ccc} 3 \\ 0 \\ 2 \end{array}\right) \]
and can be created with
Example: Create the loss structure:
Example: Initialize and connect the loss to the layer structure:
*loss | The loss structure to initialize. |
*input_layer | The output layer of the model (Must be a Softmax layer!). |