Skip to main content
. 2023 Sep 12;8(5):422. doi: 10.3390/biomimetics8050422
Algorithm 2 Learning algorithm for CNN model.

Input: a grayscale image, represented as a single-channel image.

Parameter: N_epochs, Batch_size, SGD optimizer, Cross-entropy loss function.

Output: the probabilities of the image belonging to each of the classes.

  • 1.

    Initialize the neural network with a specific architecture (layers and connections) and initial weights.

  • 2.

    Load the data and set up the training parameters.

  • 3.

    for in N_epochs do

  • 4.

          Set the neural network in training mode.

  • 5.

          for Batch_size in training dataset do

  • 6.

              Transfer the data and target values to the device (GPU or CPU) based on the settings.

  • 7.

              Reset the gradients of the optimizer.

  • 8.

              Perform a forward pass through the model to obtain the output values.

  • 9.

              Calculate the loss function between the predicted and target values.

  • 10.

               Perform backpropagation of gradients to compute them for each model parameter.

  • 11.

               Update the model weights using the SGD optimizer.

  • 12.

         end for

  • 13.

    end for

  • 14.

    Finish the algorithm execution.