Faster R-CNN for Leaf Disease Detection
Clone the github repository:
$git clone https://github.com/ILAN-Solutions/leaf-disease-using-faster-rcnn.git
$cd leaf-disease-using-faster-rcnn
And install the packages required using,
$pip install -r requirements.txt
Data Pre-processing:
The Dataset has both image and its respective annotated xml files. So the following code generates a data text document in the format "img_location, x1, x2, y1, y2, class" where "img_location" is the location of the image in the directory, "x1, y1" are x-min and y-min coordinates of the bounding box respectively, "x2, y2" are x-max and y-max coordinates respectively and class is the name of the class the object belongs to.
Run the python script named "data_preprop.py" by copying your images and its respective xml files in the "train" folder.
$data_preprop.py --path train_dir --output train.txt
Training:
You can get the official faster R-CNN repository as a base code. But I have made few changes/corrections in the validation code and added video detection code in my github repository.
I have trained my model using google colab and can find further instructions in the "leaf_disease_detection_fasterRCNN_colab.ipynb" python notebook if you are using google colab.
Run the following code for training with data augmentation.
$python train_frcnn.py -o simple –p train.txt --hf --rot --num_epochs 50
The default parser is the pascal voc style parser, so change it to simple parser with –o simple. Data augmentation can be applied by specifying --hf for horizontal flips, --vf for vertical flips and --rot for 90 degree rotations.
Testing and Validation:
To run tests on Validation set and get the output score for each image in the validation set. First use the data_preprop.py to generate a validation.txt file. And run the measure_map.py.
test_frcnn.py will use the trained model on a folder of images and the output results get stored at test_results.
$ python test_frcnn.py -p test_dir
$ python data_preprop.py --path validation_dir --output validation.txt
$python measure_map.py -o simple -p validation.txt
video_frcnn.py will use the trained mode on a video and the output video gets stored at video_results.
$python video_stream.py -p test_video.mp4