This code allows you to detect pests in several species of edible plants: potatoes, tomatoes, cherries, orange trees ... among others. Use tensorflow and I can do it with images, videos, or in real time with a pc and a camera or a raspberry pi with a camera. To use my code, you must have installed tensorflow and opencv. You will be able to detect the following pests:
Spider tomato
healthy raspberry
leaf spot isariopisis grape
stain leaf gray corn
Healthy mnanzana
Cedar apple scab
dusty mildew green leaves
tomato mosaic virus
healthy cherry
northern tizon or maiz leaf
healthy peach
cherry mushroom podosphaera clandestine
greening orange
tomato late blight
tomato bacterial spot
healthy grape
common mold corn
tomato leaf mold
bacterial blotch peppers
grape black rot
early tomato
healthy strawberry
leaf spot tomato
grape measles
curl virus yellow leaf tomato
scorched leaf strawberry
healthy potato
pudridumbrenegraen-apples
healthy blueberries
late tizon potato
healthy pepper
healthy tomato
early tizon potato
costra apple
tomato focus point
healthy soy
healthy corn
peach bacterial blotch
https://www.tensorflow.org/install/install_raspbian
https://www.tensorflow.org/install/install_linux
https://www.pyimagesearch.com/2016/04/18/install-guide-raspberry-pi-3-raspbian-jessie-opencv-3/
https://drive.google.com/drive/folders/1sowAcyeYXFCnhekE-WSOxUt5PASTijLq
recognition.py
#Loads label file, strips off carriage return
label_lines = [line.rstrip () for line
in tf.gfile.GFile ("retrained_labels11.txt")]
with tf.gfile.FastGFile ("retrained_graph11.pb", 'rb')
Modify there the route where you have saved the model that you have downloaded.
#if you use a video place your video here:
video = 'march.mp4'
#if you use a video uncomment this line:
"cam = cv2.VideoCapture (video)"
#This line is to make the detection in real time through your camera, comment on it if you do it with video:
"cam = cv2.VideoCapture (0)"
There, comment or uncomment the code according to your need if you want to do it in real time with a camera or if you want to do the detection from a video.
python recognition.py
You should first see the prediction that corresponds to the type of pest you are detecting.
labelimage.py
python labelimage.py "path of the image you want to try"
https://github.com/VikramTiwari/tensorflow-retrain-sample
If you speak English you will want to understand your model in English, so you can download the original dataset from here and train with those images so that your human text is in English:
https://github.com/salathegroup/plantvillage_deeplearning_paper_dataset/tree/master/raw/color
If you want to understand the model for use on mobile devices, you can see this guide, you will use mobilenet for this purpose :
https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/index.html#3
https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.md
Then you must convert your model to a Lite type model to work in android studio, and the build.gradle can recognize it. Use this command, it works fine on Ubuntu 16.04, you will use it for this purpose, Toco is installed when you install tensorflow:
toco --input_file=tf_files/retrained_graph.pb --output_file=tf_files/optimized_graph.lite --input_format=TENSORFLOW_GRAPHDEF
--output_format=TFLITE --input_shape="1,224,224,3" --input_array=input --output_array=final_result --inference_type=FLOAT --input_data_type=FLOAT
optimized_graph.lite
Now you must copy your model to android studio, you can follow this guide to configure your android studio in ubuntu 16.04:
https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2-tflite/#3