All Projects → umbertogriffo → Focal Loss Keras

umbertogriffo / Focal Loss Keras

Binary and Categorical Focal loss implementation in Keras.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Focal Loss Keras

Deep Math Machine Learning.ai
A blog which talks about machine learning, deep learning algorithms and the Math. and Machine learning algorithms written from scratch.
Stars: ✭ 173 (-9.42%)
Mutual labels:  deep-neural-networks
Studytensorflow
How to use TensorFlow
Stars: ✭ 180 (-5.76%)
Mutual labels:  deep-neural-networks
Megalodon
Various ML/DL Resources organised at a single place.
Stars: ✭ 189 (-1.05%)
Mutual labels:  deep-neural-networks
Awesome Deep Learning Music
List of articles related to deep learning applied to music
Stars: ✭ 2,195 (+1049.21%)
Mutual labels:  deep-neural-networks
Andrew Ng Notes
This is Andrew NG Coursera Handwritten Notes.
Stars: ✭ 180 (-5.76%)
Mutual labels:  deep-neural-networks
Sparse Evolutionary Artificial Neural Networks
Always sparse. Never dense. But never say never. A repository for the Adaptive Sparse Connectivity concept and its algorithmic instantiation, i.e. Sparse Evolutionary Training, to boost Deep Learning scalability on various aspects (e.g. memory and computational time efficiency, representation and generalization power).
Stars: ✭ 182 (-4.71%)
Mutual labels:  deep-neural-networks
Speech Emotion Recognition
Speaker independent emotion recognition
Stars: ✭ 169 (-11.52%)
Mutual labels:  deep-neural-networks
Emotion Classification From Audio Files
Understanding emotions from audio files using neural networks and multiple datasets.
Stars: ✭ 189 (-1.05%)
Mutual labels:  deep-neural-networks
Adversarial Robustness Toolbox
Adversarial Robustness Toolbox (ART) - Python Library for Machine Learning Security - Evasion, Poisoning, Extraction, Inference - Red and Blue Teams
Stars: ✭ 2,638 (+1281.15%)
Mutual labels:  deep-neural-networks
Deep Survey Text Classification
The project surveys 16+ Natural Language Processing (NLP) research papers that propose novel Deep Neural Network Models for Text Classification, based on Convolutional Neural Networks (CNN) and Recurrent Neural Networks (RNN). It also implements each of the models using Tensorflow and Keras.
Stars: ✭ 187 (-2.09%)
Mutual labels:  deep-neural-networks
Vidaug
Effective Video Augmentation Techniques for Training Convolutional Neural Networks
Stars: ✭ 178 (-6.81%)
Mutual labels:  deep-neural-networks
Smoothing Adversarial
Code for our NeurIPS 2019 *spotlight* "Provably Robust Deep Learning via Adversarially Trained Smoothed Classifiers"
Stars: ✭ 179 (-6.28%)
Mutual labels:  deep-neural-networks
Orion
Asynchronous Distributed Hyperparameter Optimization.
Stars: ✭ 186 (-2.62%)
Mutual labels:  deep-neural-networks
Awesome Deep Learning For Chinese
最全的中文版深度学习资源索引,包括论文,慕课,开源框架,数据集等等
Stars: ✭ 174 (-8.9%)
Mutual labels:  deep-neural-networks
Snn toolbox
Toolbox for converting analog to spiking neural networks (ANN to SNN), and running them in a spiking neuron simulator.
Stars: ✭ 187 (-2.09%)
Mutual labels:  deep-neural-networks
Numpydl
Deep Learning Library. For education. Based on pure Numpy. Support CNN, RNN, LSTM, GRU etc.
Stars: ✭ 169 (-11.52%)
Mutual labels:  deep-neural-networks
Dkeras
Distributed Keras Engine, Make Keras faster with only one line of code.
Stars: ✭ 181 (-5.24%)
Mutual labels:  deep-neural-networks
Awesome Video Object Detection
This is a list of awesome articles about object detection from video.
Stars: ✭ 190 (-0.52%)
Mutual labels:  deep-neural-networks
Germanwordembeddings
Toolkit to obtain and preprocess german corpora, train models using word2vec (gensim) and evaluate them with generated testsets
Stars: ✭ 189 (-1.05%)
Mutual labels:  deep-neural-networks
Plotneuralnet
Latex code for making neural networks diagrams
Stars: ✭ 14,316 (+7395.29%)
Mutual labels:  deep-neural-networks

Focal Loss

CI

focal loss down-weights the well-classified examples. This has the net effect of putting more training emphasis on that data that is hard to classify. In a practical setting where we have a data imbalance, our majority class will quickly become well-classified since we have much more data for it. Thus, in order to insure that we also achieve high accuracy on our minority class, we can use the focal loss to give those minority class examples more relative weight during training.

The focal loss can easily be implemented in Keras as a custom loss function.

Usage

Compile your model with focal loss as sample:

Binary

model.compile(loss=[binary_focal_loss(alpha=.25, gamma=2)], metrics=["accuracy"], optimizer=adam)

Categorical

model.compile(loss=[categorical_focal_loss(alpha=[[.25, .25, .25]], gamma=2)], metrics=["accuracy"], optimizer=adam)

Alpha is used to specify the weight of different categories/labels, the size of the array needs to be consistent with the number of classes.

Convert a trained keras model into an inference tensorflow model

If you use the @amir-abdi's code to convert a trained keras model into an inference tensorflow model, you have to serialize nested functions. In order to serialize nested functions you have to install dill in your anaconda environment as follow:

conda install -c anaconda dill

then modify keras_to_tensorflow.py adding this piece of code after the imports:

import dill
custom_object = {'binary_focal_loss_fixed': dill.loads(dill.dumps(binary_focal_loss(gamma=2., alpha=.25))),
                 'categorical_focal_loss_fixed': dill.loads(dill.dumps(categorical_focal_loss(gamma=2., alpha=[[.25, .25, .25]]))),
                 'categorical_focal_loss': categorical_focal_loss,
                 'binary_focal_loss': binary_focal_loss}

and modify the beginning of load_model method as follow:

if not Path(input_model_path).exists():
    raise FileNotFoundError(
        'Model file `{}` does not exist.'.format(input_model_path))
try:
    model = keras.models.load_model(input_model_path, custom_objects=custom_object)
    return model

References

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].