基于CLIP的时尚推荐系统

一个基于AWS和CLIP技术的时尚推荐系统,能够通过上传的服装图片检测并推荐相似款式。

  • by attarmau
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 attarmau/FastMCP_RecSys

使用说明

AWS_RecSys

这是一个基于CLIP的AWS时尚推荐器。

📌 UI组件示例

  1. 图片上传
  2. 提交按钮
  3. 展示服装标签+推荐

模型

用户上传服装图片→ YOLO检测衣物→ CLIP编码→ 推荐类似

文件夹结构

/project-root
│
├── /backend
│   ├── Dockerfile            
│   ├── /app
│   ├── /aws
│   │   │   └── rekognition_wrapper.py         # AWS Rekognition logic
│   │   ├── /utils
│   │   │   └── image_utils.py                 # Bounding box crop utils
│   │   ├── /controllers
│   │   │   └── clothing_detector.py           # Coordinates Rekognition + cropping
│   │   ├── /tests
│   │   │   ├── test_rekognition_wrapper.py
│   │   │   └── test_clothing_tagging.py
│   │   ├── server.py                    # FastAPI app code
│   │   ├── /routes
│   │   │   └── clothing_routes.py
│   │   ├── /controllers
│   │   │   ├── clothing_controller.py
│   │   │   ├── clothing_tagging.py
│   │   │   └── tag_extractor.py         # Pending: define core CLIP functionality
│   │   ├── schemas/
│   │   │   └── clothing_schemas.py
│   │   ├── config/
│   │   │   ├── tag_list_en.py           $ Tool for mapping: https://jsoncrack.com/editor
│   │   │   ├── database.py       
│   │   │   ├── settings.py       
│   │   │   └── api_keys.py     
│   │   └── requirements.txt      
│   └── .env                      
│                      
├── /frontend 
│   ├── Dockerfile        
│   ├── package.json              
│   ├── package-lock.json         
│   ├── /public
│   │   └── index.html            
│   ├── /src
│   │   ├── /components            
│   │   │   ├── ImageUpload.jsx    
│   │   │   ├── DetectedTags.jsx   
│   │   │   └── Recommendations.jsx 
│   │   ├── /utils
│   │   │   └── api.js             
│   │   ├── App.js                    # Main React component
│   │   ├── index.js
│   │   ├── index.css            
│   │   ├── tailwind.config.js        
│   │   └── postcss.config.js                    
│   └── .env                                
├── docker-compose.yml                     
└── README.md 

快速入门指南

第一步:克隆GitHub项目

步骤2:设置Python环境

python -m venv venv
source venv/bin/activate  # On macOS or Linux
venv\Scripts\activate     # On Windows

步骤3:安装依赖项

pip install -r requirements.txt

步骤4:启动FastAPI服务器(后端)

uvicorn backend.app.server:app --reload

服务器运行并连接数据库后,您应该在控制台中看到以下消息:

Database connected
INFO:     Application startup complete.

步骤5:安装依赖项

数据库已连接 信息:应用程序启动完成。

npm install

步骤6:启动开发服务器(前端)

npm start

运行后,服务器会记录确认并在浏览器中打开应用程序: http://localhost:3000/

到目前为止完成了什么:

  1. FastAPI服务器已启动并运行(4月24日)
  2. 数据库连接已设置(4月24日)
  3. 后端架构功能正常(4月24日)
  4. 上传图片的基本前端UI(4月25日)

5.AWS Rekognition->边界框的模拟测试(5月15日)

PYTHONPATH=. pytest backend/app/tests/test_rekognition_wrapper.py
  • 使用模拟独立测试Rekognition集成逻辑→ 验证了它仅在标签与服装集匹配时正确提取边界框
  • 已确认文件夹结构和PYTHONPATH=。从根开始与pytest顺利配合

6.AWS Rekognition->CLIP的模拟测试(5月20日)

PYTHONPATH=. pytest backend/app/tests/test_clothing_tagging.py
  • 使用AWS Rekognition检测服装

  • 在检测到的边界框周围裁剪图像

  • 使用CLIP标记裁剪后的图像

7.完整图像标记管道的模拟测试(图像字节→ AWS Rekognition(检测服装)→ 裁剪图像→ CLIP(预测标签)+错误处理(5月25日)

阴性测试用例 描述
无检测结果 AWS未检测到任何服装——应返回空列表。
Image Not Clothing CLIP返回模糊或空的标签——验证回退行为。
AWS返回异常 模拟 rekognition.detect_labels 抛出错误--检查 try-except.
损坏的图像文件 模拟损坏的(非JPEG)图像——验证它是否引发错误或给出提示。
PYTHONPATH=. pytest backend/app/tests/test_clothing_tagging.py
  • detect_garments:模拟AWS Rekognition返回一个边界框:{“左”:0.1,“上”:0.1、“宽”:0.5、“高”:0.5}
  • crop_by_bounding_box:模拟裁剪步骤,返回一个虚拟的“cropped_image”对象
  • get_tags_from_clip:模拟clip返回标签列表:[“T-shirt”、“Cotton”、“Casual”]

8.运行CLIP输出测试(5月30日)

python3 -m venv venv
pip install -r requirements.txt
pip install git+https://github.com/openai/CLIP.git
python -m backend.app.tests.test_tag_extractor

下一步:

  1. 评估CLIP在样本服装图像上的标记准确性
  2. 微调标记系统以获得更好的建议
  3. 测试后端与实时用户数据的集成
  4. 设置模型性能监控
  5. 前端演示