Library-Mutsumi/wd14_tagger_embedding_denormalize
0
Models of experiment: https://github.com/deepghs/taggerembeddingaligner
import numpy as np
from imgutils.tagging import get_wd14_tags, convert_wd14_emb_to_prediction, denormalize_wd14_emb
embedding, (r, g, c) = get_wd14_tags(
'/my/image.png',
fmt=('embedding', ('rating', 'general', 'character')),
)
# normal tag results
print('Expected result:')
print(r)
print(g)
print(c)
# normalize embedding
embedding = embedding / np.linalg.norm(embedding)
# bad tag results
br, bg, bc = convert_wd14_emb_to_prediction(embedding)
print('Bad results due to the embedding normalization:')
print(br)
print(bg)
print(bc)
# denormalize this embedding
output = denormalize_wd14_emb(embedding)
print(output.shape)
# should be similar to r, g, c, approx 1e-3 error
rating, general, character = convert_wd14_emb_to_prediction(output)
print('De-normalized result:')
print(rating)
print(general)
print(character)