Coder Social home page Coder Social logo

zhanghang1989 / resnet-matconvnet Goto Github PK

View Code? Open in Web Editor NEW
82.0 12.0 44.0 429 KB

Train Deep Residual Network from Scratch or or Fine-tune Pre-trained Model using Matconvnet

Home Page: http://zhanghang1989.github.io/ResNet/

License: MIT License

MATLAB 100.00%

resnet-matconvnet's Introduction

ResNet-Matconvnet

I have stopped maintaining this repo. For fine-tuning ResNet, I would suggest using Torch version from Facebook repo.

This repository is a Matconvnet re-implementation of "Deep Residual Learning for Image Recognition",Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun. You can train Deep Residual Network on ImageNet from Scratch or fine-tune pre-trained model on your own dataset. This repo is created by Hang Zhang.

Table of Contents

  1. Get Started
  2. Train from Scratch
  3. Fine-tune Your Own
  4. Changes

Get Started

The code relies on vlfeat, and matconvnet, which should be downloaded and built before running the experiments. You can use the following commend to download them.

git clone -b v1.0 --recurse-submodules https://github.com/zhanghang1989/ResNet-Matconvnet.git

If you have problem with compiling, please refer to the link.

Train from Scratch

  1. Cifar. Reproducing Figure 6 from the original paper.

    run_cifar_experiments([20 32 44 56 110], 'plain', 'gpus', [1]);
    run_cifar_experiments([20 32 44 56 110], 'resnet', 'gpus', [1]);

    Cifar Experiments

    Reproducing the experiments in Facebook blog. Removing ReLU layer at the end of each residual unit, we observe a small but significant improvement in test performance and the converging progress becomes smoother.

    res_cifar(20, 'modelType', 'resnet', 'reLUafterSum', false,...
    	'expDir', 'data/exp/cifar-resNOrelu-20', 'gpus', [2])
    plot_results_mix('data/exp','cifar',[],[],'plots',{'resnet','resNOrelu'})
  2. Imagenet2012. download the dataset to data/ILSVRC2012 and follow the instructions in setup_imdb_imagenet.m.

    run_experiments([50 101 152], 'gpus', [1 2 3 4 5 6 7 8]);
  3. Your own dataset.

    run_experiments([18 34],'datasetName', 'minc',...
    'datafn', @setup_imdb_minc, 'nClasses', 23, 'gpus', [1 2]);

Fine-tune Your Own

  1. Download

  2. Fine-tuning

    res_finetune('datasetName', 'minc', 'datafn',...
    @setup_imdb_minc, 'gpus',[1 2]);

Changes

  1. 06/21/2016:

  2. 05/17/2016:

    • Reproducing the experiments in Facebook blog, removing ReLU layer at the end of each residual unit.
  3. 05/02/2016:

    • Supported official Matconvnet version.
    • Added Cifar experiments and plots.
  4. 04/27/2016: Re-implementation of Residual Network:

resnet-matconvnet's People

Contributors

zhanghang1989 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

resnet-matconvnet's Issues

How did you decide the learning rate?

I've tried cifar-10 experiments several times and found that different learning rate and step have great influence on the final result, fluctuating about 0.1~0.2%. How can I address it? Hopefully someone give me suggestions!

A question on labels{fi} = fd.labels' + 1; % Index from 1

I wanted to know why the labels are incremented by 1? in res_cifar.m
I have tried to use my own dataset. So far I have been able to run the code and because of this increment
I kept getting an error in the vl_nnloss() function at the line wher we have t = - log(X(ci)) while training the net. The error was that the values held by 'ci' were exceeding the dimension of X by a value of 1. That is, X held 1280 values while ci produced an index 1281. Therefore, to remove this error I did not increment the labels by 1 and the code is running now. Is the increment cifar10 dataset specific?

networkType is fixed to 'resnet'

Hello
I think the following line in res_cifar_init.m
opts.networkType = 'resnet'; % 'plain' | 'resnet'

Keeps the network type fixed even when we pass on the 'plain' network type?

run_cifar_experiments([20 32 44 56 110 164 1001], 'plain', 'gpus', [1]);

Undefined function or variable 'bn'.

I get the "Undefined function or variable 'bn'." error when I run the command

run_cifar_experiments([20 32 44 56 110], 'plain', 'gpus', [1]);

info = add_group(opts.networkType, net, n, info, 3, 16, 1, opts);
Undefined function or variable 'bn'.

Error in res_cifar_init>add_group (line 87)
  add_block_conv(net, sprintf('%d', info.lastIdx+1), lName, ...

Error in res_cifar_init (line 50)
info = add_group(opts.networkType, net, n, info, 3, 16, 1, opts);

Error in res_cifar (line 42)
    net = res_cifar_init(m, 'networkType', opts.modelType, ...

Error in run_cifar_experiments (line 30)
  [net,info] = res_cifar(Ns(i), 'modelType', MTs{i}, opts);

>> run_cifar_experiments([20 32 44 56 110], 'plain', 'gpus', [1]);

Cannot get the same test error rate

Thank you for your work.

I have run your code but I couldn't get the same test error rate as your figure.
My final error rate is 12%.

Is there any trick to run your code?
Thank you very much!

Changing dataset to single channel

Hi again :)
I have made some changes to run your code on a single channel 28x28x7000 image dataset. So far I have made changes to getCifarImdb() which works for the new dataset. I have been able to get hold of the 'augData'
Right now it seems that the parameters that initialize the plain/resnet need to be fixed as I get error while performing convolution on the very first epoch

Error using vl_nnconv
The number of filter groups does not divide the number of filters.

Error in dagnn.Conv/forward (line 11)
outputs{1} = vl_nnconv(...

Error in dagnn.Layer/forwardAdvanced (line 85)
outputs = obj.forward(inputs, {net.params(par).value}) ;

Error in dagnn.DagNN/eval (line 88)
obj.layers(l).block.forwardAdvanced(obj.layers(l)) ;

Error in cnn_train_dag_check>process_epoch (line 218)
net.eval(inputs, opts.derOutputs) ;

Error in cnn_train_dag_check (line 84)
[stats.train(epoch),prof] = process_epoch(net, state, opts, 'train') ;

Error in res_mnist (line 75)

Can you tell me which parameters I need to set correct so that I can run your code on my own dataset?

Error using dagnn.DagNN/addLayer (line 15) - There is already a layer with name 'relu2'.

when running the command run_cifar_experiments([20 32 44 56 110], 'resnet');

I get the following error.

Error using dagnn.DagNN/addLayer (line 15)
There is already a layer with name 'relu2'.

Error in res_cifar_init>add_block_res (line 175)
net.addLayer(sprintf('relu%d', info.lastIdx), block, sprintf('sum%d', info.lastIdx), ...

Error in res_cifar_init>add_group (line 97)
info = add_block_res(net, info, [w w info.lastNumChannel ch], stride, true, opts);

Error in res_cifar_init (line 50)
info = add_group(opts.networkType, net, n, info, 3, 16, 1, opts);

Error in res_cifar (line 42)
net = res_cifar_init(m, 'networkType', opts.modelType, ...

Error in run_cifar_experiments (line 30)
[net,info] = res_cifar(Ns(i), 'modelType', MTs{i}, opts);

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.