All Projects → Minyus → optkeras

Minyus / optkeras

Licence: other
OptKeras: wrapper around Keras and Optuna for hyperparameter optimization

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to optkeras

allennlp-optuna
⚡️ AllenNLP plugin for adding subcommands to use Optuna, making hyperparameter optimization easy
Stars: ✭ 33 (+13.79%)
Mutual labels:  hyperparameters, hyperparameter-optimization, optuna
optuna-dashboard
Real-time Web Dashboard for Optuna.
Stars: ✭ 240 (+727.59%)
Mutual labels:  hyperparameter-optimization, optuna
tuneta
Intelligently optimizes technical indicators and optionally selects the least intercorrelated for use in machine learning models
Stars: ✭ 77 (+165.52%)
Mutual labels:  hyperparameter-optimization, optuna
cmaes
Python library for CMA Evolution Strategy.
Stars: ✭ 174 (+500%)
Mutual labels:  hyperparameter-optimization, optuna
randopt
Streamlined machine learning experiment management.
Stars: ✭ 108 (+272.41%)
Mutual labels:  hyperparameters, hyperparameter-optimization
Dsh tensorflow
implemement of DEEP SUPERVISED HASHING FOR FAST IMAGE RETRIEVAL_CVPR2016
Stars: ✭ 97 (+234.48%)
Mutual labels:  deep
Clone Deep
Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives. Used by superstruct, merge-deep, and many others!
Stars: ✭ 229 (+689.66%)
Mutual labels:  deep
Merge Deep
Recursively merge values in a JavaScript object.
Stars: ✭ 90 (+210.34%)
Mutual labels:  deep
Mixin Deep
Deeply mix the properties of objects into the first object, while also mixing-in child objects.
Stars: ✭ 72 (+148.28%)
Mutual labels:  deep
Hypernets
A General Automated Machine Learning framework to simplify the development of End-to-end AutoML toolkits in specific domains.
Stars: ✭ 221 (+662.07%)
Mutual labels:  hyperparameter-optimization
scicloj.ml
A Clojure machine learning library
Stars: ✭ 152 (+424.14%)
Mutual labels:  hyperparameter-optimization
Get Value
Use property paths (`a.b.c`) get a nested value from an object.
Stars: ✭ 194 (+568.97%)
Mutual labels:  deep
Djl Demo
Demo applications showcasing DJL
Stars: ✭ 126 (+334.48%)
Mutual labels:  deep
Collectable
High-performance immutable data structures for modern JavaScript and TypeScript applications. Functional interfaces, deep/composite operations API, mixed mutability API, TypeScript definitions, ES2015 module exports.
Stars: ✭ 233 (+703.45%)
Mutual labels:  deep
Neural Api
CAI NEURAL API - Pascal based neural network API optimized for AVX, AVX2 and AVX512 instruction sets plus OpenCL capable devices including AMD, Intel and NVIDIA.
Stars: ✭ 94 (+224.14%)
Mutual labels:  deep
AutoOpt
Automatic and Simultaneous Adjustment of Learning Rate and Momentum for Stochastic Gradient Descent
Stars: ✭ 44 (+51.72%)
Mutual labels:  hyperparameters
Deeplearning Mindmap
A mindmap summarising Deep Learning concepts.
Stars: ✭ 1,251 (+4213.79%)
Mutual labels:  deep
Omniclone
An isomorphic and configurable javascript utility for objects deep cloning that supports circular references.
Stars: ✭ 184 (+534.48%)
Mutual labels:  deep
Learningx
Deep & Classical Reinforcement Learning + Machine Learning Examples in Python
Stars: ✭ 241 (+731.03%)
Mutual labels:  deep
Unsuperviseddeephomographyral2018
Unsupervised Deep Homography: A Fast and Robust Homography Estimation Model
Stars: ✭ 161 (+455.17%)
Mutual labels:  deep

OptKeras, a wrapper around Keras and Optuna

PyPI version Python Version License: MIT Open In Colab

A Python package designed to optimize hyperparameters of Keras Deep Learning models using Optuna. Supported features include pruning, logging, and saving models.

What is Keras?

Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano.

What is Optuna?

Optuna is an automatic hyperparameter optimization software framework, particularly designed for machine learning.

What are the advantages of OptKeras?

  • Optuna supports pruning option which can terminate the trial (training) early based on the interim objective values (loss, accuracy, etc.). Please see Optuna's key features. OptKeras can leverage Optuna's pruning option. If enable_pruning is set to True and the performance in early epochs is not good, OptKeras can terminate training (after the first epoch at the earliest) and try another parameter set.
  • Optuna manages logs in database using SQLAlchemy and can resume trials after interruption, even after the machine is rebooted (after 90 minutes of inactivity or 12 hours of runtime of Google Colab) if the database is saved as a storage file. OptKeras can leverage this feature.
  • More epochs do not necessarily improve the performance of Deep Neural Network. OptKeras keeps the best value though epochs so it can be used as the final value.
  • OptKeras can log metrics (loss, accuracy, etc. for train and test datasets) with trial id and timestamp (begin and end) for each epoch to a CSV file.
  • OptKeras can save the best Keras models (only the best Keras model overall or all of the best models for each parameter set) with trial id in its file name so you can link to the log.
  • OptKeras supports randomized grid search (randomized search by sampling parameter sets without replacement; grid search in a randomized order) useful if your primary purpose is benchmarking/comparison rather than optimization.

How to install OptKeras?

Option 1: install from the PyPI

	pip install optkeras

Option 2: install from the GitHub repository

	pip install git+https://github.com/Minyus/optkeras.git

Option 3: clone the GitHub repository, cd into the downloaded repository, and run:

	python setup.py install

How to use OptKeras?

Please see the OptKeras example available in Google Colab (free cloud GPU) environment.

To run the code, navigate to "Runtime" >> "Run all".

To download the notebook file, navigate to "File" >> "Download .ipynb".

Here are the basic steps to use.

""" Step 0. Import Keras, Optuna, and OptKeras """

from keras.models import Sequential
from keras.layers import Flatten, Dense, Conv2D
from keras.optimizers import Adam
import keras.backend as K

import optuna

from optkeras.optkeras import OptKeras


study_name = dataset_name + '_Simple'

""" Step 1. Instantiate OptKeras class
You can specify arguments for Optuna's create_study method and other arguments 
for OptKeras such as enable_pruning. 
"""

ok = OptKeras(study_name=study_name)


""" Step 2. Define objective function for Optuna """

def objective(trial):
    
    """ Step 2.1. Define parameters to try using methods of optuna.trial such as 
    suggest_categorical. In this simple demo, try 2*2*2*2 = 16 parameter sets: 
    2 values specified in list for each of 4 parameters 
    (filters, kernel_size, strides, and activation for convolution).
    """    
    model = Sequential()
    model.add(Conv2D(
        filters = trial.suggest_categorical('filters', [32, 64]), 
        kernel_size = trial.suggest_categorical('kernel_size', [3, 5]), 
        strides = trial.suggest_categorical('strides', [1, 2]), 
        activation = trial.suggest_categorical('activation', ['relu', 'linear']), 
        input_shape = input_shape ))
    model.add(Flatten())
    model.add(Dense(num_classes, activation='softmax'))
    model.compile(optimizer = Adam(), 
                loss='sparse_categorical_crossentropy', metrics=['accuracy'])
    
    """ Step 2.2. Specify callbacks(trial) and keras_verbose in fit 
    (or fit_generator) method of Keras model
    """
    model.fit(x_train, y_train, 
              validation_data = (x_test, y_test), shuffle = True,
              batch_size = 512, epochs = 2,
              callbacks = ok.callbacks(trial), 
              verbose = ok.keras_verbose )  
    
    """ Step 2.3. Return trial_best_value (or latest_value) """
    return ok.trial_best_value

""" Step 3. Run optimize. 
Set n_trials and/or timeout (in sec) for optimization by Optuna
"""
ok.optimize(objective, timeout = 60) # 1 minute for demo

Will OptKeras limit features of Keras or Optuna?

Not at all! You can access the full feaures of Keras and Optuna even if OptKeras is used.

What parameaters are available for OptKeras?

Which version of Python is supported?

Python 3.5 or later

What was the tested environment for OptKeras?

  • Keras 2.2.4
  • TensorFlow 1.14.0
  • Optuna 0.14.0
  • OptKeras 0.0.7

About author

Yusuke Minami

License

MIT License (see https://github.com/Minyus/optkeras/blob/master/LICENSE).

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