Views
No views yet
| # | Macro@0.40 (F1/MCC/P/R) | Micro@0.40 (F1/MCC/P/R) | Macro@Best (F1/P/R) |
|---|---|---|---|
| Validation | 0.545 / 0.551 / 0.601 / 0.519 | 0.688 / 0.687 / 0.689 / 0.687 | --- |
| Test | 0.546 / 0.552 / 0.602 / 0.519 | 0.689 / 0.688 / 0.690 / 0.688 | 0.581 / 0.585 / 0.599 |
Macro/Micro@0.40 means the metrics on the threshold 0.40.Macro@Best means the mean metrics on the tag-level thresholds on each tags, which should have the best F1 scores.| Category | Name | Alpha | Threshold | Micro@Thr (F1/P/R) | Macro@0.40 (F1/P/R) | Macro@Best (F1/P/R) |
|---|---|---|---|---|---|---|
| 0 | general | 1 | 0.39 | 0.676 / 0.672 / 0.680 | 0.418 / 0.485 / 0.388 | 0.459 / 0.457 / 0.490 |
| 4 | character | 1 | 0.47 | 0.933 / 0.953 / 0.915 | 0.911 / 0.934 / 0.893 | 0.926 / 0.948 / 0.908 |
| 9 | rating | 1 | 0.39 | 0.830 / 0.792 / 0.871 | 0.837 / 0.811 / 0.864 | 0.837 / 0.813 / 0.864 |
Micro@Thr means the metrics on the category-level suggested thresholds, which are listed in the table above.Macro@0.40 means the metrics on the threshold 0.40.Macro@Best means the metrics on the tag-level thresholds on each tags, which should have the best F1 scores.pip install 'dghs-imgutils>=0.17.0' torch huggingface_hub timm pillow pandas1import json
2
3import pandas as pd
4import torch
5from huggingface_hub import hf_hub_download
6from imgutils.data import load_image
7from imgutils.preprocess import create_torchvision_transforms
8from timm import create_model
9
10repo_id = 'animetimm/caformer_b36.dbv4-full'
11model = create_model(f'hf-hub:{repo_id}', pretrained=True)
12model.eval()
13
14with open(hf_hub_download(repo_id=repo_id, repo_type='model', filename='preprocess.json'), 'r') as f:
15 preprocessor = create_torchvision_transforms(json.load(f)['test'])
16# Compose(
17# PadToSize(size=(512, 512), interpolation=bilinear, background_color=white)
18# Resize(size=384, interpolation=bicubic, max_size=None, antialias=True)
19# CenterCrop(size=[384, 384])
20# MaybeToTensor()
21# Normalize(mean=tensor([0.4850, 0.4560, 0.4060]), std=tensor([0.2290, 0.2240, 0.2250]))
22# )
23
24image = load_image('https://huggingface.co/animetimm/caformer_b36.dbv4-full/resolve/main/sample.webp')
25input_ = preprocessor(image).unsqueeze(0)
26# input_, shape: torch.Size([1, 3, 384, 384]), dtype: torch.float32
27with torch.no_grad():
28 output = model(input_)
29 prediction = torch.sigmoid(output)[0]
30# output, shape: torch.Size([1, 12476]), dtype: torch.float32
31# prediction, shape: torch.Size([12476]), dtype: torch.float32
32
33df_tags = pd.read_csv(
34 hf_hub_download(repo_id=repo_id, repo_type='model', filename='selected_tags.csv'),
35 keep_default_na=False
36)
37tags = df_tags['name']
38mask = prediction.numpy() >= df_tags['best_threshold']
39print(dict(zip(tags[mask].tolist(), prediction[mask].tolist())))
40# {'sensitive': 0.6932118535041809,
41# '1girl': 0.9990721940994263,
42# 'solo': 0.9785084128379822,
43# 'looking_at_viewer': 0.7411327958106995,
44# 'blush': 0.8228459358215332,
45# 'smile': 0.9370849132537842,
46# 'short_hair': 0.8239911198616028,
47# 'long_sleeves': 0.5299726724624634,
48# 'brown_hair': 0.6389132738113403,
49# 'holding': 0.6104577779769897,
50# 'dress': 0.6728140115737915,
51# 'closed_mouth': 0.33915525674819946,
52# 'sitting': 0.7986266016960144,
53# 'purple_eyes': 0.7082042694091797,
54# 'flower': 0.8504390120506287,
55# 'braid': 0.812047004699707,
56# 'blunt_bangs': 0.27516067028045654,
57# 'tears': 0.8593371510505676,
58# 'floral_print': 0.28373879194259644,
59# 'crying': 0.31545740365982056,
60# 'plant': 0.7968168258666992,
61# 'blue_flower': 0.47092026472091675,
62# 'tareme': 0.1419680416584015,
63# 'crying_with_eyes_open': 0.2293853610754013,
64# 'crown_braid': 0.6291146874427795,
65# 'potted_plant': 0.7235668897628784,
66# 'flower_pot': 0.7853846549987793,
67# 'happy_tears': 0.18256734311580658,
68# 'pavement': 0.3113744258880615,
69# 'wiping_tears': 0.7474808096885681,
70# 'morning_glory': 0.865814208984375}pip install 'dghs-imgutils>=0.17.0'multilabel_timm_predict function with the following code1from imgutils.generic import multilabel_timm_predict
2
3general, character, rating = multilabel_timm_predict(
4 'https://huggingface.co/animetimm/caformer_b36.dbv4-full/resolve/main/sample.webp',
5 repo_id='animetimm/caformer_b36.dbv4-full',
6 fmt=('general', 'character', 'rating'),
7)
8
9print(general)
10# {'1girl': 0.9990721940994263,
11# 'solo': 0.9785083532333374,
12# 'smile': 0.9370849132537842,
13# 'morning_glory': 0.8658077716827393,
14# 'tears': 0.8593354225158691,
15# 'flower': 0.8504382371902466,
16# 'short_hair': 0.8239905834197998,
17# 'blush': 0.8228461742401123,
18# 'braid': 0.8120447397232056,
19# 'sitting': 0.798625111579895,
20# 'plant': 0.7968136072158813,
21# 'flower_pot': 0.7853772640228271,
22# 'wiping_tears': 0.7474707365036011,
23# 'looking_at_viewer': 0.7411322593688965,
24# 'potted_plant': 0.7235615253448486,
25# 'purple_eyes': 0.7082012295722961,
26# 'dress': 0.6728127598762512,
27# 'brown_hair': 0.6389119029045105,
28# 'crown_braid': 0.6291083693504333,
29# 'holding': 0.6104577779769897,
30# 'long_sleeves': 0.5299732089042664,
31# 'blue_flower': 0.470914363861084,
32# 'closed_mouth': 0.33915433287620544,
33# 'crying': 0.31545311212539673,
34# 'pavement': 0.3113621473312378,
35# 'floral_print': 0.2837352156639099,
36# 'blunt_bangs': 0.2751583755016327,
37# 'crying_with_eyes_open': 0.22938179969787598,
38# 'happy_tears': 0.1825598180294037,
39# 'tareme': 0.1419658362865448}
40print(character)
41# {}
42print(rating)
43# {'sensitive': 0.6932107210159302}