标签:
- 剪辑
库名称: open_clip
管道标签: 零样本图像分类
许可证: mit
语言:
- 英语
- 中文
- 葡萄牙语
- 西班牙语
- 法语
- 德语
- 荷兰语
- 意大利语
- 韩语
- 俄语
基础模型:
- laion/CLIP-ViT-B-32-xlm-roberta-base-laion5B-s13B-b90k
RS-M-CLIP:面向遥感领域的多语言视觉-语言预训练模型
本文是题为《面向遥感领域的多语言视觉-语言预训练》的官方仓库,论文链接:Multilingual Vision-Language Pre-training for the Remote Sensing Domain
作者:
若昂·丹尼尔·席尔瓦,INESC-ID,里斯本高等技术学院,里斯本大学
若昂·马加良斯,NOVA-LINCS,科学技术学院,新里斯本大学
德维斯·图亚,ECEO,洛桑联邦理工学院
布鲁诺·马丁斯,INESC-ID & LUMLIS,里斯本高等技术学院,里斯本大学
摘要
基于对比语言-图像预训练(CLIP)的方法如今广泛应用于支持涉及遥感数据的视觉-语言任务,如跨模态检索。CLIP在该领域的适应主要依赖于使用标准对比目标进行模型微调,利用现有的人工标注图像-标题数据集,或使用从遥感图像其他标注(如对象类别)派生的合成图像-标题对数据。不同预训练机制的使用较少受到关注,仅有少数例外考虑了多语言输入。本研究提出了一种面向遥感领域的新型视觉-语言模型,探索了多语言CLIP模型的微调,并测试了基于对齐单个输入图像的局部和全局表示的自监督方法,结合标准CLIP目标的使用。模型训练依赖于整合现有的遥感图像与英文标题配对的数据集,随后使用自动机器翻译将其转化为九种其他语言。我们表明,翻译数据确实有帮助,例如也能提高英语性能。我们最终的模型,命名为遥感多语言CLIP(RS-M-CLIP),在各种视觉-语言任务中取得了最先进的结果,包括跨模态和多语言图像-文本检索,或零样本图像分类。
描述
(Remote Sensing Multilingual CLIP)RS-M-CLIP是一个面向遥感领域的基于CLIP的模型。我们通过整合可用的图像-标题配对数据集,结合自蒸馏方法与对比学习目标,并使用不同语言翻译的标题,在不增加训练数据量的情况下提高了CLIP的性能。我们从具有多语言文本编码器的CLIP模型开始训练,视觉编码器为ViT-B:https://huggingface.co/laion/CLIP-ViT-B-32-xlm-roberta-base-laion5B-s13B-b90k。我们的模型在跨模态图像-文本检索方面取得了最先进的结果,并具有多语言能力,能够处理英语以外的其他语言。
支持的语言:英语、葡萄牙语、西班牙语、法语、德语、荷兰语、意大利语、中文、韩语和俄语。
您可以从huggingface-hub仓库下载RS-M-CLIP:https://huggingface.co/joaodaniel/RS-M-CLIP
代码示例
要加载模型,OpenCLIP库将从huggingface hub加载存储的权重。
import torch
import open_clip
model, preprocess, preprocess_val = open_clip.create_model_and_transforms('hf-hub:joaodaniel/RS-M-CLIP')
tokenizer = open_clip.get_tokenizer('hf-hub:joaodaniel/RS-M-CLIP')
图像分类(英语)
以下是使用英语文本查询进行图像分类的示例。
model = model.eval()
from PIL import Image
image = preprocess(Image.open('figs/airplane_004.jpg')).unsqueeze(0)
text_queries = [
"A residential area with houses.",
"Blocks of buildings can be seen in the factory .",
"Dense residential areas on both sides of the road .",
"Many airplanes in the open area.",
"A cute cat",
]
text = tokenizer(text_queries)
with torch.no_grad():
image_features = model.encode_image(image)
text_features = model.encode_text(text)
image_features /= image_features.norm(dim=-1, keepdim=True)
text_features /= text_features.norm(dim=-1, keepdim=True)
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1).cpu().numpy()[0]
for query, prob in zip(text_queries, text_probs):
print(f"{query:<40} {prob * 100:5.1f}%")
输出如下:
A residential area with houses. 0.0%
Blocks of buildings can be seen in the factory . 0.0%
Dense residential areas on both sides of the road . 0.0%
Many airplanes in the open area. 100.0%
A cute cat 0.0%
图像分类(西班牙语)
model = model.eval()
from PIL import Image
image = preprocess(Image.open('figs/golf_course_004.jpg')).unsqueeze(0)
text_queries = [
"Una zona residencial con casas.",
"Se pueden ver bloques de edificios en la fábrica.",
"Zonas residenciales densas a ambos lados de la carretera.",
"Muchos aviones en el área abierta.",
"Un lindo gato",
"Un campo de golf con bunkers."
]
text = tokenizer(text_queries)
with torch.no_grad():
image_features = model.encode_image(image)
text_features = model.encode_text(text)
image_features /= image_features.norm(dim=-1, keepdim=True)
text_features /= text_features.norm(dim=-1, keepdim=True)
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1).cpu().numpy()[0]
for query, prob in zip(text_queries, text_probs):
print(f"{query:<60} {prob * 100:5.1f}%")
输出如下:
Una zona residencial con casas. 0.0%
Se pueden ver bloques de edificios en la fábrica. 0.0%
Zonas residenciales densas a ambos lados de la carretera. 0.0%
Muchos aviones en el área abierta. 0.0%
Un lindo gato 0.0%
Un campo de golf con bunkers. 100.0%
引用
如果您觉得我们的工作有用🙏,请引用我们:
@article{silva2024large,
title={Multilingual Vision-Language Pre-training for the Remote Sensing Domain},
author={Silva, Jo{\~a}o Daniel and Magalh{\~a}es, Jo{\~a}o and Tuia, Devis and Martins, Bruno},
journal={arXiv:2410.23370},
year={2024}
}