Giter VIP home page Giter VIP logo

plantvillage-challenge's Introduction

Code in Torch for PlantVillage challenge

I wrote a blog post describing the code here: http://chsasank.github.io/plantvillage-tutorial.html

Requirements

See the installation instructions for a step-by-step guide.

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

Training

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

Example usage

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.

Submission

Create a submission using model.t7:

th submission.lua model.t7 path/to/test > submission.csv

plantvillage-challenge's People

Contributors

chsasank avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

plantvillage-challenge's Issues

bad argument #1 to '?' (must be strictly positive at /tmp/luarocks_torch-scm-1-2561/torch7/lib/TH/generic/THTensorMath.c:1467)

rzai@rzai00:/prj/plantvillage-challenge/crowdai_train_tar$ ll
total 20
drwxrwxr-x 4 rzai rzai 4096 12月 23 11:38 ./
drwxrwxr-x 4 rzai rzai 4096 12月 23 11:35 ../
-rw-rw-r-- 1 rzai rzai 74 12月 23 11:38 divide_dat.sh
drwxrwxr-x 40 rzai rzai 4096 12月 23 11:38 train/
drwxrwxr-x 40 rzai rzai 4096 12月 23 11:38 val/
rzai@rzai00:
/prj/plantvillage-challenge/crowdai_train_tar$
rzai@rzai00:/prj/plantvillage-challenge/crowdai_train_tar$ cd ..
rzai@rzai00:
/prj/plantvillage-challenge$ th main.lua -model alexnet -data crowdai_train_tar
Creating new alexnet model
=> Training epoch # 1
[======================================== 21917/21917 ================================>] Tot: 4m18s | Step: 9ms
train Loss: 2.3574 Accuracy: 35.75 time: 259.87 s
==> Validating
/home/rzai/torch/install/bin/luajit: bad argument #1 to '?' (must be strictly positive at /tmp/luarocks_torch-scm-1-2561/torch7/lib/TH/generic/THTensorMath.c:1467)
stack traceback:
[C]: at 0x7f405a1308b0
[C]: in function 'randperm'
...zai/prj/plantvillage-challenge/datasets/plantvillage.lua:36: in function 'valGenerator'
/home/rzai/prj/plantvillage-challenge/train.lua:87: in function 'validate'
main.lua:72: in main chunk
[C]: in function 'dofile'
...rzai/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
[C]: at 0x00406670
rzai@rzai00:~/prj/plantvillage-challenge$

Assertion failed

Nice code, but when I modify and use my own dataset, I got this error:
(The problem seems to be when put the input to the model, the tensor input should also in cuda?)
(cmd: th main.lua -model resnet -depth 34 -learningRate 0.1 -data datasets/data-torch/)

.../cudnn/init.lua:64: assertion failed!
[C]: in function 'assert'
/home/adwin5/torch/install/share/lua/5.1/cudnn/init.lua:64: in function 'toDescriptor'
...torch/install/share/lua/5.1/cudnn/SpatialConvolution.lua:116: in function 'createIODescriptors'
...torch/install/share/lua/5.1/cudnn/SpatialConvolution.lua:366: in function <...torch/install/share/lua/5.1/cudnn/SpatialConvolution.lua:363>
[C]: in function 'xpcall'
/home/adwin5/torch/install/share/lua/5.1/nn/Container.lua:63: in function 'rethrowErrors'
/home/adwin5/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward'
/home/adwin5/testing/plantvillage-challenge/train.lua:112: in function 'train'
main.lua:71: in main chunk

Running on a Windows environment

I don't have Linux installed on my machine so I'm wondering if there's a way to run the code in Windows, by porting it to TensorFlow may be?

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.