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.570 / 0.573 / 0.600 / 0.557 | 0.693 / 0.692 / 0.690 / 0.696 | --- |
| Test | 0.569 / 0.573 / 0.600 / 0.556 | 0.693 / 0.693 / 0.691 / 0.696 | 0.599 / 0.600 / 0.618 |
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.681 / 0.674 / 0.688 | 0.445 / 0.485 / 0.427 | 0.480 / 0.476 / 0.510 |
| 4 | character | 1 | 0.61 | 0.943 / 0.961 / 0.925 | 0.921 / 0.925 / 0.920 | 0.938 / 0.954 / 0.924 |
| 9 | rating | 1 | 0.38 | 0.832 / 0.801 / 0.865 | 0.838 / 0.817 / 0.860 | 0.839 / 0.819 / 0.861 |
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/eva02_large_patch14_448.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, 448), interpolation=bicubic, max_size=None, antialias=True)
19# CenterCrop(size=[448, 448])
20# MaybeToTensor()
21# Normalize(mean=tensor([0.4815, 0.4578, 0.4082]), std=tensor([0.2686, 0.2613, 0.2758]))
22# )
23
24image = load_image('https://huggingface.co/animetimm/eva02_large_patch14_448.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.9555495381355286,
41# '1girl': 0.9977720379829407,
42# 'solo': 0.9800751209259033,
43# 'looking_at_viewer': 0.7236320972442627,
44# 'blush': 0.7710952758789062,
45# 'smile': 0.8856169581413269,
46# 'short_hair': 0.803878128528595,
47# 'long_sleeves': 0.3804128170013428,
48# 'brown_hair': 0.6562796831130981,
49# 'dress': 0.5758444666862488,
50# 'sitting': 0.7712022066116333,
51# 'purple_eyes': 0.5440564751625061,
52# 'flower': 0.9287881851196289,
53# 'braid': 0.8394284844398499,
54# 'tears': 0.778815746307373,
55# 'floral_print': 0.43895024061203003,
56# 'plant': 0.6179906725883484,
57# 'blue_flower': 0.30160021781921387,
58# 'crown_braid': 0.40592360496520996,
59# 'potted_plant': 0.5879666209220886,
60# 'flower_pot': 0.49822214245796204,
61# 'wiping_tears': 0.4761575758457184}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/eva02_large_patch14_448.dbv4-full/resolve/main/sample.webp',
5 repo_id='animetimm/eva02_large_patch14_448.dbv4-full',
6 fmt=('general', 'character', 'rating'),
7)
8
9print(general)
10# {'1girl': 0.9977719783782959,
11# 'solo': 0.9800750613212585,
12# 'flower': 0.9287877082824707,
13# 'smile': 0.8856177926063538,
14# 'braid': 0.8394323587417603,
15# 'short_hair': 0.8038788437843323,
16# 'tears': 0.7787976264953613,
17# 'sitting': 0.7712044715881348,
18# 'blush': 0.7710968255996704,
19# 'looking_at_viewer': 0.7236329317092896,
20# 'brown_hair': 0.6562790870666504,
21# 'plant': 0.6180056929588318,
22# 'potted_plant': 0.5879812836647034,
23# 'dress': 0.5758441686630249,
24# 'purple_eyes': 0.5440553426742554,
25# 'flower_pot': 0.4982312321662903,
26# 'wiping_tears': 0.47614389657974243,
27# 'floral_print': 0.43895548582077026,
28# 'crown_braid': 0.40593117475509644,
29# 'long_sleeves': 0.3804135322570801,
30# 'blue_flower': 0.3015919327735901}
31print(character)
32# {}
33print(rating)
34# {'sensitive': 0.9555498361587524}