Skip to main content

My submission the (completed) Plant Pathology 2020 competition on Kaggle.

Project description

Plant Pathology Classifier

A neural network classifies images of leaves as healthy or diseased!

A picture of a leaf

Recently, I've been learning about Fast.ai and PyTorch in my free time and wanted to apply my knowledge. I'm trying to learn how to win Kaggle competitions, so I decided to build a model for the completed Kaggle Plant Pathology Competition.

I built this model using Nbdev, which provides an literate programming environment as originally envisioned by Donald Knuth. This means the notebooks in the nbks folder are the library's "source code". They get converted into regular python files, a full documentation site, and contain unit and functional test, all in one place.

Install

pip install plant-pathology

How to use

Inference example

from plant_pathology.pretrained_models import get_model

model = get_model("resnet18_2021-04-08")
prediction = model.predict("images/leaf.jpg")
prediction
('rust', tensor(2), tensor([0.0456, 0.0402, 0.8795, 0.0347]))

Training

Run training script

python -m plant_pathology.train -h
usage: train.py [-h] [--frz FRZ] [--pre PRE] [--re RE] [--bs BS] [--smooth] [--arch ARCH] [--dump] [--log] [--save] [--mixup MIXUP] [--tta] [--fp16] [--eval_dir EVAL_DIR] [--val_fold VAL_FOLD] [--pseudo PSEUDO] path epochs lr

positional arguments:
  path                 Path to data dir
  epochs               Number of unfrozen epochs
  lr                   Initial learning rate

optional arguments:
  -h, --help           show this help message and exit
  --frz FRZ            Number of frozen epochs (default: 1)
  --pre PRE            Image presize (default: (682, 1024))
  --re RE              Image resize (default: 256)
  --bs BS              Batch size (default: 256)
  --smooth             Label smoothing? (default: False)
  --arch ARCH          Architecture (default: resnet18)
  --dump               Don't train, just print model (default: False)
  --log                Log w/ W&B (default: False)
  --save               Save model based on RocAuc (default: False)
  --mixup MIXUP        Mixup (0.4 is good) (default: 0.0)
  --tta                Test-time augmentation (default: False)
  --fp16               Mixed-precision training (default: False)
  --eval_dir EVAL_DIR  Evaluate model and save results in dir
  --val_fold VAL_FOLD  Don't go cross-validation, just do 1 fold (or pass 9 to train on all data)
  --pseudo PSEUDO      Path to pseudo labels to train on

Testing

To run all the tests in the notebooks in parallel, just run nbdev_test_nbs from the terminal! :)

Web App

I deployed the classifier as a simple web app using Streamlit and Heroku. Note, it may take a few minutes to start up.

The code for the app is here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plant_pathology-0.0.3.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plant_pathology-0.0.3-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file plant_pathology-0.0.3.tar.gz.

File metadata

  • Download URL: plant_pathology-0.0.3.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for plant_pathology-0.0.3.tar.gz
Algorithm Hash digest
SHA256 4a497dc9a56244f45dde257d4b0f2c22ddf53141eaf4ed8143ede2e70def2bda
MD5 e359fca4a8ac7333846ee925e3c5e4ab
BLAKE2b-256 e94e33725c57cb330ef013a47269ea973f198f637655c5a81cdf5ac6ceec2b9e

See more details on using hashes here.

File details

Details for the file plant_pathology-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: plant_pathology-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for plant_pathology-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e7b6a0ab4d365784d573fedc985804457d7992bf4e780de296776743806739cb
MD5 0d75498f0effaad710243943b22857de
BLAKE2b-256 f470cf600ee0b29c087a8cddabe3d3e6cf8ac88f332d1c379f225141c2e7e1ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page