ONNX 模型库
返回模型

说明文档

🎨 Author_ID — 动漫画师风格识别

<div align="center"> <a href="https://aniworldai.org/"> <img src="https://img.shields.io/badge/AniWorldAI-Official-blue?style=for-the-badge&logo=web" alt="AniWorldAI 网站"> </a> <a href="https://t.me/aniworldai"> <img src="https://img.shields.io/badge/Telegram-频道-2CA5E0?style=for-the-badge&logo=telegram" alt="Telegram 频道"> </a> <a href="https://t.me/aniworld_bot"> <img src="https://img.shields.io/badge/🔥_完整版3000位作者-在机器人中体验-orange?style=for-the-badge&logo=telegram" alt="体验完整版"> </a> </div>

<br>

🇨🇳 中文说明

Author_ID 是一个能够识别动漫插画艺术风格的 AI 模型,并从 Danbooru 数据库中找出最可能的画师。

可以把它看作是**"动漫艺术的 Shazam"**——上传任意插画,即可立即发现是谁画的,或与哪位画师的风格相似。

🧠 架构:艺术版 Face ID

该模型采用与 Apple Face ID 相同的架构原理构建:

Face ID Author_ID
将面部特征编码为嵌入向量 将艺术风格编码为嵌入向量
与存储的人脸模板进行比对 与画师风格质心进行比对
单张照片即可完成注册 支持少样本画师示例

模型生成 512 维风格嵌入向量,并通过余弦相似度与预计算的画师质心进行比对。

⚡ 少样本学习

与每个类别需要数千个样本的传统分类器不同,Author_ID 采用度量学习方法:

  • 添加新画师无需重新训练
  • 只需从 3-5 张样本图像计算质心
  • 在嵌入空间中即可即时搜索

📦 模型版本

版本 画师数量 获取方式
演示版(本仓库) 500 免费下载
完整版 3000+ Telegram 机器人

🏷️ 输出格式

返回相似度最高的前 5 位画师及其置信度分数:

(artist:hiten:0.87), (artist:saitom:0.72), (artist:anmi:0.68), ...

🚀 使用方法

安装

pip install onnxruntime onnx pillow numpy huggingface_hub
# GPU 版本:
pip install onnxruntime-gpu onnx pillow numpy huggingface_hub

推理

import onnxruntime as ort
import onnx
import numpy as np
from PIL import Image
import json
from huggingface_hub import hf_hub_download

# 从 HuggingFace 下载模型(自动缓存)
MODEL_PATH = hf_hub_download(
    repo_id="AugustLabs/Author_ID",
    filename=" style_predictor_500.onnx"
)

class AuthorID:
    """
    Author_ID: 动漫画师风格识别
    单个 ONNX 文件包含:模型 + 质心 + 画师名称
    """
    
    def __init__(self, onnx_path):
        # 加载元数据(画师名称嵌入在 ONNX 中)
        model_onnx = onnx.load(onnx_path)
        self.names = []
        self.input_size = 384
        
        for prop in model_onnx.metadata_props:
            if prop.key == "author_names":
                self.names = json.loads(prop.value)
            elif prop.key == "input_size":
                self.input_size = int(prop.value)
        
        providers = ['CUDAExecutionProvider', 'CPUExecutionProvider']
        self.session = ort.InferenceSession(onnx_path, providers=providers)
        
        self.mean = np.array([0.485, 0.456, 0.406], dtype=np.float32).reshape(1, 3, 1, 1)
        self.std = np.array([0.229, 0.224, 0.225], dtype=np.float32).reshape(1, 3, 1, 1)

    def preprocess(self, image_path):
        img = Image.open(image_path)
        
        # 处理透明度
        if img.mode in ('RGBA', 'LA') or (img.mode == 'P' and 'transparency' in img.info):
            bg = Image.new('RGB', img.size, (255, 255, 255))
            img = img.convert('RGBA')
            bg.paste(img, mask=img.split()[3])
            img = bg
        else:
            img = img.convert('RGB')
        
        img = img.resize((self.input_size, self.input_size), Image.BILINEAR)
        
        img_np = np.array(img, dtype=np.float32) / 255.0
        img_np = img_np.transpose(2, 0, 1)[np.newaxis, ...]
        img_np = (img_np - self.mean) / self.std
        
        return img_np

    def predict(self, image_path, top_k=5):
        """返回 (画师名称, 相似度分数) 列表"""
        img_np = self.preprocess(image_path)
        top_indices, top_scores = self.session.run(None, {'image': img_np})
        
        results = []
        for idx, score in zip(top_indices[0][:top_k], top_scores[0][:top_k]):
            results.append((self.names[idx], float(score)))
        
        return results

    def predict_tags(self, image_path, top_k=5):
        """返回格式化标签: (artist:名称:分数)"""
        results = self.predict(image_path, top_k)
        return [f"(artist:{name}:{score:.2f})" for name, score in results]


# === 使用示例 ===
if __name__ == "__main__":
    # 初始化(仅需一次)— 模型自动下载
    model = AuthorID(MODEL_PATH)
    
    # 预测
    results = model.predict("your_image.jpg", top_k=5)
    
    print("🎨 检测到的画师风格:")
    for author, score in results:
        print(f"   {author}: {score:.1%}")
    
    # 或获取格式化标签
    tags = model.predict_tags("your_image.jpg")
    print("\n📝 标签:", ", ".join(tags))

示例输出

🎨 检测到的画师风格:
   hiten_(hitenkei): 87.3%
   saitom: 71.8%
   anmi: 68.2%
   kantoku: 65.1%
   mishima_kurone: 62.4%

📝 标签: (artist:hiten_(hitenkei):0.87), (artist:saitom:0.72), (artist:anmi:0.68), (artist:kantoku:0.65), (artist:mishima_kurone:0.62)

📊 技术细节

参数
骨干网络 ConvNeXt-Tiny
嵌入维度 512
输入尺寸 384×384
训练数据 Danbooru(已过滤)
度量方式 余弦相似度
格式 ONNX (opset 17)

⚠️ 限制

  • 最适合动漫/漫画风格插画
  • 可能会混淆风格非常相似的画师
  • 严重裁剪低质量图像上置信度会下降
  • 演示版仅限 500 位画师

<div align="center">

🔥 想要完整的 3000+ 画师版本?

<a href="https://t.me/aniworld_bot"> <img src="https://img.shields.io/badge/体验完整版-Telegram_机器人-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white" alt="Telegram 机器人"> </a>

<br><br>

更多 AI 模型与资讯:

<a href="https://aniworldai.org/"> <img src="https://img.shields.io/badge/🌐_AniWorldAI.org-网站-blue?style=flat&logo=google-chrome" alt="网站"> </a> <a href="https://t.me/aniworldai"> <img src="https://img.shields.io/badge/📢_订阅-Telegram_频道-2CA5E0?style=flat&logo=telegram" alt="频道"> </a> <a href="https://huggingface.co/AniWorldAI"> <img src="https://img.shields.io/badge/🤗_更多模型-HuggingFace-yellow?style=flat" alt="HuggingFace"> </a>

</div>

AugustLabs/Author_ID

作者 AugustLabs

image-classification onnxruntime
↓ 0 ♥ 1

创建时间: 2025-11-30 09:14:52+00:00

更新时间: 2025-11-30 09:58:38+00:00

在 Hugging Face 上查看

文件 (3)

.gitattributes
README.md
style_predictor_500.onnx ONNX