APP Link : https://cloth-recommendation.streamlit.app/
This project provides a clothing similarity recommendation system using a deep learning feature extractor and a FastAPI backend. A pre-trained MobileNet model is fine-tuned on a custom dataset to extract image features, which are stored in a SQLite database. Users can upload images to find visually similar clothing items.
- Python 3.8 or higher
- pip
- Virtual environment tool (optional but recommended)
- Clone the repository:
git clone <repo_url> cd "Cloth Similarity"
- Create and activate a virtual environment:
python -m venv cloth_env # Windows cloth_env\Scripts\activate.bat # macOS/Linux source cloth_env/bin/activate
- Install required packages:
pip install -r requirements.txt
- Launch Jupyter Notebook:
jupyter notebook exp.ipynb
- In
exp.ipynb:- Run cells to load and preprocess data from
dataset/trainanddataset/test. - Perform data augmentation with
ImageDataGenerator. - Load MobileNet base model (weights from ImageNet) and build a custom classifier on top.
- Train the model for 10 epochs.
- Fine-tune by unfreezing the base model and re-running training for another 10 epochs.
- Save the feature extractor:
feature_extractor.save('feature_extractor.keras')
- Run cells to load and preprocess data from
The FastAPI app (api.py) provides two endpoints:
-
POST
/reset_and_update_db- Deletes existing
textile.dbif present. - Crawls product images from the configured base URL.
- Extracts features using the saved feature extractor and populates the SQLite database.
- Returns a success message.
- Deletes existing
-
POST
/upload- Accepts an image file upload.
- Preprocesses and extracts features.
- Queries the database for the top 5 visually similar items using cosine similarity.
- Returns the list of image URLs with similarity scores.
uvicorn api:app --reloadThe API will be available at http://127.0.0.1:8000.
- Reset and populate the database:
curl -X POST http://127.0.0.1:8000/reset_and_update_db
- Upload an image to get recommendations:
curl -X POST -F "file=@path/to/image.jpg" http://127.0.0.1:8000/upload
dataset/
train/
pants/
shirt/
shorts/
t-shirt/
test/
pants/
shirt/
shorts/
t-shirt/
This project is licensed under the MIT License.