A microservice for generating and managing image embeddings for fashion products using ResNet50. The service provides similarity search capabilities based on visual features extracted from product images.
- Generate embeddings from fashion product images using ResNet50
- Store embeddings in Redis for fast similarity search
- RESTful API for embedding generation and similarity search
- Asynchronous processing with Celery
- Docker support for easy deployment
- Docker and Docker Compose
- Python 3.8+
- Redis
- Clone the repository:
git clone <repository-url>
cd fashion-image-processor- Create required directories:
mkdir embeddings- Start the services using Docker Compose:
docker compose up -dThis will start:
- FastAPI application on port 4000
- Redis on port 6379
- Celery worker for background tasks
POST /embeddings/generateGenerates embeddings for all products in the database.
POST /embeddings/product/{product_id}Generates an embedding only for the product with the given product ID.
PUT /embeddings/product/{product_id}Updates the embedding for the product with the given product ID.
DELETE /embeddings/product/{product_id}Deletes the embedding for the product with the given product ID.
GET /similar-products/{product_id}?top_n=5Returns the most similar products based on image embeddings.
GET /pingReturns the service status.
- Create a virtual environment:
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# or
.venv\Scripts\activate # Windows- Install dependencies:
pip install -r requirements.txt- Run Celery worker:
celery -A app.celery_config.celery_app worker --loglevel=infoThe service consists of several components:
- FastAPI application for HTTP endpoints
- ResNet50 model for feature extraction
- Redis for embedding storage
- Celery for background task processing
Environment variables:
API_BASE_URL: Base URL for the fashion APIREDIS_URL: Redis connection URLCELERY_BROKER_URL: Celery broker URL
curl -X POST "http://localhost:4000/embeddings/generate" \
-H "Content-Type: application/json"curl -X POST "http://localhost:4000/embeddings/product/123" \
-H "Content-Type: application/json"curl -X PUT "http://localhost:4000/embeddings/product/123" \
-H "Content-Type: application/json"curl -X DELETE "http://localhost:4000/embeddings/product/123" \
-H "Content-Type: application/json"curl -X GET "http://localhost:4000/similar-products/123?top_n=5" \
-H "Content-Type: application/json"MIT License
client = ApiClient(base_url="https://fashion.aknevrnky.dev")
image_data = await client.get_product_image(product_id=1)
image_data = await client.get_product_image(image_url="https://fashion.aknevrnky.dev/storage/products/10000.jpg")
from PIL import Image import io image = Image.open(io.BytesIO(image_data))