GithubHelp home page GithubHelp logo

hanxunh / ldreg Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 0.0 74 KB

[ICLR2024] LDReg: Local Dimensionality Regularized Self-Supervised Learning

License: MIT License

Python 100.00%
deep-learning iclr iclr2024 neural-networks self-supervised-learning pytorch

ldreg's Introduction

LDReg: Local Dimensionality Regularized Self-Supervised Learning

Code for ICLR2024 paper "LDReg: Local Dimensionality Regularized Self-Supervised Learning"


LDReg

# Method of Moments estimation of LID
def lid_mom_est(data, reference, k, get_idx=False, 
                compute_mode='use_mm_for_euclid_dist_if_necessary'):
    b = data.shape[0]
    k = min(k, b-2)
    data = torch.flatten(data, start_dim=1)
    reference = torch.flatten(reference, start_dim=1)
    r = torch.cdist(data, reference, p=2, compute_mode=compute_mode)
    a, idx = torch.sort(r, dim=1)
    m = torch.mean(a[:, 1:k], dim=1)
    lids = m / (a[:, k] - m)
    if get_idx:
        return idx, lids
    return lids

# features: representations that need LID to be estimated. 
# reference: reference representations, usually, the same batch of representations can be used. 
# k: locality parameter, the neighbourhood size. 
# NOTE: features and reference should be in the same dimension.

lids = lid_mom_est(data=features, reference=reference.detach(), k=k)
reg_loss = - torch.log(lids)  # Eq (1) of the paper. 
        

Reproduce results from the paper

We provide configuration files in the configs folder. Details of all necessary hyperparameters are also in the Appendix of the paper.

Pretrained models are available here in this Google Drive folder.

An example of how to run pretraing is the following:

srun python3 main_simclr.py --ddp --dist_eval                  \
                            --exp_path path/to/exp/folder      \
                            --exp_config path/to/config/folder \
                            --exp_name pretrain     

An example of how to run linear probing:

srun python3 main_linear_prob.py --ddp --dist_eval                  \
                                 --exp_path path/to/exp/folder      \
                                 --exp_config path/to/config/folder \
                                 --exp_name linear_prob          

Citation

If you use this code in your work, please cite the accompanying paper:

@inproceedings{huang2024ldreg,
  title={LDReg: Local Dimensionality Regularized Self-Supervised Learning},
  author={Hanxun Huang and Ricardo J. G. B. Campello and Sarah Monazam Erfani and Xingjun Ma and Michael E. Houle and James Bailey},
  booktitle={ICLR},
  year={2024}
}

Part of the code is based on the following repo:

ldreg's People

Contributors

hanxunh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.