Skip to main content

Python API and CLI for the SmilingFox E621 image tagger

Project description

smilingfox

smilingfox banner

Python 3.10+ PyPI version Test status License: MIT Model on Hugging Face Author: Nolla Fox

InstallPython APICLIThresholdsDevelopmentModel details

Most taggers hand you one confidence slider and leave you to figure out the rest. smilingfox wraps the SmilingFox E621 tagger with something more deliberate: all 32,617 labels carry their own calibrated decision threshold, so a rare, easily-confused tag isn't held to the same bar as anthro or fur. Point it at an image or a folder and get tags back — as Python objects or .json sidecars, whichever fits the job.

Install

pipx install smilingfox

pipx keeps torch/timm and everything else out of your system Python. No pipx? brew install pipx on macOS, or python3 -m pip install --user pipx anywhere, then run pipx ensurepath once and restart your shell. Plain pip install smilingfox also works — you just lose the isolation.

Confirm it's on your PATH:

smilingfox --help

From source

For development on the package itself, or to run an unreleased version:

git clone git@github.com:nollafox/smilingfox.git
cd smilingfox
poetry install
poetry run smilingfox --help

pipx install . / pip install --user . from the checkout also put the smilingfox command on PATH without going through Poetry.

Python API

from smilingfox import Tagger

tagger = Tagger.from_pretrained()  # downloads and caches nollafox/smilingfox
prediction = tagger.predict("photo.jpg")

prediction.tags    # ("anthro", "mammal", "fur", ...)
prediction.scores  # {"anthro": 0.91, "mammal": 0.88, ...}

Tagger only builds the model once, so reuse it for batches instead of calling predict in a loop:

predictions = tagger.predict_batch(["a.jpg", "b.jpg", "c.jpg"], batch_size=8)

For a one-off script you don't need to construct a Tagger at all — smilingfox.tag() lazily loads and caches a default one the first time you call it:

import smilingfox

smilingfox.tag("photo.jpg").tags

from_pretrained takes either a Hugging Face repo id or a local bundle directory, so the same code works against a fine-tune or an offline copy:

tagger = Tagger.from_pretrained("/path/to/local/bundle", device="cuda")

Both predict and predict_batch also take required_confidence, applied as a floor on top of each label's own calibrated threshold — raise it when you want fewer, more confident tags:

tagger.predict("photo.jpg", required_confidence=0.5)

CLI

$ smilingfox tag ./photos                  # one .json sidecar per image
$ smilingfox tag photo.jpg --stdout        # print JSON instead of writing sidecars
$ smilingfox tag ./photos --confidence 0.5
$ smilingfox tag ./photos --device cuda --model /path/to/bundle

--stdout prints plain JSON, so it pipes straight into jq or a script. Progress and status messages go to stderr, not stdout, so they never end up mixed into the output:

$ smilingfox tag photo.jpg --stdout
{
  "tags": [
    "anthro",
    "mammal",
    "fur",
    "solo"
  ]
}

smilingfox info shows what's actually loaded — the fastest way to check that a --model override took effect before you tag a thousand images against the wrong bundle:

$ smilingfox info
                                 SmilingFox
┏━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ field              value                                                 ┃
┡━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ model dir          ~/.cache/huggingface/hub/models--nollafox--smilingfox │
│ base architecture  SmilingWolf/wd-swinv2-tagger-v3                       │
│ labels             32,617                                                │
│ device             mps                                                   │
└───────────────────┴───────────────────────────────────────────────────────┘

smilingfox tag --help / smilingfox info --help for the rest of the options.

How Thresholds Work

A single global cutoff treats every label the same, but not every label is equally hard to call. The 0.35 default is really a fallback: most of the 32,617 labels don't have enough training examples to earn their own confident cutoff, so they inherit it. The labels with enough support get their own threshold instead — picked by grid search to maximize that label's F1, then shrunk back toward the default in proportion to how little data backed it up. A well-supported, easy-to-separate label might settle near 0.24; a label the model tends to over-fire on might sit closer to 0.77.

--confidence / required_confidence doesn't replace that calibration, it sets a floor underneath it. Pass 0.5 and every label's effective threshold becomes max(calibrated_threshold, 0.5) — results get tighter without losing the higher bar already set on labels that needed one.

See the model card for the full calibration policy and the threshold distribution across all 32,617 labels.

Development

$ poetry install
$ poetry run smilingfox --help
$ poetry run pytest
$ poetry run python -m compileall -q src/smilingfox

Model details

See the model card for the base architecture and training configuration.



smilingfox — a calibrated multi-label tagger for e621 images.

Crafted with ❤️ by Nolla Fox

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

smilingfox-0.0.1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

smilingfox-0.0.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file smilingfox-0.0.1.tar.gz.

File metadata

  • Download URL: smilingfox-0.0.1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.12 Darwin/25.1.0

File hashes

Hashes for smilingfox-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d1069959b8e770aec4a6d0bbf694e0abb8648e75e555f55ad6dfeafcd52ff2f6
MD5 fb5e290566aee7eed83050cf873bd8ca
BLAKE2b-256 bc308469afe122b31f10633ac2edc698a93e8364c322dfce96aac2514f997c4d

See more details on using hashes here.

File details

Details for the file smilingfox-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: smilingfox-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.12 Darwin/25.1.0

File hashes

Hashes for smilingfox-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 54b106f3f96c2da919fc3674772c7aa50627eab4e04c47649dd1a028ddb5332c
MD5 0f8cc059c53b8265adee21767c72ff36
BLAKE2b-256 ab41c20b33216bc69dee12b971a0aa5f0aab7fd4dab72ace7380a99f9ee88e6a

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