To build our flower classifier, we are going to use the Flowers Recognition dataset provided by Kaggle. The pictures are divided into five classes: daisy, tulip, rose, sunflower, dandelion. For each class there are about 800 photos.
Dividing data into Training and Validation Sets
Since our data is not already segregated into training and validation sets, we are going to divide them on our own using the ‘os’ and ‘shutil’ modules. (Assuming current path of dataset is data/flowers-kaggle)
Importing packages and setting batch Size
from fastai import *
from fastai.vision import *bs = 64
Looking at the Data
We always need to understand very well what the problem is and what the data looks like before we can figure out how to solve it. Taking a look at the data means understanding how the data directories are structured, what the labels are and what some sample images look like.
Your output should look like this:
Congratulations! Our model is now trained and you can see its accuracy is more than 90%.
Testing our classifier on custom input
We can test our classifier by passing it any image of our choice and seeing how well it works. For this, we need to create a folder called test and put our custom file in it. To see the classifier’s output , we first get its predictions on the image for all classes , pick the class which has the highest prediction and then return the class label of that class: