animagine xl 4.0

提供商cagliostrolab
分类text-to-image
许可证openrail++
下载量9.7K
星标10

简介

Animagine XL 4.0 是一款深耕二次元领域的开源图像生成模型,基于 SDXL 架构并经过大规模动漫数据集精调。它解决了以往模型在处理复杂角色特征和特定画风时容易“崩坏”的痛点,能够精准还原动漫角色的服装与细节。对于国内创作者而言,它不仅支持高质量的立绘和场景生成,且对提示词的理解力更强,上手门槛低,是目前替代商业绘图软件、构建个人动漫资产的理想选择。

核心亮点

  • 极致的二次元画风还原,角色特征精准度高
  • 基于 SDXL 架构,兼容主流 Stable Diffusion 生态
  • 支持大规模标签控制,复杂场景构图能力强
  • 开源协议灵活,适合个人创作与商业工作流

使用方法

安装依赖
# 安装 Hugging Face transformers
pip install transformers torch
SDK 使用
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("cagliostrolab/animagine-xl-4.0")
tokenizer = AutoTokenizer.from_pretrained("cagliostrolab/animagine-xl-4.0")

Hugging Face 下载

我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 huggingface_hub:

操作指引
pip install -U huggingface_hub

命令行下载

下载完整模型库

下载完整模型库
huggingface-cli download cagliostrolab/animagine-xl-4.0

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download cagliostrolab/animagine-xl-4.0 config.json --local-dir ./dir

更多命令行下载选项,可参见官方文档

SDK 下载

SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('cagliostrolab/animagine-xl-4.0')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://huggingface.co/cagliostrolab/animagine-xl-4.0

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/cagliostrolab/animagine-xl-4.0

模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。

PyTorch / Transformers 使用

安装 Transformers

安装 Transformers
pip install -U transformers torch

模型加载和推理

模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained('cagliostrolab/animagine-xl-4.0')
tokenizer = AutoTokenizer.from_pretrained('cagliostrolab/animagine-xl-4.0')

模型下载

我们推荐使用命令行或者 ModelScope SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 ModelScope:

操作指引
pip install modelscope

命令行下载

下载完整模型库

下载完整模型库
modelscope download --model cagliostrolab/animagine-xl-4.0

下载单个文件到指定本地文件夹(以下载 README.md 到当前路径下 dir 目录为例)

下载单个文件到指定本地文件夹(以下载 README.md 到当前路径下 dir 目录为例)
modelscope download --model cagliostrolab/animagine-xl-4.0 README.md --local_dir ./dir

更多更丰富的命令行下载选项,可参见具体文档

SDK 下载

SDK 下载
# 模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('cagliostrolab/animagine-xl-4.0')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://www.modelscope.cn/cagliostrolab/animagine-xl-4.0.git

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://www.modelscope.cn/cagliostrolab/animagine-xl-4.0.git

ModelScope 模型页直接下载模型文件;无需将模型文件放在本站服务器。

Notebook 快速开发

下载并安装 ModelScope library

下载并安装 ModelScope library
pip install "modelscope[audio,cv,nlp,multi-modal,science]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html

模型加载和推理

模型加载和推理
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks

p = pipeline('text-generation', 'cagliostrolab/animagine-xl-4.0')

完整文档

来源: HuggingFace

---
language:

  • en

tags:
  • text-to-image

  • stable-diffusion

  • safetensors

  • stable-diffusion-xl

widget:
  • text: >-

1girl, green hair, sweater, looking at viewer, upper body, beanie, outdoors,
night, turtleneck, masterpiece, high score, great score, absurdres
parameter:
negative_prompt: >-
lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit,
fewer digits, cropped, worst quality, low quality, low score, bad score,
average score, signature, watermark, username, blurry
example_title: 1girl
  • text: >-

1boy, male focus, green hair, sweater, looking at viewer, upper body,
beanie, outdoors, night, turtleneck, masterpiece, high score, great score,
absurdres
parameter:
negative_prompt: >-
lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit,
fewer digits, cropped, worst quality, low quality, low score, bad score,
average score, signature, watermark, username, blurry
example_title: 1boy
license: openrail++
base_model:
  • stabilityai/stable-diffusion-xl-base-1.0

---

Animagine XL 4.0

!image/png

Overview

Animagine XL 4.0, also stylized as Anim4gine, is the ultimate anime-themed finetuned SDXL model and the latest installment of Animagine XL series. Despite being a continuation, the model was retrained from Stable Diffusion XL 1.0 with a massive dataset of 8.4M diverse anime-style images from various sources with the knowledge cut-off of January 7th 2025 and finetuned for approximately 2650 GPU hours. Similar to the previous version, this model was trained using tag ordering method for the identity and style training.
With the release of Animagine XL 4.0 Opt (Optimized), the model has been further refined with an additional dataset, improving stability, anatomy accuracy, noise reduction, color saturation, and overall color accuracy. These enhancements make Animagine XL 4.0 Opt more consistent and visually appealing while maintaining the signature quality of the series.

Changelog

  • 2025-02-13 – Added Animagine XL 4.0 Opt
- Better stability for more consistent outputs - Enhanced anatomy with more accurate proportions - Reduced noise and artifacts in generations - Fixed low saturation issues, resulting in richer colors - Improved color accuracy for more visually appealing results
  • 2025-01-24 – Initial release

Model Details

  • Model type: Diffusion-based text-to-image generative model
  • Model Description: This is a model that can be used to generate and modify specifically anime-themed images based on text prompt

Downstream Use

1. Use this model in our Hugging Face Spaces
2. Use it in ComfyUI or Stable Diffusion Webui
3. Use it with 🧨 diffusers

🧨 Diffusers Installation

1. Install Required Libraries

bash
pip install diffusers transformers accelerate safetensors --upgrade

2. Example Code

The example below uses lpw_stable_diffusion_xl pipeline which enables better handling of long, weighted and detailed prompts. The model is already uploaded in FP16 format, so there's no need to specify variant="fp16" in the from_pretrained call.
python
import torch
from diffusers import StableDiffusionXLPipeline

pipe = StableDiffusionXLPipeline.from_pretrained(
"cagliostrolab/animagine-xl-4.0",
torch_dtype=torch.float16,
use_safetensors=True,
custom_pipeline="lpw_stable_diffusion_xl",
add_watermarker=False
)
pipe.to('cuda')

prompt = "1girl, arima kana, oshi no ko, hoshimachi suisei, hoshimachi suisei \(1st costume\), cosplay, looking at viewer, smile, outdoors, night, v, masterpiece, high score, great score, absurdres"
negative_prompt = "lowres, bad anatomy, bad hands, text, error, missing finger, extra digits, fewer digits, cropped, worst quality, low quality, low score, bad score, average score, signature, watermark, username, blurry"

image = pipe(
prompt,
negative_prompt=negative_prompt,
width=832,
height=1216,
guidance_scale=5,
num_inference_steps=28
).images[0]

image.save("./arima_kana.png")

Usage Guidelines

The summary can be seen in the image for the prompt guideline.

!image/png

1. Prompt Structure

The model was trained with tag-based captions and the tag-ordering method. Use this structured template:
code
1girl/1boy/1other, character name, from which series, rating, everything else in any order and end with quality enhancement

2. Quality Enhancement Tags

Add these tags at the end of your prompt:
code
masterpiece, high score, great score, absurdres

3. Recommended Negative Prompt

code
lowres, bad anatomy, bad hands, text, error, missing finger, extra digits, fewer digits, cropped, worst quality, low quality, low score, bad score, average score, signature, watermark, username, blurry

4. Optimal Settings

  • CFG Scale: 4-7 (5 Recommended)
  • Sampling Steps: 25-28 (28 Recommended)
  • Preferred Sampler: Euler Ancestral (Euler a)

5. Recommended Resolutions

| Orientation | Dimensions | Aspect Ratio |
|------------|------------|--------------|
| Square | 1024 x 1024| 1:1 |
| Landscape | 1152 x 896 | 9:7 |
| | 1216 x 832 | 3:2 |
| | 1344 x 768 | 7:4 |
| | 1536 x 640 | 12:5 |
| Portrait | 896 x 1152 | 7:9 |
| | 832 x 1216 | 2:3 |
| | 768 x 1344 | 4:7 |
| | 640 x 1536 | 5:12 |

6. Final Prompt Structure Example

code
1girl, firefly \(honkai: star rail\), honkai \(series\), honkai: star rail, safe, casual, solo, looking at viewer, outdoors, smile, reaching towards viewer, night, masterpiece, high score, great score, absurdres

Special Tags

The model supports various special tags that can be used to control different aspects of the image generation process. These tags are carefully weighted and tested to provide consistent results across different prompts.

Quality Tags

Quality tags are fundamental controls that directly influence the overall image quality and detail level. Available quality tags:
  • masterpiece
  • best quality
  • low quality
  • worst quality

| <img src="https://cdn-uploads.huggingface.co/production/uploads/6365c8dbf31ef76df4042821/bDdKraYxjiReKknlYJepR.png" width="100%" style="max-height: 400px; object-fit: contain;"> | <img src="https://cdn-uploads.huggingface.co/production/uploads/6365c8dbf31ef76df4042821/mAgMMKL2tBj8oBuWHTYUz.png" width="100%" style="max-height: 400px; object-fit: contain;"> |
|---|---|
| Sample image using "masterpiece, best quality" quality tags with negative prompt left empty. | Sample image using "low quality, worst quality" quality tags with negative prompt left empty. |

Score Tags

Score tags provide a more nuanced control over image quality compared to basic quality tags. They have a stronger impact on steering output quality in this model. Available score tags:
  • high score
  • great score
  • good score
  • average score
  • bad score
  • low score

| <img src="https://cdn-uploads.huggingface.co