Code in Torch for PlantVillage challenge
I wrote a blog post describing the code here: http://chsasank.github.io/plantvillage-tutorial.html
See the installation instructions for a step-by-step guide.
- Install Torch
- Optionally install Nvidia CUDA and cuDNN v4 and the Torch cuDNN bindings
- Download and extract the training and test dataset from https://www.crowdai.org.
If you already have Torch installed, update nn
, cunn
, and cudnn
.
Divide the training data in to train
and val
folders. You can use a bash script like this:
cd directory/contaning/c_0c_1...etcdirectories
mkdir -p train val
for i in {0..37}; do mkdir val/c_$i; done
mv c_* train
The training scripts come with several options, which can be listed with the --help
flag.
$ th main.lua --help
Torch-7 PlantVillage Challenge Training script
-learningRate initial learning rate for sgd [0.01]
-momentum momentum term of sgd [0.9]
-maxEpochs Max # Epochs [120]
-batchSize batch size [32]
-nbClasses # of classes [38]
-nbChannels # of channels [3]
-backend Options: cudnn | nn [cudnn]
-model Options: alexnet | vgg | resnet [alexnet]
-depth For vgg depth: A | B | C | D, For resnet depth: 18 | 34 | 50 | 101 | ... Not applicable for alexnet [A]
-retrain Path to model to finetune [none]
-save Path to save models [.]
-data Path to folder with train and val directories [datasets/crowdai/]
Train alexnet:
$ th main.lua -model alexnet -data path/to/train-val-directories
Train alexnet on CPU (not recommended):
$ th main.lua -model alexnet -data path/to/train-val-directories -backend nn
Train resnet 34
$ th main.lua -model resnet -depth 34 -learningRate 0.1 -data path/to/train-val-directories
This checkpoints the model every 10 epochs. It also saves the best model as per validation set. You can use these to make a submission.
Create a submission using model.t7
:
th submission.lua model.t7 path/to/test > submission.csv