All Projects → psklight → Keras_one_cycle_clr

psklight / Keras_one_cycle_clr

Keras callbacks for one-cycle training, cyclic learning rate (CLR) training, and learning rate range test.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Keras one cycle clr

Chineseaddress ocr
Photographing Chinese-Address OCR implemented using CTPN+CTC+Address Correction. 拍照文档中文地址文字识别。
Stars: ✭ 309 (+653.66%)
Mutual labels:  keras-tensorflow
Attention Is All You Need Keras
A Keras+TensorFlow Implementation of the Transformer: Attention Is All You Need
Stars: ✭ 628 (+1431.71%)
Mutual labels:  keras-tensorflow
Tf Keras Surgeon
Pruning and other network surgery for trained TF.Keras models.
Stars: ✭ 25 (-39.02%)
Mutual labels:  keras-tensorflow
Predictive Maintenance Using Lstm
Example of Multiple Multivariate Time Series Prediction with LSTM Recurrent Neural Networks in Python with Keras.
Stars: ✭ 352 (+758.54%)
Mutual labels:  keras-tensorflow
Labml
🔎 Monitor deep learning model training and hardware usage from your mobile phone 📱
Stars: ✭ 508 (+1139.02%)
Mutual labels:  keras-tensorflow
Pytorch2keras
PyTorch to Keras model convertor
Stars: ✭ 676 (+1548.78%)
Mutual labels:  keras-tensorflow
Segmentation models
Segmentation models with pretrained backbones. Keras and TensorFlow Keras.
Stars: ✭ 3,575 (+8619.51%)
Mutual labels:  keras-tensorflow
Nhdrrnet
Keras Implementation of the paper Deep HDR Imaging via A Non-Local Network - TIP 2020
Stars: ✭ 37 (-9.76%)
Mutual labels:  keras-tensorflow
Music recommender
Music recommender using deep learning with Keras and TensorFlow
Stars: ✭ 528 (+1187.8%)
Mutual labels:  keras-tensorflow
Deep Music Genre Classification
🎵 Using Deep Learning to Categorize Music as Time Progresses Through Spectrogram Analysis
Stars: ✭ 23 (-43.9%)
Mutual labels:  keras-tensorflow
Invoice
增值税发票OCR识别,使用flask微服务架构,识别type:增值税电子普通发票,增值税普通发票,增值税专用发票;识别字段为:发票代码、发票号码、开票日期、校验码、税后金额等
Stars: ✭ 381 (+829.27%)
Mutual labels:  keras-tensorflow
Introneuralnetworks
Introducing neural networks to predict stock prices
Stars: ✭ 486 (+1085.37%)
Mutual labels:  keras-tensorflow
Face Mask Detection
Face Mask Detection system based on computer vision and deep learning using OpenCV and Tensorflow/Keras
Stars: ✭ 774 (+1787.8%)
Mutual labels:  keras-tensorflow
Deepcut
A Thai word tokenization library using Deep Neural Network
Stars: ✭ 330 (+704.88%)
Mutual labels:  keras-tensorflow
Dncnn
Beyond a Gaussian Denoiser: Residual Learning of Deep CNN for Image Denoising (TIP, 2017)
Stars: ✭ 912 (+2124.39%)
Mutual labels:  keras-tensorflow
Amazing Semantic Segmentation
Amazing Semantic Segmentation on Tensorflow && Keras (include FCN, UNet, SegNet, PSPNet, PAN, RefineNet, DeepLabV3, DeepLabV3+, DenseASPP, BiSegNet)
Stars: ✭ 309 (+653.66%)
Mutual labels:  keras-tensorflow
Kafka Streams Machine Learning Examples
This project contains examples which demonstrate how to deploy analytic models to mission-critical, scalable production environments leveraging Apache Kafka and its Streams API. Models are built with Python, H2O, TensorFlow, Keras, DeepLearning4 and other technologies.
Stars: ✭ 661 (+1512.2%)
Mutual labels:  keras-tensorflow
Unsuprevised seg via cnn
Stars: ✭ 38 (-7.32%)
Mutual labels:  keras-tensorflow
Densedepth
High Quality Monocular Depth Estimation via Transfer Learning
Stars: ✭ 963 (+2248.78%)
Mutual labels:  keras-tensorflow
Otto
Otto makes machine learning an intuitive, natural language experience. 🏆 Facebook AI Hackathon winner ⭐️ #1 Trending on MadeWithML.com ⭐️ #4 Trending JavaScript Project on GitHub ⭐️ #15 Trending (All Languages) on GitHub
Stars: ✭ 894 (+2080.49%)
Mutual labels:  keras-tensorflow

One Cycle & Cyclic Learning Rate for Keras

This module provides Keras callbacks to implement in training the following:

(Documentation at https://psklight.github.io/keras_one_cycle_clr/)

Highlights

  • Learning rate & Weight decay range test.
  • Using callbacks, the module works for datasets of numpy arrays or data generator.
  • Common usage as callbacks for both model.fit and model.fit_generator where epochs is intuitively interpreted as cycle lengths.

In detail:

This is inspired by how well fastai library implements this for PyTorch. By the time this module was made, a few options to implement these learning policies in Keras have two limitations: (1) They might not work with data generator; (2) They might need a different way to train (rather than passing a policy as a callback). This module addresses both limitation by defining these training policies as Keras callbacks in such a way that both model.fit and model.fit_generator can be called. For OPC, the number of epochs (argument for fitting) directly represents a cycle length. For LrRT and CLR, epochs necessary to complete a training with a particular policy can be calculated from the policy callback's .find_n_epoch.

Additionally, the utils submodule defines some useful functions such as:

  • plot_from_history plots train and validation loss (if any) as a function of epochs.
  • concatenate_history concatenates training and validation losses and metrics from a list of keras.callbacks.History which can be obtained from model.history after training. This is helpful in connecting histories from multiple one-cycle policy trainings.

Dependencies:

  • tensorflow
  • (optional) keras
  • matplotlib, numpy, pandas, tqdm
  • (optional) numba

Example of LrRT

lrrt_cb = clr.LrRangeTest(lr_range=(1e-3, 1),
                          wd_list=[0, 1e-4, 1e-3, 1e-2, 1e-1], # grid test for weight decay
                          steps=steps,
                          batches_per_step=b,
                          validation_data=(x_test, y_test), # good to find weight decay
                          batches_per_val=5,
                          threshold_multiplier=5.,
                          verbose=False)

n_epoch = lrrt_cb.find_n_epoch(train_gen)
# n_epoch = lrrt_cb.find_n_epoch(x_train, batch_size) # for numpy array as train set
        
model.fit_generator(generator=train_gen,
                       epochs=n_epoch,
                       verbose=0,
                       callbacks=[lrrt_cb])

lrrt_cb.plot()
Drawing

Example of OCP

ocp_1_cb = clr.OneCycle(lr_range=(0.01, 0.1),
                     momentum_range=(0.95, 0.85),
                     reset_on_train_begin=True,
                     record_frq=10)

ocp_cb.test_run(1000)  # plot out values of learning rate and momentum as a function of iteration (batch). 1000 is just for plotting. The actual iteration will be computed when model.fit or model.fit_generator is run.

ocp_test_run

# setting ``epochs`` to 20 means a cycle length is 20 epochs.
hist1 = model_kr.fit_generator(generator=train_gen,
                      epochs=20,
                      validation_data=val_gen,
                      callbacks=[ocp_1_cb, checkpoint, tensorboard_cb],
                      verbose=2)

# train for another cycle
ocp_2_cb = clr.OneCycle(lr_range=(0.001, 0.01),
                     momentum_range=(0.95, 0.85),
                     reset_on_train_begin=True,
                     record_frq=10)

hist2 = model_kr.fit_generator(generator=train_gen,
                      epochs=20,
                      validation_data=val_gen,
                      callbacks=[ocp_2_cb, checkpoint, tensorboard_cb],
                      verbose=2)

hist_all = concatenate_history([hist1, hist2], reindex_epoch=True)

plot_from_history(hist_all) # plot train and validation losses versus epochs

loss_curve

Example of CLR

clr_cb = ktool.CLR(cyc=3,
                   lr_range=(1e-2/5, 1e-2),
                   momentum_range=(0.95, 0.85),
                   verbose=False,
                   amplitude_fn=lambda x: np.power(1.0/3, x))

clr_cb.test_run(600) # see that a new cycle starts at 0th, 200th, and 400th iteration.

clr_test_run

clr_hist = model.fit(x_train, y_train,
                     epochs=60,
                     validation_data=(x_test, y_test),
                     verbose=2,
                     callbacks=[clr_cb])

plot_from_history(clr_hist)

clr_hist

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].