Botanical gardens and flower enthusiasts often encounter difficulties in manually identifying various flower species, especially when dealing with a large number of species. Automated flower classification aided by machine learning can significantly aid in the identification process and improve efficiency. This project showcases a simple use case of classifying if a given image of a flower is a Daisy or a Dandelion. This can easily be extended to scale to many flower categories.
Used the Kaggle
flower classification data set, which has been collected from scraped data from flickr
, Google
, and Yandex
images.
Machine Learning:
- Utilized the capabilities of state-of-the-art architecture provided by
Keras
. - Employed the transfer learning technique to construct two distinct models based on Inception and MobileNet.
Tuning:
- Trained with various learning rates, added additional inner layers, regularization and augmentation.
Model Evaluation:
- After thorough evaluation, selected MobileNet as the final model due to its compactness and efficiency, with comparable accuracy to Inception but with fewer parameters.
Ease of Use:
- Containerized using Docker and serviced by REST APIs using Flask.
Cloud Deployment:
- Deployed model to AWS Lambda.
User Friendly Interface:
- Web interface deployed as
streamlit
web app.
Python 3.8
Docker
git clone https://github.com/PriyaVellanki/flower_classification.git
- flower_classification (root)
- app (Flask API service)
- serverless (AWS Lambda Deployment and Docker File)
- model (final model)
- data (Jupyter Notebook files and env files)
pip install pipenv
pipenv --python 3.8
pipenv install
pipenv shell
# install tflite-runtime
pip install --extra-index-url https://google-coral.github.io/py-repo/ tflite_runtime
GPU is needed to run the notebook. One can run on Google Collab
and any other platform which supports GPU. It does save models multiple models from Mobilenet
and Xcpetion
. Make sure to delete unwanted files to make sure disk is not getting full.
- Clone the repo
pipenv install
pipenv shell
pip install --extra-index-url https://google-coral.github.io/py-repo/ tflite_runtime
cd app/
( This is needed to make sure model is accessed from the right directory for local testing)- Run
python3 app/predict.py
- In another window, run the
python3 test_api.py
You should see the result similar to below:
(flower_classification) (base) XXXX-MacBook-Air app % python3 test_api.py
{'daisy': 0.9988572001457214, 'dandelion': -4.313272953033447}
- Change to serverless directory.
cd flower_classification/serverless
docker build --platform linux/amd64 -t flower-classifcation:v1 .
docker run --platform linux/amd64 --rm -p 9000:8080 flower-classifcation:v1
- Make sure
docker container
is running. You can check this by runningdocker ps
. - Run the
python3 test_docker_local.py
orcurl "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"url":"https://github.com/PriyaVellanki/flower_classification/raw/main/data/11124324295_503f3a0804.jpg"}'
Expected result:
flower_classification % curl "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"url":"https://github.com/PriyaVellanki/flower_classification/raw/main/data/11124324295_503f3a0804.jpg"}'
{"daisy": 0.9988558292388916, "dandelion": -4.313270568847656}
Hosted on AWS Lambda
and Streamlit
Cloud
AWS Lambda Setup Instructions: Official instructions for reference: https://docs.aws.amazon.com/lambda/latest/dg/python-image.html#python-image-instructions
- Build, tag and run docker container image :
docker tag flower_classification:latest ${REMOTE_URI}
- Login to AWS ECR:
aws ecr get-login-password | docker login --username AWS --password-stdin <account_url>
- Create AWS elastic container registry (ECR) repository to store the image :
aws ecr create-repository --repository-name <repo_name>
- Publish docker container image to ECR repository as tagged image :
docker push ${REMOTE_URI}
- Create, configure and test AWS Lambda function
- Create, configure and test AWS Rest API Gateway to access Lambda function
- Make prediction using POST METHOD /predict
Run the following command to test:
curl 'https://ivw7r2k600.execute-api.us-west-1.amazonaws.com/stage/predict' -d '{"url":"https://github.com/PriyaVellanki/flower_classification/raw/main/data/11124324295_503f3a0804.jpg"}'
Expected output:


App url : https://flowerclassification-daisyordandelion.streamlit.app/
Streamlit
is an open-source Python framework for machine learning and data science teams.
- Open the App url in the browser:
https://flowerclassification-daisyordandelion.streamlit.app/
- Download the test data from
https://github.com/PriyaVellanki/flower_classification/raw/main/data/11124324295_503f3a0804.jpg
and upload image in the web app - Click on
Predict
to see the result
Streamlit webapp result example:
