🚀 水印检测-SigLIP2
水印检测-SigLIP2是一个基于视觉语言的编码器模型,它从google/siglip2-base-patch16-224微调而来,用于二分类图像分类任务。该模型经过训练,能够检测图像是否包含水印,采用了SiglipForImageClassification架构。

🚀 快速开始
安装依赖
pip install -q transformers torch pillow gradio
推理代码
import gradio as gr
from transformers import AutoImageProcessor, SiglipForImageClassification
from PIL import Image
import torch
model_name = "prithivMLmods/Watermark-Detection-SigLIP2"
model = SiglipForImageClassification.from_pretrained(model_name)
processor = AutoImageProcessor.from_pretrained(model_name)
id2label = {
"0": "无水印",
"1": "有水印"
}
def classify_watermark(image):
image = Image.fromarray(image).convert("RGB")
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
prediction = {
id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))
}
return prediction
iface = gr.Interface(
fn=classify_watermark,
inputs=gr.Image(type="numpy"),
outputs=gr.Label(num_top_classes=2, label="水印检测"),
title="水印检测-SigLIP2",
description="上传一张图片以检测是否包含水印。"
)
if __name__ == "__main__":
iface.launch()
✨ 主要特性
- 基于SigLIP2架构:从google/siglip2-base-patch16-224微调而来,具有良好的视觉语言编码能力。
- 二分类图像分类:专注于检测图像是否包含水印。
- 多场景应用:可用于内容审核、数据集清理、版权保护和数字取证等场景。
📚 详细文档
标签空间:2 个类别
该模型将图像分类为以下两类:
类别 0: "无水印"
类别 1: "有水印"
分类报告
分类报告:
精确率 召回率 f1分数 样本数
无水印 0.9290 0.9722 0.9501 12779
有水印 0.9622 0.9048 0.9326 9983
准确率 0.9427 22762
宏平均 0.9456 0.9385 0.9414 22762
加权平均 0.9435 0.9427 0.9424 22762
演示推理
⚠️ 重要提示
水印检测在清晰、高质量的图像上效果最佳。不建议使用有噪声的图像进行验证。
有水印的图像示例

无水印的图像示例

预期用途
水印检测-SigLIP2 在以下场景中非常有用:
- 内容审核 – 自动检测图像分享平台上的水印内容。
- 数据集清理 – 从训练数据集中过滤掉带有水印的图像。
- 版权保护 – 监控并标记使用带有水印的媒体。
- 数字取证 – 支持对篡改或受保护的媒体资产进行分析。
📄 许可证
本项目采用Apache-2.0许可证。
引用
SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features https://arxiv.org/pdf/2502.14786