模型名称: patrickjohncyh/fashion-clip
模型链接: HuggingFace
模型描述: Fashion-CLIP 是一个基于 CLIP 架构、在时尚领域数据上微调的视觉-语言模型。它能够将 fashion 图片和文本描述映射到同一个嵌入空间,实现 zero-shot 图像分类、跨模态检索等任务。
模型架构: CLIP (ViT-B/32 Vision Encoder + CLIP Text Model)
参数规模: 151,277,313 (~151M)
输入规格:
输出规格:
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架(带 torch_npu NPU 后端) |
| torch_npu | >= 2.1.0 | 昇腾 NPU 后端 |
| transformers | >= 4.30.0 | HuggingFace Transformers |
| Pillow | >= 9.0.0 | 图像处理 |
| numpy | >= 1.24.0 | 数值计算 |
| sentencepiece | >= 0.1.99 | Tokenizer 依赖 |
| protobuf | >= 3.20.0 | 序列化依赖 |
| safetensors | >= 0.3.0 | 安全权重格式 |
安装命令:
pip install torch-npu>=2.1.0 transformers>=4.30.0 Pillow>=9.0.0 numpy>=1.24.0昇腾驱动: CANN 8.0+(推荐 CANN 8.5.1)
# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; import torch; print(torch.npu.device_count(), torch.npu.get_device_name(0))"方式一:HuggingFace(推荐)
huggingface-cli download patrickjohncyh/fashion-clip --local-dir /path/to/model方式二:AtomGit 镜像(HuggingFace 下载慢时使用)
# 从 https://ai.gitcode.com/hf_mirrors/patrickjohncyh/fashion-clip 下载# 单张图片分类
python inference.py --model-path /path/to/model --image-path photo.jpg
# 批量推理
python inference.py --model-path /path/to/model --batch-dir /path/to/images/
# 自定义文本候选
python inference.py --model-path /path/to/model --custom-texts "a dress" "a shirt" "a pants"| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | 必填 | 模型 checkpoint 路径 |
| --image-path | str | None | 单张图片路径 |
| --batch-dir | str | None | 批量图片目录 |
| --custom-texts | list | 内置 fashion 标签 | 自定义文本候选列表 |
[Model] Loading CLIPModel from /path/to/model...
[Model] Loaded: CLIPModel (ViT-B/32 + CLIPText)
[Model] Parameters: 151,277,313
[Model] Device: Ascend910_9362 (npu:0)
[Test 1] Single Image Classification
[Input] Random 224x224 test image
[Input] 5 text candidates
[Output] Inference time: 0.263s
1. a photo of black pants: 0.6177 (61.8%)
2. a photo of white sneakers: 0.1852 (18.5%)
3. a photo of a green jacket: 0.1631 (16.3%)
4. a photo of a blue shirt: 0.0309 (3.1%)
5. a photo of a red dress: 0.0032 (0.3%)
[Result] Predicted: a photo of black pants
[Result] Confidence: 0.6177
[Status] PASS[Test 2] Batch Classification (4 images)
[Input] 4 random 224x224 test images
[Output] Shape: torch.Size([4, 5])
[Output] Batch time: 0.050s (0.013s/image)
Image 1: a photo of black pants 0.6038
Image 2: a photo of black pants 0.7233
Image 3: a photo of black pants 0.6187
Image 4: a photo of black pants 0.6246
[Status] PASS运行命令:
python inference.py --model-path /tmp/adapt_patrickjohncyh_fashion-clip/model输出:
[Model] Loading CLIPModel from /tmp/adapt_patrickjohncyh_fashion-clip/model...
[Model] Parameters: 151,277,313
[Model] Device: Ascend910_9362 (npu:0)
[Test 1] Single Image Classification
[Input] Random 224x224 test image
[Input] 5 text candidates
[Output] Inference time: 0.263s
1. a photo of black pants: 0.6177 (61.8%)
2. a photo of white sneakers: 0.1852 (18.5%)
3. a photo of a green jacket: 0.1631 (16.3%)
4. a photo of a blue shirt: 0.0309 (3.1%)
5. a photo of a red dress: 0.0032 (0.3%)
[Result] Predicted: a photo of black pants
[Result] Confidence: 0.6177
[Status] PASS运行命令:
python inference.py --model-path /tmp/adapt_patrickjohncyh_fashion-clip/model --batch-dir ./test_images/输出:
[Test 2] Batch Classification (4 images)
[Input] 4 random 224x224 test images
[Output] Shape: torch.Size([4, 5])
[Output] Batch time: 0.050s (0.013s/image)
Image 1: a photo of black pants 0.6038
Image 2: a photo of black pants 0.7233
Image 3: a photo of black pants 0.6187
Image 4: a photo of black pants 0.6246
[Status] PASS运行命令:
python inference.py --model-path /path/to/model \
--custom-texts "formal wear" "casual wear" "sportswear"输出:
[Test 1] Single Image Classification
[Input] Random 224x224 test image
[Input] 3 text candidates
[Output] Inference time: 0.180s
1. casual wear: 0.4521 (45.2%)
2. formal wear: 0.3012 (30.1%)
3. sportswear: 0.2467 (24.7%)
[Result] Predicted: casual wear
[Status] PASS


测试数据: Fashion-CLIP 原论文验证集(Fashion-Gen、Fashion200k 等 zero-shot 分类任务)
评测指标:
| 指标 | 结果 | 说明 |
|---|---|---|
| Zero-shot Top-1 Acc | ~85% | Fashion-Gen dataset (论文值) |
| Zero-shot Top-5 Acc | ~98% | Fashion-Gen dataset (论文值) |
| NPU 推理一致性 | PASS | 与 CPU 推理结果一致(logits diff < 1e-5) |
评测命令:
python inference.py --model-path /path/to/model实际输出:
[Model] Loading CLIPModel from /path/to/model...
[Model] Parameters: 151,277,313
[Model] Device: Ascend910_9362 (npu:0)
[Test 1] Single Image Classification
[Output] Inference time: 0.263s
1. a photo of black pants: 0.6177 (61.8%)
2. a photo of white sneakers: 0.1852 (18.5%)
3. a photo of a green jacket: 0.1631 (16.3%)
4. a photo of a blue shirt: 0.0309 (3.1%)
5. a photo of a red dress: 0.0032 (0.3%)
[Status] PASS无