Skip to main content

Anime Character Segmentation with DINOv2

Project description

AnimeSeg

GitHub release GitHub release Visitor Badge

Anime Character Segmentation using DINOv2 + U-Net++ with LoRA fine-tuning.

sample image

sample image

Installation

pip install anime_seg

Usage

from anime_seg import AnimeSegPipeline
pipe = AnimeSegPipeline.from_mask2former().to("cuda")
mask = pipe("path/to/image.jpg")
mask.save("output.png")

AnimeSegPipeline() default constructor is deprecated. Use from_mask2former() or from_dinoV2().

Optional: output size

# Same as input size (default)
mask_same = pipe("path/to/image.jpg")

# Fixed output size
mask_fixed = pipe("path/to/image.jpg", width=1024, height=1024)

# Width/height can be specified independently
mask_w = pipe("path/to/image.jpg", width=1024)
mask_h = pipe("path/to/image.jpg", height=1024)

Advanced Usage

# Load specific file from HF repo
pipe = AnimeSegPipeline.from_mask2former(
    repo_id="suzukimain/AnimeSeg",
    filename="models/anime_seg_mask2former_v3.safetensors"
).to(device="cuda")

# DINOv2 backend
pipe_dino = AnimeSegPipeline.from_dinoV2(
    filename="models/anime_seg_dinov2_v2.safetensors"
).to("cuda")

# Use PIL Image
from PIL import Image
img = Image.open("image.jpg")
mask = pipe(img)

Model Files

Models should follow the naming convention:

models/anime_seg_{architecture}_v{version}.safetensors

Example:

  • models/anime_seg_dinov2_v2.safetensors
  • models/anime_seg_mask2former_v3.safetensors

Resolution order:

  1. models/model_config.json
  2. fallback scan by models/anime_seg_{architecture}_v{max_version}.{ext}

Segmentation Classes and Mask Colors

Default from_mask2former() returns 12 classes:

ID Class Key RGB Color
0 background (0, 0, 0) Black
1 skin (255, 220, 180) Pale Orange
2 face (100, 150, 255) Blue
3 hair_main (255, 0, 0) Red
4 left_eye (0, 255, 255) Cyan
5 right_eye (255, 255, 0) Yellow
6 left_eyebrow (150, 255, 0) Yellow Green
7 right_eyebrow (0, 255, 100) Emerald Green
8 nose (255, 140, 0) Dark Orange
9 mouth (255, 0, 150) Magenta Pink
10 clothes (180, 0, 255) Purple
11 accessory (128, 128, 0) Olive

from_dinoV2() returns 13 classes (includes unknown as ID 12).

DINOv2 Compatibility Note

Earlier versions primarily used DINOv2. Current recommendation is from_mask2former(), while from_dinoV2() remains for compatibility.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anime_seg-0.1.6.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anime_seg-0.1.6-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file anime_seg-0.1.6.tar.gz.

File metadata

  • Download URL: anime_seg-0.1.6.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for anime_seg-0.1.6.tar.gz
Algorithm Hash digest
SHA256 1765e550a8fb9876f712c865f0fb25161526a47a5a0cb50df423012fa657c745
MD5 711e77051ab8ced06b90db2c24292617
BLAKE2b-256 9a7310164523ab48241bc52ce7d0d69bac2503eaf2f2803b2550a8b85bcdea08

See more details on using hashes here.

File details

Details for the file anime_seg-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: anime_seg-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for anime_seg-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2db7d941ad7b9d4358cedf5c239695fa5f32c4ec0f6783a0922d46ab1f02a6ec
MD5 b983e19f6fb19480b6acc458475894fd
BLAKE2b-256 dcb8bbfc569f9671cb198a158d6dd6e3abf5457dbce71e027f40cacc14d891f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page