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.457 / 0.473 / 0.586 / 0.407 | 0.641 / 0.642 / 0.693 / 0.596 | --- |
| Test | 0.458 / 0.473 / 0.586 / 0.408 | 0.641 / 0.642 / 0.694 / 0.596 | 0.511 / 0.537 / 0.513 |
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.33 | 0.631 / 0.639 / 0.624 | 0.323 / 0.475 / 0.272 | 0.388 / 0.404 / 0.405 |
| 4 | character | 1 | 0.42 | 0.873 / 0.921 / 0.829 | 0.840 / 0.901 / 0.793 | 0.860 / 0.913 / 0.819 |
| 9 | rating | 1 | 0.38 | 0.807 / 0.759 / 0.862 | 0.813 / 0.788 / 0.841 | 0.814 / 0.783 / 0.851 |
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/mobilenetv4_conv_aa_large.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=448, interpolation=bicubic, max_size=None, antialias=True)
19# CenterCrop(size=[448, 448])
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/mobilenetv4_conv_aa_large.dbv4-full/resolve/main/sample.webp')
25input_ = preprocessor(image).unsqueeze(0)
26# input_, shape: torch.Size([1, 3, 448, 448]), 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.6181432604789734,
41# '1girl': 0.9969968795776367,
42# 'solo': 0.9696205258369446,
43# 'looking_at_viewer': 0.8432332873344421,
44# 'blush': 0.7917149662971497,
45# 'smile': 0.9405843615531921,
46# 'short_hair': 0.6273495554924011,
47# 'shirt': 0.5353975892066956,
48# 'long_sleeves': 0.7138653993606567,
49# 'brown_hair': 0.8164870738983154,
50# 'holding': 0.6878705024719238,
51# 'dress': 0.6111152172088623,
52# 'closed_mouth': 0.5007601976394653,
53# 'white_shirt': 0.34434816241264343,
54# 'purple_eyes': 0.7064062356948853,
55# 'flower': 0.9301103949546814,
56# 'braid': 0.869755208492279,
57# 'sidelocks': 0.23272593319416046,
58# 'outdoors': 0.4784768223762512,
59# 'hand_up': 0.17624469101428986,
60# 'blunt_bangs': 0.3426509499549866,
61# 'head_tilt': 0.11214721202850342,
62# 'sunlight': 0.15041665732860565,
63# 'plant': 0.22287964820861816,
64# 'light_smile': 0.08559338748455048,
65# 'blue_flower': 0.8238141536712646,
66# 'backlighting': 0.17485418915748596,
67# 'crown_braid': 0.6755908131599426}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/mobilenetv4_conv_aa_large.dbv4-full/resolve/main/sample.webp',
5 repo_id='animetimm/mobilenetv4_conv_aa_large.dbv4-full',
6 fmt=('general', 'character', 'rating'),
7)
8
9print(general)
10# {'1girl': 0.9969969987869263,
11# 'solo': 0.969620406627655,
12# 'smile': 0.940584659576416,
13# 'flower': 0.9301101565361023,
14# 'braid': 0.8697538375854492,
15# 'looking_at_viewer': 0.8432332277297974,
16# 'blue_flower': 0.8238140344619751,
17# 'brown_hair': 0.816490650177002,
18# 'blush': 0.7917153835296631,
19# 'long_sleeves': 0.7138651609420776,
20# 'purple_eyes': 0.7064056396484375,
21# 'holding': 0.6878722906112671,
22# 'crown_braid': 0.6755940318107605,
23# 'short_hair': 0.6273516416549683,
24# 'dress': 0.6111209392547607,
25# 'shirt': 0.5354008078575134,
26# 'closed_mouth': 0.5007631182670593,
27# 'outdoors': 0.47849011421203613,
28# 'white_shirt': 0.34435153007507324,
29# 'blunt_bangs': 0.34265023469924927,
30# 'sidelocks': 0.2327292263507843,
31# 'plant': 0.22287851572036743,
32# 'hand_up': 0.17624491453170776,
33# 'backlighting': 0.17485374212265015,
34# 'sunlight': 0.15041813254356384,
35# 'head_tilt': 0.11214578151702881,
36# 'light_smile': 0.08559340238571167}
37print(character)
38# {}
39print(rating)
40# {'sensitive': 0.6181411743164062}