Giter Club home page Giter Club logo

mlhf's Introduction

Meta Learning with Hessian Free Approach in Neural Nets Training

This is a Tensorflow implementation of MLHF optimizer (paper link https://arxiv.org/abs/1805.08462), a generic second-order meta-optimizer, which includes:

  • souce code of MLHF built on 2 layer LSTM.
  • meta-traning code on cuda-convnet and resnet of cifar10.
  • valuation code by traning cuda-convnet and resnet on cifar10 and ImageNet.

The training model code was modified from Tensorflow/model, while experience replay code was modified from evaldsurtans/dqn-prioritized-experience-replay. see git submodule for more detail.

Recommened Runtime Environment:

  • python 3.6
  • TensorFlow 1.7.0

One should be emphasized that although this work is based on Tensorflow, it does not mean that the current Tensorflow framework has the full capacity to impliment all technique detail of MLHF, e.g. the gradient of $H$'s inplimentation require the tf.gradents cancalculated in Defun while it's graph was not the default graph and not allowed in current Tensorflow. So, we hack some core code of tensorflow, which would not guarantee the compatibility in different tensorflow version any more. This part of hackfull and evil code can be view in CustomOp/gradients_impl.py.

meta-training and validation on CUDA-convnet or ResNet of cifar10

First, prepare dataset and environment:

git clone --recurse-submodules -j8 [email protected]:ozzzp/MLHF.git
cd MLHF

python models/official/resnet/cifar10_download_and_extract.py --data_dir=./cifar10_data

base_path=$(pwd)
addition_path=${base_path}'/RL_farmwork/dqn-prioritized-experience-replay'
export PYTHONPATH=${base_path}':'${addition_path}

To meta-train on CUDA-convnet, run:

python train_val/train_meta_optimizer.py \
        --data_dir=./cifar10_data \
        --batch_size=64 \
        --meta_roll_back=10 \
        --model_dir=./cuda_convnet_log \
        --keep_prob=0.3 \
        --data_format=channels_last \
        --meta_lr=1e-3 \
        --train_epochs=250 \
        --problem=convnet \
        --x_use=x --y_use=rnn --CG_iter=4

To meta-train on ResNet, run:

python  train_val/train_meta_optimizer.py \
        --data_dir=./cifar10_data \
        --batch_size=128 \
        --meta_roll_back=10 \
        --resnet_size=20 \
        --model_dir=./resnet_log \
        --keep_prob=0.5 \
        --data_format=channels_last \
        --meta_lr=1e-2 \
        --epochs_per_eval=250 \
        --problem=resnet \
        --x_use=x --y_use=rnn --CG_iter=4

To evaluate by training on cifar10, run:

 python -u train_val/use_meta_optimizer.py \
        --data_dir=./cifar10_data \
        --batch_size=128 \
        --model_dir=./eval_cuda_convnet\
        --data_format=channels_last \
        --problem=convnet \
        --optimizer=meta \
        --train_epochs=250 \
        --lr=1 \
        --meta_ckpt=./cuda_convnet_log \
        --x_use=x --y_use=rnn --CG_iter=4

To evaluate by training imagenet on resnet, first, preapre ImageNet dataset as here to ./ImageNet_2012, then, run:

 python --train_val/use_meta_resnet_on_imagenet.py \
        --data_dir=./ImageNet_2012 \
        --batch_size=64 \
        --resnet_size=18 \
        --model_dir=./eval_resnet \
        --data_format=channels_last \
        --problem=resnet \
        --optimizer=meta \
        --lr=1 \
        --meta_ckpt=./resnet_log \
        --x_use=x --y_use=rnn --CG_iter=4

Or, another choice is to modify and run scripts in ./scripts

extend to new model

The MLHF is a general optimizer, but we have impliment the minimal operators' difference forward and losses of experiment, this might be the main task that extend to new model. This part of code can be view in CustomOp/op_r_forward.py and CustomOp/hession_loss.py. Also, To register new operator's type to RNN, view CustomOp/rnn.py.

dicussion and feedback

Any discusstion, feedback or bugs report about MLHF are welcome. But it's not very recommend to contribute the application or extenstion of MLHF (e.g. extend to new dataset, new model, more ops) to this repository, consider it's still a experiment project and might not be merged in time. If you do such things or want to do, just fork this repository, and modify as your managed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.