HuggingFace镜像/marqo-fashionSigLIP
模型介绍文件和版本分析
下载使用量0

Marqo-FashionSigLIP 模型卡片

GitHub

Marqo Fashion Siglip 2 已发布。 与 marqo-fashion-SigLip 相比,marqo-fashion-SigLip-2 在 MMR 和召回率方面进一步提升了 78%。联系 Marqo 了解更多信息:https://www.marqo.ai/book-demo

Marqo-FashionSigLIP 是一款多模态嵌入模型,与 fashion clip 相比,其 MRR 和召回率最高可提升 57%。

Marqo-FashionSigLIP 利用了广义对比学习(GCL),该学习方法使模型不仅能基于文本描述进行训练,还能结合类别、风格、颜色、材质、关键词和细节特征,从而为时尚产品提供高度相关的搜索结果。该模型是在 ViT-B-16-SigLIP(webli)的基础上进行微调得到的。

GitHub 页面:Marqo-FashionCLIP

博客:Marqo 博客

使用方法

Hugging Face

可通过 AutoModel 加载模型,方法如下

from transformers import AutoModel, AutoProcessor
model = AutoModel.from_pretrained('Marqo/marqo-fashionSigLIP', trust_remote_code=True)
processor = AutoProcessor.from_pretrained('Marqo/marqo-fashionSigLIP', trust_remote_code=True)

import torch
from PIL import Image

image = [Image.open("docs/fashion-hippo.png")]
text = ["a hat", "a t-shirt", "shoes"]
processed = processor(text=text, images=image, padding='max_length', return_tensors="pt")

with torch.no_grad():
    image_features = model.get_image_features(processed['pixel_values'], normalize=True)
    text_features = model.get_text_features(processed['input_ids'], normalize=True)

    text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)

print("Label probs:", text_probs)
# [0.98379946, 0.01294010, 0.00326044]

OpenCLIP

该模型可通过以下方式与 OpenCLIP 无缝配合使用

import open_clip
model, preprocess_train, preprocess_val = open_clip.create_model_and_transforms('hf-hub:Marqo/marqo-fashionSigLIP')
tokenizer = open_clip.get_tokenizer('hf-hub:Marqo/marqo-fashionSigLIP')

import torch
from PIL import Image

image = preprocess_val(Image.open("docs/fashion-hippo.png")).unsqueeze(0)
text = tokenizer(["a hat", "a t-shirt", "shoes"])

with torch.no_grad(), torch.cuda.amp.autocast():
    image_features = model.encode_image(image, normalize=True)
    text_features = model.encode_text(text, normalize=True)

    text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)

print("Label probs:", text_probs)
# [0.9860219105287394, 0.00777916527489097, 0.006198924196369721]

Transformers.js

您也可以借助 Transformers.js 库在 JavaScript 中运行该模型。

首先,通过以下命令从 NPM 进行安装:

npm i @huggingface/transformers

然后,按如下方式计算嵌入:

import { SiglipTextModel, SiglipVisionModel, AutoTokenizer, AutoProcessor, RawImage, softmax, dot } from '@huggingface/transformers';

const model_id = 'Marqo/marqo-fashionSigLIP';

// Load tokenizer and text model
const tokenizer = await AutoTokenizer.from_pretrained(model_id);
const text_model = await SiglipTextModel.from_pretrained(model_id);

// Load processor and vision model
const processor = await AutoProcessor.from_pretrained(model_id);
const vision_model = await SiglipVisionModel.from_pretrained(model_id);

// Run tokenization
const texts = ['a hat', 'a t-shirt', 'shoes'];
const text_inputs = tokenizer(texts, { padding: 'max_length', truncation: true });

// Compute text embeddings
const { text_embeds } = await text_model(text_inputs);

// Read image and run processor
const image = await RawImage.read('https://raw.githubusercontent.com/marqo-ai/marqo-FashionCLIP/main/docs/fashion-hippo.png');
const image_inputs = await processor(image);

// Compute vision embeddings
const { image_embeds } = await vision_model(image_inputs);

// Compute similarity scores
const normalized_text_embeds = text_embeds.normalize().tolist();
const normalized_image_embeds = image_embeds.normalize().tolist()[0];

const text_probs = softmax(normalized_text_embeds.map((text_embed) => 
    100.0 * dot(normalized_image_embeds, text_embed)
));
console.log(text_probs);
// [0.9860219105287394, 0.00777916527489097, 0.006198924196369721]

基准测试结果

以下报告了在 6 个公开多模态时尚数据集(Atlas、DeepFashion (In-shop)、DeepFashion (Multimodal)、Fashion200k、KAGL 和 Polyvore)上的平均评估结果:

文本到图像(6 个数据集的平均值)

模型平均召回率(AvgRecall)召回率@1(Recall@1)召回率@10(Recall@10)平均倒数排名(MRR)
Marqo-FashionSigLIP0.2310.1210.3400.239
FashionCLIP2.00.1630.0770.2490.165
OpenFashionCLIP0.1320.0600.2040.135
ViT-B-16-laion2b_s34b_b88k0.1740.0880.2610.180
ViT-B-16-SigLIP-webli0.2120.1110.3140.214

类别到产品(5 个数据集的平均值)

模型平均精确率(AvgP)精确率@1(P@1)精确率@10(P@10)平均倒数排名(MRR)
Marqo-FashionSigLIP0.7370.7580.7160.812
FashionCLIP2.00.6840.6810.6860.741
OpenFashionCLIP0.6460.6530.6390.720
ViT-B-16-laion2b_s34b_b88k0.6620.6730.6520.743
ViT-B-16-SigLIP-webli0.6880.6900.6850.751

子类别到产品(4 个数据集的平均值)

模型平均精确率(AvgP)精确率@1(P@1)精确率@10(P@10)平均倒数排名(MRR)
Marqo-FashionSigLIP0.7250.7670.6830.811
FashionCLIP2.00.6570.6760.6380.733
OpenFashionCLIP0.5980.6190.5780.689
ViT-B-16-laion2b_s34b_b88k0.6380.6510.6240.712
ViT-B-16-SigLIP-webli0.6430.6430.6430.726