Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev(narugo): embedding inverse #94

Merged
merged 12 commits into from
May 15, 2024
Merged

dev(narugo): embedding inverse #94

merged 12 commits into from
May 15, 2024

Conversation

narugo1992
Copy link
Contributor

@narugo1992 narugo1992 commented May 14, 2024

import numpy as np
from huggingface_hub import hf_hub_download

from imgutils.tagging.wd14 import inv_wd14_by_predictions

model_name = 'ConvNext'
scale: int = 2000

samples = np.load(hf_hub_download(
    repo_id='deepghs/wd14_tagger_inversion',
    repo_type='dataset',
    filename=f'{model_name}/samples_{scale}.npz',
))

predictions, embeddings = samples['preds'], samples['embs']

inv_embs = inv_wd14_by_predictions(predictions, model_name=model_name, norm=True)
print('Inversed embeddings:', inv_embs)
print(inv_embs.shape)

expected_embs = embeddings / np.linalg.norm(embeddings, axis=-1)[..., None]
print('Expected embeddings:', expected_embs)
print(expected_embs.shape)

sims = (inv_embs * expected_embs).sum(axis=-1)
print('Similarities:', sims)
sim = sims.mean()
print('Mean Similarity:', sim)  # 0.997

@narugo1992 narugo1992 added the enhancement New feature or request label May 14, 2024
@narugo1992 narugo1992 self-assigned this May 14, 2024
Copy link

codecov bot commented May 14, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 98.80%. Comparing base (803ee23) to head (d3dba8f).
Report is 2 commits behind head on main.

❗ Current head d3dba8f differs from pull request most recent head 195c8fa. Consider uploading reports for the commit 195c8fa to get more accurate results

Files Patch % Lines
imgutils/tagging/wd14.py 33.33% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #94      +/-   ##
==========================================
- Coverage   99.16%   98.80%   -0.36%     
==========================================
  Files          93       93              
  Lines        2752     2766      +14     
==========================================
+ Hits         2729     2733       +4     
- Misses         23       33      +10     
Flag Coverage Δ
unittests 98.80% <33.33%> (-0.36%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@narugo1992 narugo1992 merged commit 195c8fa into main May 15, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant