An AI tool that counts coins using computer vision
See YouTube video Build A Computer Vision App from Start to Finish
git clone https://github.com/Uniqcoda/money-app
cd money-app
Create a virtual environment. The common way to name virtual environments is env
. But you can give it a different name if you need to identify it elsewhere, like on Jupyter notebook or jupyterLab. So, we would use .coin_env
instead.
python3 -m venv .coin_env
Add this virtual environment to your .gitignore file, under the Environments
section, so you don't push it to GitHub.
source .coin_env/bin/activate # Linux/Mac
.\.coin_env\Scripts\activate # Windows
python3 -m pip install --upgrade pip
If working on Jupyter notebook, and you need the virtual env, run this code in your terminal, then go to jupyter nb and select the virtual env from the list of kernels.
pip install ipykernel
python3 -m ipykernel install --user --name=coin_env
On JupyterLab
python3 -m pip install --upgrade Pillow
Add collected images to the raw_images
folder
If running from vscode, run
python3 preprocess.py
If on Jupyter notebook, run the preprocess_images.ipynb
file
Your cleaned images should be in the /images folder.
=> This step would be done on the GCP VertexAI platform. Follow the image upload and labelling video for further instructions.
=> Also check out Vertex AI documentation on object detection. This docs is also applicable to model training, evaluation, deployment and testing.
This step is also done on GCP VertexAI platform. Follow the Model Training video for further instructions.
We would be using the endpoint from the deployed model in the previous step to create predictions for the web app.
- Install dependencies
pip install Flask google-cloud-aiplatform python-dotenv
- Create a new file named
.env
, under the root directory (main folder). Add the API keys and other environment variables to the .env file.
PROJECT_NUMBER=0000000000
LOCATION=europe-west4
ENDPOINT_ID=0000000000
API_ENDPOINT=europe-west4-aiplatform.googleapis.com
- Google cloud service account authentication
Ref: https://developers.google.com/identity/protocols/oauth2/service-account#python
Follow the setup instructions to (i) create a service account and (ii) create a service account key.
The new service account key will be downloaded to your computer. Move it to the directory/folder where you need it. Then add the file path to the script below and run
export GOOGLE_APPLICATION_CREDENTIALS="path/to/downloaded_key.json"
- Start the Flask app
flask run
Sample model prediction result for single object detection
python3 test-prediction.py
Result
{
"bboxes": [[0.316620409, 0.678313732, 0.435367882, 0.789723396]],
"confidences": [0.994227529],
"displayNames": ["2p"],
"ids": ["2112341057353023488"]
}
Docs: https://cloud.google.com/vertex-ai/docs/image-data/object-detection/interpret-results