"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;
Showing posts with label Keras. Show all posts
Showing posts with label Keras. Show all posts

December 09, 2023

Simplifying Neural Network Training Under Class Imbalance

Simplifying Neural Network Training Under Class Imbalance

  • Small batch size - Class-imbalanced - settings, where small batch sizes shine.
  • Data augmentations have an amplified impact on performance under class imbalance, especially on minority-class accuracy
  • Adding a self-supervised loss during training can improve feature representations
  • Label smoothing, especially on minority class examples, helps prevent overfitting. We adapt label smoothing for the class-imbalanced setting by applying more smoothing to minorityclass examples than to majority-class  examples
  • A small modification of Sharpness-Aware Minimization (SAM) pulls decision boundaries away from minority samples and significantly improves minority-group accuracy
  • Loss reweighting. Reweighting methods assign different weights to majority and minority class loss functions, increasing the influence of minority samples which would otherwise play little role in the loss function

Label smoothing is a technique often used in training deep learning models, particularly for classification tasks. It modifies the target labels, making them a blend of the original hard labels and some uniform or prior distribution. This can lead to better generalization by preventing the model from becoming too confident about its predictions. In a class-imbalanced setting, where some classes have significantly more examples than others, label smoothing can help by reducing the model's bias towards the more frequent classes.

Label smoothing for the class-imbalanced setting python example


In practice, label smoothing does not change the dataset's inherent imbalance but softens the target distributions by moving a portion of the mass from the peak (corresponding to the hard label) to other classes, which can help during the training of a model, preventing it from becoming overly confident on the majority class.



Loss reweighting for the class-imbalanced setting python example


class_weight: Optional dictionary mapping class indices (integers) to a weight (float) value, used for weighting the loss function (during training only).

Let's import the module first

from sklearn.utils import class_weight

In order to calculate the class weight do the following

class_weights = class_weight.compute_class_weight('balanced', np.unique(y_train), y_train)

Thirdly and lastly add it to the model fitting

model.fit(X_train, y_train, class_weight=class_weights)

Keep Exploring!!!

February 24, 2023

MLFlow on AWS EC2

  • MLflow is organized into four components: Tracking, Projects, Models, and Model Registry. 
  • Create AWS Free EC2 t2 micro ubuntu machine
  • Follow the below steps to setup mlflow
  • Install ngnix to route requests from external networks
  • Run a few experiments, Visualize results
Steps


References





Keep Exploring!!!


February 07, 2023

Segmentation Notes

If things work happy else its another next step towards solution :)

Residual Blocks


What is Dice Coeff and Dice Coeff Loss in segmentation explain with python code simple terms

Dice Coefficient (also known as the Sørensen–Dice coefficient) is a measure of similarity between two sets of data. It is commonly used in image segmentation to measure the accuracy of a segmentation algorithm.

The Dice coefficient is calculated as the ratio of the intersection of two sets of data to the union of the two sets. It is expressed as a value between 0 and 1, where 1 indicates a perfect match.

Dice Coefficient Loss is a loss function used in image segmentation tasks. It is used to measure the difference between the predicted segmentation and the ground truth segmentation. The loss is calculated as the negative of the Dice coefficient.

Code Examples Notes


Keep Exploring!!!

January 16, 2022

#keras #experiments #ParallelNetworks #Merge

Experiments to build hybrid approach of models. Leverage different convolutions, activation functions.

For custom training vision tasks. Get Features from both vggnet, resnet
  • Resnet - 224 x 224 x 3
  • Vgg16  - 224 x 224 x 3
Feature Vectors
  • VGG16 feature shape — (1L, 7L, 7L, 512L)
  • VGG19 feature shape — (1L, 7L, 7L, 512L)
  • InceptionV3 feature shape — (1L, 5L, 5L, 2048L)
  • ResNet50 feature shape — (1L, 1L, 1L, 2048L)
Inputs
  • Sobel, Laplace Transformations
  • Shareped X / Y Axis edges
  • Multiple inputs
Further Techniques
  • Apply different convolution filters
  • Apply different activation functions
  • Append different weights and analyze
Keep Exploring!!!

December 13, 2019

Day #302 - Keras Best Practices during Training

In this post we take the raw version of code and add below features in code
  • Adding Checkpoint
  • Adding Logging
  • Plot Results
  • Restart Training from Checkpoint
  • Early Stopping

Run #1 Output (10 Epochs)


Run #2 Continue with Existing Weights (5 Epochs)


Happy Learning!!!