An API that uses computer vision and semantic textual analysis to recognize clothing items through images.
Explore the docs »
Watch a demo »
Table of Contents
The Garment Recognition API is a RESTful API that uses computer vision and semantic textual analysis to recognize clothing items through images. The project was developed by a team of 5 students as part of BCIT's COMP 3800 course. The API leverages Azure's Dense Captioning model to generate textual descriptions of images, which are then processed by a custom-built NLP model to extract relevant information about the clothing items. The server is built using Flask and the API is documented using Swagger.
The following instructions will guide you through setting up the project on your local machine.
-
Python (version 3.11 or higher)
- Download and install Python from here.
- Ensure that you check the box that says "Add Python to PATH" during installation.
- Ensure that you check the box that says "Install pip" during installation.
- Verify installation by running the following command in your terminal:
python --version # Check the version of Python - Download and install Python from here.
-
Pip (Python package installer)
- Verify installation by running the following command in your terminal:
pip --version # Check the version of pip -
Git (optional, but recommended)
- Download and install Git from here.
- Verify installation by running the following command in your terminal:
git --version # Check the version of Git -
VSCode (or any other code editor).
- Download and install VSCode from here.
-
An Azure Dense Captioning model API Key.
-
An NVIDIA GPU (optional, but recommended for faster processing).
-
Clone the repo (or download the ZIP file and extract it to a folder on your local machine)
git clone https://github.com/ChinaiArman/GarmentRecognitionAPI.git # Clone the repository -
Create a virtual environment
2.1 Create a virtual environment using the following commands:
cd GarmentRecognitionAPI # Change to the project directory python -m venv .venv # Create a virtual environment
2.2 Activate the virtual environment:
- Mac:
- Activation command:
source .venv/bin/activate # Activate the virtual environment
- Deactivation command:
source .venv/bin/deactivate # Deactivate the virtual environment
- Activation command:
- Windows:
- Activation command:
.venv\Scripts\activate.bat # Activate the virtual environment
- Deactivation command:
.venv\Scripts\deactivate.bat # Deactivate the virtual environment
- Activation command:
- Mac:
-
Install required Python libraries
cd server # Change to the server directory pip install -r requirements.txt # Install the required libraries
- If after running the command, none of the packages have installed, restart the terminal and try again, ensuring that the virtual environment is activated.
- If a single package fails to install, try installing it separately using the following command:
pip install <package_name> # Install the package separately
-
Set up environment variables
- Create a
.envfile in the server directory of the project. - Add the following environment variables to the
.envfile:
AZURE_VISION_ENDPOINT="" # your_azure_vision_endpoint AZURE_VISION_KEY_1="" # your_azure_vision_key AZURE_VISION_KEY_2="" # your_azure_vision_key RAPID_API_KEY="" # your_rapid_api_key EMBEDDED_MODEL="" # your_embedded_model DATA_SOURCE_FILE="" # your_data_source_file PYTHONPATH="server" # Set the PYTHONPATH to "server"
- Replace the placeholder values with your own API keys and file paths.
- Note:
RAPID_API_KEYis only used within the data aggregation module. You can obtain an API key by creating an account here. If you do not plan to use that module for gathering clothing data then this can be left empty. - Note:
DATA_SOURCE_FILEis the path to the data source file. This file can be modified to point to any CSV file with the appropriate columns. - Note:
EMBEDDED_MODELis the name of the HuggingFace model that you want to use for the NLP processing. The model can be substituted with any other model from the HuggingFace model hub, but we suggest usinggte-smallfor optimal results.
- Create a
-
Start the server by running the following command:
cd .. # Return to the root directory python server/app.py # Start the server
-
Access the API documentation at
http://localhost:5000/to view the available endpoints and interact with the API. -
You can also use client software of your choice (cURL, Postman, etc.) to send HTTP requests to the endpoints. The API documentation will guide you in how to format any request bodies and path parameters for the HTTP requests.
The full API can be deployed to a cloud platform such as Azure or AWS directly.
- Ensure that the required environment variables are set in the deployment environment.
- Set the entry point of the server to
server/app.py. - Deploy the server to the cloud platform of your choice. The server will serve the Swagger UI at the root URL, and will respond to all other API requests as a RESTful API.
The API server can be deployed to a cloud platform such as Azure or AWS with minimal changes.
-
Ensure that the required environment variables are set in the deployment environment.
-
In app.py, change the initialization of the Flask app (line 29 in
server/app.py) to the following:app = Flask(__name__)
-
In app.py, change the root route of the Flask server (line 330 in
server/app.py) to the following:return jsonify("Hello World")
-
Deploy the server folder to the cloud platform of your choice.
The Swagger frontend can be deployed to GitHub Pages or any other static site hosting service.
- A guide to deploying the Swagger UI to GitHub can be found here.
- Swagger can also be deployed on any major cloud platform such as Azure or AWS.
The Swagger YAML file can be found here. Ensure that all references to the server are updated to the deployed server URL.
Arman Chinai:
Lex Wong:
Natalie Yu:
Ehsan Emadi:
Collin Chan:
Project Link:
-
Chris Thompson - Project Supervisor
-
Farnaz Dargahi - COMP 3800 Instructor
-
Laura Aslan - Founder and CEO of Odd Fabric, owner of this product
-
Will Stahl - Laura’s business partner, co-owner of this product
Thank you for your continued support throughout the project!
