Full Code of facebookresearch/dinov2 for AI

main 7b187bd4df8e cached
201 files
2.1 MB
557.7k tokens
1094 symbols
1 requests
Download .txt
Showing preview only (2,225K chars total). Download the full file or copy to clipboard to get everything.
Repository: facebookresearch/dinov2
Branch: main
Commit: 7b187bd4df8e
Files: 201
Total size: 2.1 MB

Directory structure:
gitextract_rhfo6abb/

├── .github/
│   └── workflows/
│       └── lint.yaml
├── .gitignore
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── LICENSE_CELL_DINO_CODE
├── LICENSE_CELL_DINO_MODELS
├── LICENSE_XRAY_DINO_MODEL
├── MODEL_CARD.md
├── README.md
├── conda-extras.yaml
├── conda.yaml
├── dinov2/
│   ├── __init__.py
│   ├── configs/
│   │   ├── __init__.py
│   │   ├── eval/
│   │   │   ├── cell_dino/
│   │   │   │   ├── vitl16_channel_adaptive_pretrain.yaml
│   │   │   │   └── vitl16_pretrain.yaml
│   │   │   ├── vitb14_pretrain.yaml
│   │   │   ├── vitb14_reg4_pretrain.yaml
│   │   │   ├── vitg14_pretrain.yaml
│   │   │   ├── vitg14_reg4_pretrain.yaml
│   │   │   ├── vitl14_pretrain.yaml
│   │   │   ├── vitl14_reg4_pretrain.yaml
│   │   │   ├── vits14_pretrain.yaml
│   │   │   └── vits14_reg4_pretrain.yaml
│   │   ├── ssl_default_config.yaml
│   │   └── train/
│   │       ├── cell_dino/
│   │       │   ├── vitl16_boc_hpafov.yaml
│   │       │   ├── vitl16_hpafov.yaml
│   │       │   └── vitl16_hpaone.yaml
│   │       ├── vitg14.yaml
│   │       ├── vitl14.yaml
│   │       └── vitl16_short.yaml
│   ├── data/
│   │   ├── __init__.py
│   │   ├── accumulators.py
│   │   ├── adapters.py
│   │   ├── augmentations.py
│   │   ├── cell_dino/
│   │   │   ├── augmentations.py
│   │   │   └── transforms.py
│   │   ├── collate.py
│   │   ├── datasets/
│   │   │   ├── __init__.py
│   │   │   ├── cell_dino/
│   │   │   │   ├── chammi_cp.py
│   │   │   │   ├── chammi_hpa.py
│   │   │   │   ├── chammi_wtc.py
│   │   │   │   ├── hpafov.py
│   │   │   │   └── hpaone.py
│   │   │   ├── decoders.py
│   │   │   ├── extended.py
│   │   │   ├── image_net.py
│   │   │   └── image_net_22k.py
│   │   ├── loaders.py
│   │   ├── masking.py
│   │   ├── samplers.py
│   │   └── transforms.py
│   ├── distributed/
│   │   └── __init__.py
│   ├── eval/
│   │   ├── __init__.py
│   │   ├── cell_dino/
│   │   │   ├── knn.py
│   │   │   ├── linear.py
│   │   │   └── utils.py
│   │   ├── depth/
│   │   │   ├── __init__.py
│   │   │   ├── models/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── backbones/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   └── vision_transformer.py
│   │   │   │   ├── builder.py
│   │   │   │   ├── decode_heads/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── decode_head.py
│   │   │   │   │   ├── dpt_head.py
│   │   │   │   │   └── linear_head.py
│   │   │   │   ├── depther/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── base.py
│   │   │   │   │   └── encoder_decoder.py
│   │   │   │   └── losses/
│   │   │   │       ├── __init__.py
│   │   │   │       ├── gradientloss.py
│   │   │   │       └── sigloss.py
│   │   │   └── ops/
│   │   │       ├── __init__.py
│   │   │       └── wrappers.py
│   │   ├── knn.py
│   │   ├── linear.py
│   │   ├── log_regression.py
│   │   ├── metrics.py
│   │   ├── segmentation/
│   │   │   ├── __init__.py
│   │   │   ├── hooks/
│   │   │   │   ├── __init__.py
│   │   │   │   └── optimizer.py
│   │   │   ├── models/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── backbones/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   └── vision_transformer.py
│   │   │   │   └── decode_heads/
│   │   │   │       ├── __init__.py
│   │   │   │       └── linear_head.py
│   │   │   └── utils/
│   │   │       ├── __init__.py
│   │   │       └── colormaps.py
│   │   ├── segmentation_m2f/
│   │   │   ├── __init__.py
│   │   │   ├── core/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── anchor/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── builder.py
│   │   │   │   │   └── point_generator.py
│   │   │   │   ├── box/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── builder.py
│   │   │   │   │   └── samplers/
│   │   │   │   │       ├── __init__.py
│   │   │   │   │       ├── base_sampler.py
│   │   │   │   │       ├── mask_pseudo_sampler.py
│   │   │   │   │       ├── mask_sampling_result.py
│   │   │   │   │       └── sampling_result.py
│   │   │   │   └── utils/
│   │   │   │       ├── __init__.py
│   │   │   │       ├── dist_utils.py
│   │   │   │       └── misc.py
│   │   │   ├── models/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── backbones/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── adapter_modules.py
│   │   │   │   │   ├── drop_path.py
│   │   │   │   │   ├── vit.py
│   │   │   │   │   └── vit_adapter.py
│   │   │   │   ├── builder.py
│   │   │   │   ├── decode_heads/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   └── mask2former_head.py
│   │   │   │   ├── losses/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── cross_entropy_loss.py
│   │   │   │   │   ├── dice_loss.py
│   │   │   │   │   └── match_costs.py
│   │   │   │   ├── plugins/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   └── msdeformattn_pixel_decoder.py
│   │   │   │   ├── segmentors/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   └── encoder_decoder_mask2former.py
│   │   │   │   └── utils/
│   │   │   │       ├── __init__.py
│   │   │   │       ├── assigner.py
│   │   │   │       ├── point_sample.py
│   │   │   │       ├── positional_encoding.py
│   │   │   │       └── transformer.py
│   │   │   └── ops/
│   │   │       └── modules/
│   │   │           ├── __init__.py
│   │   │           └── ms_deform_attn.py
│   │   ├── setup.py
│   │   └── utils.py
│   ├── fsdp/
│   │   └── __init__.py
│   ├── hub/
│   │   ├── __init__.py
│   │   ├── backbones.py
│   │   ├── cell_dino/
│   │   │   └── backbones.py
│   │   ├── classifiers.py
│   │   ├── depth/
│   │   │   ├── __init__.py
│   │   │   ├── decode_heads.py
│   │   │   ├── encoder_decoder.py
│   │   │   └── ops.py
│   │   ├── depthers.py
│   │   ├── dinotxt.py
│   │   ├── text/
│   │   │   ├── dinotxt_model.py
│   │   │   ├── dinov2_wrapper.py
│   │   │   ├── text_tower.py
│   │   │   ├── text_transformer.py
│   │   │   ├── tokenizer.py
│   │   │   └── vision_tower.py
│   │   ├── utils.py
│   │   └── xray_dino/
│   │       └── backbones.py
│   ├── layers/
│   │   ├── __init__.py
│   │   ├── attention.py
│   │   ├── block.py
│   │   ├── dino_head.py
│   │   ├── drop_path.py
│   │   ├── layer_scale.py
│   │   ├── mlp.py
│   │   ├── patch_embed.py
│   │   └── swiglu_ffn.py
│   ├── logging/
│   │   ├── __init__.py
│   │   └── helpers.py
│   ├── loss/
│   │   ├── __init__.py
│   │   ├── dino_clstoken_loss.py
│   │   ├── ibot_patch_loss.py
│   │   └── koleo_loss.py
│   ├── models/
│   │   ├── __init__.py
│   │   └── vision_transformer.py
│   ├── run/
│   │   ├── __init__.py
│   │   ├── eval/
│   │   │   ├── cell_dino/
│   │   │   │   ├── knn.py
│   │   │   │   └── linear.py
│   │   │   ├── knn.py
│   │   │   ├── linear.py
│   │   │   └── log_regression.py
│   │   ├── submit.py
│   │   └── train/
│   │       └── train.py
│   ├── thirdparty/
│   │   └── CLIP/
│   │       ├── LICENSE
│   │       └── clip/
│   │           └── simple_tokenizer.py
│   ├── train/
│   │   ├── __init__.py
│   │   ├── ssl_meta_arch.py
│   │   └── train.py
│   └── utils/
│       ├── __init__.py
│       ├── checkpoint.py
│       ├── cluster.py
│       ├── config.py
│       ├── dtype.py
│       ├── param_groups.py
│       └── utils.py
├── docs/
│   ├── README_CELL_DINO.md
│   └── README_CHANNEL_ADAPTIVE_DINO.md
├── hubconf.py
├── notebooks/
│   ├── cell_dino/
│   │   └── inference.ipynb
│   ├── depth_estimation.ipynb
│   ├── dinotxt.ipynb
│   └── semantic_segmentation.ipynb
├── pyproject.toml
├── requirements-dev.txt
├── requirements-extras.txt
├── requirements.txt
├── scripts/
│   ├── cell_dino/
│   │   ├── launcher_knn_eval_on_chammi.sh
│   │   └── launcher_linear_eval_on_chammi.sh
│   └── lint.sh
├── setup.cfg
└── setup.py

================================================
FILE CONTENTS
================================================

================================================
FILE: .github/workflows/lint.yaml
================================================
name: Lint

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: 3.9
          cache: 'pip'
          cache-dependency-path: '**/requirements*.txt'
      - name: Install Python (development) dependencies
        run: |
          pip install -r requirements-dev.txt
      - name: Run flake8
        run: |
          flake8
      - name: Run black
        if: always()
        run: |
          black --check dinov2
      - name: Run pylint
        if: always()
        run: |
          pylint --exit-zero dinov2


================================================
FILE: .gitignore
================================================
build/
dist/
*.egg-info/
**/__pycache__/

**/.ipynb_checkpoints
**/.ipynb_checkpoints/**

*.swp

.vscode/


================================================
FILE: CODE_OF_CONDUCT.md
================================================
# Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies within all project spaces, and it also applies when
an individual is representing the project or its community in public spaces.
Examples of representing a project or community include using an official
project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.

This Code of Conduct also applies outside the project spaces when there is a
reasonable belief that an individual's behavior may have a negative impact on
the project or its community.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at <opensource-conduct@meta.com>. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq


================================================
FILE: CONTRIBUTING.md
================================================
# Contributing to DINOv2
We want to make contributing to this project as easy and transparent as
possible.

## Pull Requests
We actively welcome your pull requests.

1. Fork the repo and create your branch from `main`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. If you haven't already, complete the Contributor License Agreement ("CLA").

## Contributor License Agreement ("CLA")
In order to accept your pull request, we need you to submit a CLA. You only need
to do this once to work on any of Meta's open source projects.

Complete your CLA here: <https://code.facebook.com/cla>

## Issues
We use GitHub issues to track public bugs. Please ensure your description is
clear and has sufficient instructions to be able to reproduce the issue.

Meta has a [bounty program](https://www.facebook.com/whitehat/) for the safe
disclosure of security bugs. In those cases, please go through the process
outlined on that page and do not file a public issue.

## License
By contributing to DINOv2, you agree that your contributions will be licensed
under the LICENSE file in the root directory of this source tree.


================================================
FILE: LICENSE
================================================


                                 Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction,
      and distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by
      the copyright owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all
      other entities that control, are controlled by, or are under common
      control with that entity. For the purposes of this definition,
      "control" means (i) the power, direct or indirect, to cause the
      direction or management of such entity, whether by contract or
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity
      exercising permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.

      "Object" form shall mean any form resulting from mechanical
      transformation or translation of a Source form, including but
      not limited to compiled object code, generated documentation,
      and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or
      Object form, made available under the License, as indicated by a
      copyright notice that is included in or attached to the work
      (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object
      form, that is based on (or derived from) the Work and for which the
      editorial revisions, annotations, elaborations, or other modifications
      represent, as a whole, an original work of authorship. For the purposes
      of this License, Derivative Works shall not include works that remain
      separable from, or merely link (or bind by name) to the interfaces of,
      the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including
      the original version of the Work and any modifications or additions
      to that Work or Derivative Works thereof, that is intentionally
      submitted to Licensor for inclusion in the Work by the copyright owner
      or by an individual or Legal Entity authorized to submit on behalf of
      the copyright owner. For the purposes of this definition, "submitted"
      means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems,
      and issue tracking systems that are managed by, or on behalf of, the
      Licensor for the purpose of discussing and improving the Work, but
      excluding communication that is conspicuously marked or otherwise
      designated in writing by the copyright owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity
      on behalf of whom a Contribution has been received by Licensor and
      subsequently incorporated within the Work.

   2. Grant of Copyright License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the
      Work and such Derivative Works in Source or Object form.

   3. Grant of Patent License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      (except as stated in this section) patent license to make, have made,
      use, offer to sell, sell, import, and otherwise transfer the Work,
      where such license applies only to those patent claims licensable
      by such Contributor that are necessarily infringed by their
      Contribution(s) alone or by combination of their Contribution(s)
      with the Work to which such Contribution(s) was submitted. If You
      institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work
      or a Contribution incorporated within the Work constitutes direct
      or contributory patent infringement, then any patent licenses
      granted to You under this License for that Work shall terminate
      as of the date such litigation is filed.

   4. Redistribution. You may reproduce and distribute copies of the
      Work or Derivative Works thereof in any medium, with or without
      modifications, and in Source or Object form, provided that You
      meet the following conditions:

      (a) You must give any other recipients of the Work or
          Derivative Works a copy of this License; and

      (b) You must cause any modified files to carry prominent notices
          stating that You changed the files; and

      (c) You must retain, in the Source form of any Derivative Works
          that You distribute, all copyright, patent, trademark, and
          attribution notices from the Source form of the Work,
          excluding those notices that do not pertain to any part of
          the Derivative Works; and

      (d) If the Work includes a "NOTICE" text file as part of its
          distribution, then any Derivative Works that You distribute must
          include a readable copy of the attribution notices contained
          within such NOTICE file, excluding those notices that do not
          pertain to any part of the Derivative Works, in at least one
          of the following places: within a NOTICE text file distributed
          as part of the Derivative Works; within the Source form or
          documentation, if provided along with the Derivative Works; or,
          within a display generated by the Derivative Works, if and
          wherever such third-party notices normally appear. The contents
          of the NOTICE file are for informational purposes only and
          do not modify the License. You may add Your own attribution
          notices within Derivative Works that You distribute, alongside
          or as an addendum to the NOTICE text from the Work, provided
          that such additional attribution notices cannot be construed
          as modifying the License.

      You may add Your own copyright statement to Your modifications and
      may provide additional or different license terms and conditions
      for use, reproduction, or distribution of Your modifications, or
      for any such Derivative Works as a whole, provided Your use,
      reproduction, and distribution of the Work otherwise complies with
      the conditions stated in this License.

   5. Submission of Contributions. Unless You explicitly state otherwise,
      any Contribution intentionally submitted for inclusion in the Work
      by You to the Licensor shall be under the terms and conditions of
      this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify
      the terms of any separate license agreement you may have executed
      with Licensor regarding such Contributions.

   6. Trademarks. This License does not grant permission to use the trade
      names, trademarks, service marks, or product names of the Licensor,
      except as required for reasonable and customary use in describing the
      origin of the Work and reproducing the content of the NOTICE file.

   7. Disclaimer of Warranty. Unless required by applicable law or
      agreed to in writing, Licensor provides the Work (and each
      Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
      implied, including, without limitation, any warranties or conditions
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
      PARTICULAR PURPOSE. You are solely responsible for determining the
      appropriateness of using or redistributing the Work and assume any
      risks associated with Your exercise of permissions under this License.

   8. Limitation of Liability. In no event and under no legal theory,
      whether in tort (including negligence), contract, or otherwise,
      unless required by applicable law (such as deliberate and grossly
      negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special,
      incidental, or consequential damages of any character arising as a
      result of this License or out of the use or inability to use the
      Work (including but not limited to damages for loss of goodwill,
      work stoppage, computer failure or malfunction, or any and all
      other commercial damages or losses), even if such Contributor
      has been advised of the possibility of such damages.

   9. Accepting Warranty or Additional Liability. While redistributing
      the Work or Derivative Works thereof, You may choose to offer,
      and charge a fee for, acceptance of support, warranty, indemnity,
      or other liability obligations and/or rights consistent with this
      License. However, in accepting such obligations, You may act only
      on Your own behalf and on Your sole responsibility, not on behalf
      of any other Contributor, and only if You agree to indemnify,
      defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason
      of your accepting any such warranty or additional liability.

   END OF TERMS AND CONDITIONS

   APPENDIX: How to apply the Apache License to your work.

      To apply the Apache License to your work, attach the following
      boilerplate notice, with the fields enclosed by brackets "[]"
      replaced with your own identifying information. (Don't include
      the brackets!)  The text should be enclosed in the appropriate
      comment syntax for the file format. We also recommend that a
      file or class name and description of purpose be included on the
      same "printed page" as the copyright notice for easier
      identification within third-party archives.

   Copyright [yyyy] [name of copyright owner]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.


================================================
FILE: LICENSE_CELL_DINO_CODE
================================================
Attribution 4.0 International

=======================================================================

Creative Commons Corporation ("Creative Commons") is not a law firm and
does not provide legal services or legal advice. Distribution of
Creative Commons public licenses does not create a lawyer-client or
other relationship. Creative Commons makes its licenses and related
information available on an "as-is" basis. Creative Commons gives no
warranties regarding its licenses, any material licensed under their
terms and conditions, or any related information. Creative Commons
disclaims all liability for damages resulting from their use to the
fullest extent possible.

Using Creative Commons Public Licenses

Creative Commons public licenses provide a standard set of terms and
conditions that creators and other rights holders may use to share
original works of authorship and other material subject to copyright
and certain other rights specified in the public license below. The
following considerations are for informational purposes only, are not
exhaustive, and do not form part of our licenses.

     Considerations for licensors: Our public licenses are
     intended for use by those authorized to give the public
     permission to use material in ways otherwise restricted by
     copyright and certain other rights. Our licenses are
     irrevocable. Licensors should read and understand the terms
     and conditions of the license they choose before applying it.
     Licensors should also secure all rights necessary before
     applying our licenses so that the public can reuse the
     material as expected. Licensors should clearly mark any
     material not subject to the license. This includes other CC-
     licensed material, or material used under an exception or
     limitation to copyright. More considerations for licensors:
    wiki.creativecommons.org/Considerations_for_licensors

     Considerations for the public: By using one of our public
     licenses, a licensor grants the public permission to use the
     licensed material under specified terms and conditions. If
     the licensor's permission is not necessary for any reason--for
     example, because of any applicable exception or limitation to
     copyright--then that use is not regulated by the license. Our
     licenses grant only permissions under copyright and certain
     other rights that a licensor has authority to grant. Use of
     the licensed material may still be restricted for other
     reasons, including because others have copyright or other
     rights in the material. A licensor may make special requests,
     such as asking that all changes be marked or described.
     Although not required by our licenses, you are encouraged to
     respect those requests where reasonable. More considerations
     for the public:
    wiki.creativecommons.org/Considerations_for_licensees

=======================================================================

Creative Commons Attribution 4.0 International Public License

By exercising the Licensed Rights (defined below), You accept and agree
to be bound by the terms and conditions of this Creative Commons
Attribution 4.0 International Public License ("Public License"). To the
extent this Public License may be interpreted as a contract, You are
granted the Licensed Rights in consideration of Your acceptance of
these terms and conditions, and the Licensor grants You such rights in
consideration of benefits the Licensor receives from making the
Licensed Material available under these terms and conditions.


Section 1 -- Definitions.

  a. Adapted Material means material subject to Copyright and Similar
     Rights that is derived from or based upon the Licensed Material
     and in which the Licensed Material is translated, altered,
     arranged, transformed, or otherwise modified in a manner requiring
     permission under the Copyright and Similar Rights held by the
     Licensor. For purposes of this Public License, where the Licensed
     Material is a musical work, performance, or sound recording,
     Adapted Material is always produced where the Licensed Material is
     synched in timed relation with a moving image.

  b. Adapter's License means the license You apply to Your Copyright
     and Similar Rights in Your contributions to Adapted Material in
     accordance with the terms and conditions of this Public License.

  c. Copyright and Similar Rights means copyright and/or similar rights
     closely related to copyright including, without limitation,
     performance, broadcast, sound recording, and Sui Generis Database
     Rights, without regard to how the rights are labeled or
     categorized. For purposes of this Public License, the rights
     specified in Section 2(b)(1)-(2) are not Copyright and Similar
     Rights.

  d. Effective Technological Measures means those measures that, in the
     absence of proper authority, may not be circumvented under laws
     fulfilling obligations under Article 11 of the WIPO Copyright
     Treaty adopted on December 20, 1996, and/or similar international
     agreements.

  e. Exceptions and Limitations means fair use, fair dealing, and/or
     any other exception or limitation to Copyright and Similar Rights
     that applies to Your use of the Licensed Material.

  f. Licensed Material means the artistic or literary work, database,
     or other material to which the Licensor applied this Public
     License.

  g. Licensed Rights means the rights granted to You subject to the
     terms and conditions of this Public License, which are limited to
     all Copyright and Similar Rights that apply to Your use of the
     Licensed Material and that the Licensor has authority to license.

  h. Licensor means the individual(s) or entity(ies) granting rights
     under this Public License.

  i. Share means to provide material to the public by any means or
     process that requires permission under the Licensed Rights, such
     as reproduction, public display, public performance, distribution,
     dissemination, communication, or importation, and to make material
     available to the public including in ways that members of the
     public may access the material from a place and at a time
     individually chosen by them.

  j. Sui Generis Database Rights means rights other than copyright
     resulting from Directive 96/9/EC of the European Parliament and of
     the Council of 11 March 1996 on the legal protection of databases,
     as amended and/or succeeded, as well as other essentially
     equivalent rights anywhere in the world.

  k. You means the individual or entity exercising the Licensed Rights
     under this Public License. Your has a corresponding meaning.


Section 2 -- Scope.

  a. License grant.

       1. Subject to the terms and conditions of this Public License,
          the Licensor hereby grants You a worldwide, royalty-free,
          non-sublicensable, non-exclusive, irrevocable license to
          exercise the Licensed Rights in the Licensed Material to:

            a. reproduce and Share the Licensed Material, in whole or
               in part; and

            b. produce, reproduce, and Share Adapted Material.

       2. Exceptions and Limitations. For the avoidance of doubt, where
          Exceptions and Limitations apply to Your use, this Public
          License does not apply, and You do not need to comply with
          its terms and conditions.

       3. Term. The term of this Public License is specified in Section
          6(a).

       4. Media and formats; technical modifications allowed. The
          Licensor authorizes You to exercise the Licensed Rights in
          all media and formats whether now known or hereafter created,
          and to make technical modifications necessary to do so. The
          Licensor waives and/or agrees not to assert any right or
          authority to forbid You from making technical modifications
          necessary to exercise the Licensed Rights, including
          technical modifications necessary to circumvent Effective
          Technological Measures. For purposes of this Public License,
          simply making modifications authorized by this Section 2(a)
          (4) never produces Adapted Material.

       5. Downstream recipients.

            a. Offer from the Licensor -- Licensed Material. Every
               recipient of the Licensed Material automatically
               receives an offer from the Licensor to exercise the
               Licensed Rights under the terms and conditions of this
               Public License.

            b. No downstream restrictions. You may not offer or impose
               any additional or different terms or conditions on, or
               apply any Effective Technological Measures to, the
               Licensed Material if doing so restricts exercise of the
               Licensed Rights by any recipient of the Licensed
               Material.

       6. No endorsement. Nothing in this Public License constitutes or
          may be construed as permission to assert or imply that You
          are, or that Your use of the Licensed Material is, connected
          with, or sponsored, endorsed, or granted official status by,
          the Licensor or others designated to receive attribution as
          provided in Section 3(a)(1)(A)(i).

  b. Other rights.

       1. Moral rights, such as the right of integrity, are not
          licensed under this Public License, nor are publicity,
          privacy, and/or other similar personality rights; however, to
          the extent possible, the Licensor waives and/or agrees not to
          assert any such rights held by the Licensor to the limited
          extent necessary to allow You to exercise the Licensed
          Rights, but not otherwise.

       2. Patent and trademark rights are not licensed under this
          Public License.

       3. To the extent possible, the Licensor waives any right to
          collect royalties from You for the exercise of the Licensed
          Rights, whether directly or through a collecting society
          under any voluntary or waivable statutory or compulsory
          licensing scheme. In all other cases the Licensor expressly
          reserves any right to collect such royalties.


Section 3 -- License Conditions.

Your exercise of the Licensed Rights is expressly made subject to the
following conditions.

  a. Attribution.

       1. If You Share the Licensed Material (including in modified
          form), You must:

            a. retain the following if it is supplied by the Licensor
               with the Licensed Material:

                 i. identification of the creator(s) of the Licensed
                    Material and any others designated to receive
                    attribution, in any reasonable manner requested by
                    the Licensor (including by pseudonym if
                    designated);

                ii. a copyright notice;

               iii. a notice that refers to this Public License;

                iv. a notice that refers to the disclaimer of
                    warranties;

                 v. a URI or hyperlink to the Licensed Material to the
                    extent reasonably practicable;

            b. indicate if You modified the Licensed Material and
               retain an indication of any previous modifications; and

            c. indicate the Licensed Material is licensed under this
               Public License, and include the text of, or the URI or
               hyperlink to, this Public License.

       2. You may satisfy the conditions in Section 3(a)(1) in any
          reasonable manner based on the medium, means, and context in
          which You Share the Licensed Material. For example, it may be
          reasonable to satisfy the conditions by providing a URI or
          hyperlink to a resource that includes the required
          information.

       3. If requested by the Licensor, You must remove any of the
          information required by Section 3(a)(1)(A) to the extent
          reasonably practicable.

       4. If You Share Adapted Material You produce, the Adapter's
          License You apply must not prevent recipients of the Adapted
          Material from complying with this Public License.


Section 4 -- Sui Generis Database Rights.

Where the Licensed Rights include Sui Generis Database Rights that
apply to Your use of the Licensed Material:

  a. for the avoidance of doubt, Section 2(a)(1) grants You the right
     to extract, reuse, reproduce, and Share all or a substantial
     portion of the contents of the database;

  b. if You include all or a substantial portion of the database
     contents in a database in which You have Sui Generis Database
     Rights, then the database in which You have Sui Generis Database
     Rights (but not its individual contents) is Adapted Material; and

  c. You must comply with the conditions in Section 3(a) if You Share
     all or a substantial portion of the contents of the database.

For the avoidance of doubt, this Section 4 supplements and does not
replace Your obligations under this Public License where the Licensed
Rights include other Copyright and Similar Rights.


Section 5 -- Disclaimer of Warranties and Limitation of Liability.

  a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
     EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
     AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
     ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
     IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
     WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
     PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
     ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
     KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
     ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.

  b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
     TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
     NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
     INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
     COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
     USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
     ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
     DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
     IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.

  c. The disclaimer of warranties and limitation of liability provided
     above shall be interpreted in a manner that, to the extent
     possible, most closely approximates an absolute disclaimer and
     waiver of all liability.


Section 6 -- Term and Termination.

  a. This Public License applies for the term of the Copyright and
     Similar Rights licensed here. However, if You fail to comply with
     this Public License, then Your rights under this Public License
     terminate automatically.

  b. Where Your right to use the Licensed Material has terminated under
     Section 6(a), it reinstates:

       1. automatically as of the date the violation is cured, provided
          it is cured within 30 days of Your discovery of the
          violation; or

       2. upon express reinstatement by the Licensor.

     For the avoidance of doubt, this Section 6(b) does not affect any
     right the Licensor may have to seek remedies for Your violations
     of this Public License.

  c. For the avoidance of doubt, the Licensor may also offer the
     Licensed Material under separate terms or conditions or stop
     distributing the Licensed Material at any time; however, doing so
     will not terminate this Public License.

  d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
     License.


Section 7 -- Other Terms and Conditions.

  a. The Licensor shall not be bound by any additional or different
     terms or conditions communicated by You unless expressly agreed.

  b. Any arrangements, understandings, or agreements regarding the
     Licensed Material not stated herein are separate from and
     independent of the terms and conditions of this Public License.


Section 8 -- Interpretation.

  a. For the avoidance of doubt, this Public License does not, and
     shall not be interpreted to, reduce, limit, restrict, or impose
     conditions on any use of the Licensed Material that could lawfully
     be made without permission under this Public License.

  b. To the extent possible, if any provision of this Public License is
     deemed unenforceable, it shall be automatically reformed to the
     minimum extent necessary to make it enforceable. If the provision
     cannot be reformed, it shall be severed from this Public License
     without affecting the enforceability of the remaining terms and
     conditions.

  c. No term or condition of this Public License will be waived and no
     failure to comply consented to unless expressly agreed to by the
     Licensor.

  d. Nothing in this Public License constitutes or may be interpreted
     as a limitation upon, or waiver of, any privileges and immunities
     that apply to the Licensor or You, including from the legal
     processes of any jurisdiction or authority.


=======================================================================

Creative Commons is not a party to its public
licenses. Notwithstanding, Creative Commons may elect to apply one of
its public licenses to material it publishes and in those instances
will be considered the “Licensor.” The text of the Creative Commons
public licenses is dedicated to the public domain under the CC0 Public
Domain Dedication. Except for the limited purpose of indicating that
material is shared under a Creative Commons public license or as
otherwise permitted by the Creative Commons policies published at
creativecommons.org/policies, Creative Commons does not authorize the
use of the trademark "Creative Commons" or any other trademark or logo
of Creative Commons without its prior written consent including,
without limitation, in connection with any unauthorized modifications
to any of its public licenses or any other arrangements,
understandings, or agreements concerning use of licensed material. For
the avoidance of doubt, this paragraph does not form part of the
public licenses.

Creative Commons may be contacted at creativecommons.org.

================================================
FILE: LICENSE_CELL_DINO_MODELS
================================================
FAIR Noncommercial Research License
v1 Last Updated: August 18, 2025

“Acceptable Use Policy” means the FAIR Acceptable Use Policy, applicable to Research Materials, that is incorporated into this Agreement.

“Agreement” means the terms and conditions for use, reproduction, distribution and modification of the Research Materials set forth herein.


“Documentation” means the specifications, manuals and documentation accompanying 
Research Materials distributed by Meta.


“Licensee” or “you” means you, or your employer or any other person or entity (if you are entering into this Agreement on such person or entity’s behalf), of the age required under applicable laws, rules or regulations to provide legal consent and that has legal authority to bind your employer or such other person or entity if you are entering in this Agreement on their behalf.


“Meta” or “we” means Meta Platforms Ireland Limited (if you are located in or, if you are an entity, your principal place of business is in the EEA or Switzerland) and Meta Platforms, Inc. (if you are located outside of the EEA or Switzerland).

“Noncommercial Research Uses” means noncommercial research use cases related to research, development, education, processing, or analysis and in each case, is not primarily intended for commercial advantage or monetary compensation to you or others.

“Research Materials” means, collectively, Documentation and the models, software and algorithms, including machine-learning model code, trained model weights, inference-enabling code, training-enabling code, fine-tuning enabling code, demonstration materials and other elements of the foregoing distributed by Meta and made available under this Agreement.

By clicking “I Accept” below or by using or distributing any portion or element of the Research Materials, you agree to be bound by this Agreement.


1. License Rights and Redistribution.


a. Grant of Rights. You are granted a non-exclusive, worldwide, non-transferable and royalty-free limited license under Meta’s intellectual property or other rights owned by Meta embodied in the Research Materials to use, reproduce, distribute, copy, create derivative works of, and make modifications to the Research Materials.  
 
b. Redistribution and Use.  
 i. You will not use the Research Materials or any outputs or results of the Research Materials in connection with any commercial uses or for any uses other than Noncommercial Research Uses;


ii. Distribution of Research Materials, and any derivative works thereof, are subject to the terms of this Agreement. If you distribute or make the Research Materials, or any derivative works thereof, available to a third party, you may only do so under the terms of this Agreement. You shall also provide a copy of this Agreement to such third party.


iii.  If you submit for publication the results of research you perform on, using, or otherwise in connection with Research Materials, you must acknowledge the use of Research Materials in your publication.


iv. Your use of the Research Materials must comply with applicable laws and regulations (including Trade Control Laws) and adhere to the FAIR Acceptable Use Policy, which is hereby incorporated by reference into this Agreement.
2. User Support. Your Noncommercial Research Use of the Research Materials is done at your own discretion; Meta does not process any information nor provide any service in relation to such use.  Meta is under no obligation to provide any support services for the Research Materials. Any support provided is “as is”, “with all faults”, and without warranty of any kind.


3. Disclaimer of Warranty. UNLESS REQUIRED BY APPLICABLE LAW, THE RESEARCH MATERIALS AND ANY OUTPUT AND RESULTS THEREFROM ARE PROVIDED ON AN “AS IS” BASIS, WITHOUT WARRANTIES OF ANY KIND, AND META DISCLAIMS ALL WARRANTIES OF ANY KIND, BOTH EXPRESS AND IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. YOU ARE SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USING OR REDISTRIBUTING THE RESEARCH MATERIALS AND ASSUME ANY RISKS ASSOCIATED WITH YOUR USE OF THE RESEARCH MATERIALS AND ANY OUTPUT AND RESULTS.
 
4. Limitation of Liability. IN NO EVENT WILL META OR ITS AFFILIATES BE LIABLE UNDER ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, TORT, NEGLIGENCE, PRODUCTS LIABILITY, OR OTHERWISE, ARISING OUT OF THIS AGREEMENT, FOR ANY LOST PROFITS OR ANY DIRECT OR INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL, EXEMPLARY OR PUNITIVE DAMAGES, EVEN IF META OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF ANY OF THE FOREGOING.
 
5. Intellectual Property.


a. Subject to Meta’s ownership of Research Materials and derivatives made by or for Meta, with respect to any derivative works and modifications of the Research Materials that are made by you, as between you and Meta, you are and will be the owner of such derivative works and modifications.
 
b. If you institute litigation or other proceedings against Meta or any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Research Materials, outputs or results, or any portion of any of the foregoing, constitutes infringement of intellectual property or other rights owned or licensable by you, then any licenses granted to you under this Agreement shall terminate as of the date such litigation or claim is filed or instituted. You will indemnify and hold harmless Meta from and against any claim by any third party arising out of or related to your use or distribution of the Research Materials.
 
6. Term and Termination. The term of this Agreement will commence upon your acceptance of this Agreement or access to the Research Materials and will continue in full force and effect until terminated in accordance with the terms and conditions herein. Meta may terminate this Agreement if you are in breach of any term or condition of this Agreement. Upon termination of this Agreement, you shall delete and cease use of the Research Materials. Sections 3, 4 and 7 shall survive the termination of this Agreement. 
 
7. Governing Law and Jurisdiction. This Agreement will be governed and construed under the laws of the State of California without regard to choice of law principles, and the UN Convention on Contracts for the International Sale of Goods does not apply to this Agreement. The courts of California shall have exclusive jurisdiction of any dispute arising out of this Agreement. 


8. Modifications and Amendments. Meta may modify this Agreement from time to time; provided that they are similar in spirit to the current version of the Agreement, but may differ in detail to address new problems or concerns. All such changes will be effective immediately. Your continued use of the Research Materials after any modification to this Agreement constitutes your agreement to such modification. Except as provided in this Agreement, no modification or addition to any provision of this Agreement will be binding unless it is in writing and signed by an authorized representative of both you and Meta.


FAIR Acceptable Use Policy 

The Fundamental AI Research (FAIR) team at Meta seeks to further understanding of new and existing research domains with the mission of advancing the state-of-the-art in artificial intelligence through open research for the benefit of all. 

As part of this mission, Meta makes certain research materials available for noncommercial research use. Meta is committed to promoting the safe and responsible use of such research materials.  

Prohibited Uses

You agree you will not use, or allow others to use, Research Materials to:

 Violate the law or others’ rights, including to:
Engage in, promote, generate, contribute to, encourage, plan, incite, or further illegal or unlawful activity or content, such as:
Violence or terrorism
Exploitation or harm to children, including the solicitation, creation, acquisition, or dissemination of child exploitative content or failure to report Child Sexual Abuse Material
Human trafficking, exploitation, and sexual violence
The illegal distribution of information or materials to minors, including obscene materials, or failure to employ legally required age-gating in connection with such information or materials.
Sexual solicitation
Any other criminal activity

Engage in, promote, incite, or facilitate the harassment, abuse, threatening, or bullying of individuals or groups of individuals

Engage in, promote, incite, or facilitate discrimination or other unlawful or harmful conduct in the provision of employment, employment benefits, credit, housing, other economic benefits, or other essential goods and services

Engage in the unauthorized or unlicensed practice of any profession including, but not limited to, financial, legal, medical/health, or related professional practices

Collect, process, disclose, generate, or infer health, demographic, or other sensitive personal or private information about individuals without rights and consents required by applicable laws

Engage in or facilitate any action or generate any content that infringes, misappropriates, or otherwise violates any third-party rights, including the outputs or results of any technology using FAIR research materials

Create, generate, or facilitate the creation of malicious code, malware, computer viruses or do anything else that could disable, overburden, interfere with or impair the proper working, integrity, operation or appearance of a website or computer system

2. Engage in, promote, incite, facilitate, or assist in the planning or development of activities that present a risk of death or bodily harm to individuals, including use of research artifacts related to the following:

Military, warfare, nuclear industries or applications, espionage, use for materials or activities that are subject to the International Traffic Arms Regulations (ITAR) maintained by the United States Department of State

Guns and illegal weapons (including weapon development)

Illegal drugs and regulated/controlled substances

Operation of critical infrastructure, transportation technologies, or heavy machinery

Self-harm or harm to others, including suicide, cutting, and eating disorders

Any content intended to incite or promote violence, abuse, or any infliction of bodily harm to an individual

3. Intentionally deceive or mislead others, including use of FAIR Research Materials related to the following:

 Generating, promoting, or furthering fraud or the creation or promotion of disinformation

 Generating, promoting, or furthering defamatory content, including the creation of defamatory statements, images, or other content

Generating, promoting, or further distributing spam

 Impersonating another individual without consent, authorization, or legal right

Representing that outputs of FAIR research materials or outputs from technology using FAIR research materials are human-generated

Generating or facilitating false online engagement, including fake reviews and other means of fake online engagement

4. Fail to appropriately disclose to end users any known dangers of your Research Materials.

Please report any violation of this Policy or other problems that could lead to a violation of this Policy by submitting a report here [https://docs.google.com/forms/d/e/1FAIpQLSeb11cryAopJ7LNrC4nxEUXrHY26hfkXQMf_uH-oFgA3WlYZQ/viewform].

================================================
FILE: LICENSE_XRAY_DINO_MODEL
================================================
X-Ray DINO Research License [2025/12/18]

This X-Ray DINO Research License (“Agreement”) contains the terms and conditions that govern your access and use of the Materials (as defined below). You may not use the Materials if you do not accept this Agreement.  By clicking “I Accept” to accept, or accessing, using, or distributing any portion or element of the Materials you hereby agree to be bound by the terms of this Agreement.  If you are agreeing to be bound by the Agreement on behalf of your employer or other entity, you represent and warrant to Meta Platforms Ireland Limited (if you are located in or, if you are an entity, your principal place of business is in the EEA or Switzerland) and Meta Platforms, Inc. (if you are located outside of the EEA or Switzerland) (“Meta”) that you have full legal authority to bind your employer or such entity to this Agreement.  If you do not have requisite authority, you may not accept the Agreement or access the Materials on behalf of your employer or other entity.

This Agreement is effective upon the earlier of the date that you first access the Materials or accept this Agreement (“Effective Date”), and is entered into by and between Meta, and you, or if you are entering into this Agreement on behalf of your employer or other entity (if you are entering into this Agreement on such person or entity’s behalf), of the age required under applicable laws, rules, or regulations to provide legal consent and, your employer or other entity and that has legal authority to bind your employer or such other person or entity if you are entering in this Agreement on their behalf (“Licensee” or “You”).

1. Definitions.
“Documentation” means the specifications, manuals and documentation accompanying this release distributed by Meta at [https://github.com/facebookresearch/dinov2/blob/main/README.md].

“Noncommercial Research Use” means noncommercial research use cases related to research, development, education, processing, or analysis and in each case, is not primarily intended for commercial advantage or monetary compensation to you or others.

“Materials” means, collectively, Documentation and the models and software and algorithms, including machine-learning model code, trained model weights, inference-enabling code, training-enabling code, fine-tuning enabling code, demonstration materials and other elements of the foregoing distributed by Meta at [https://github.com/facebookresearch/dinov2/blob/main/README.md] and made available under this Agreement.

“Trade Control Laws” means any applicable U.S. and non-U.S. export control and trade sanctions laws and regulations.

2. License Rights and Redistribution. Subject to Your compliance with the terms and conditions of this Agreement, Meta hereby grants you the following:
Grant of Rights. You are hereby granted a non-exclusive, worldwide, non-transferable and royalty-free limited license under Meta’s intellectual property or other rights owned by Meta embodied in the Materials to use, reproduce, distribute, copy, create derivative works of, and make modifications to the Materials solely for Noncommercial Research Uses.
Redistribution and Use.
Distribution of Materials, and any derivative works thereof, are subject to the terms of this Agreement. If you distribute or make the Materials, or any derivative works thereof, available to a third party, you may only do so under the terms of this Agreement. You shall also provide a copy of this Agreement to such third party.
If you submit for publication the results of research you perform on, using, or otherwise in connection with Materials, you must acknowledge the use of Materials in your publication.
You must retain in all copies of the Materials that you distribute and include the following attribution notice within a “Notice” text file distributed as a part of such copies: “Materials are licensed under the X-Ray DINO Research License, Copyright © Meta Platforms, Inc. All Rights Reserved.”
Your use of the Materials must comply with applicable laws and regulations (including Trade Control Laws).
You agree to report any violation of this X-Ray DINO Research License.
3. Restrictions. You will not, and will not permit, assist or cause any third party to:
use the Materials or any outputs or results of the Materials in connection with any commercial uses or for any uses other than Noncommercial Research Uses;
use the Materials or any outputs or results of the Materials for provisioning medical advice or in connection with any clinical purpose or medical procedures, including health preventative, mitigatory, diagnostic, treatment, or curative applications or as a substitute or adjunct to professional medical judgment as the Materials have not been reviewed or approved by the Food and Drug Administration, and are for non-clinical, Noncommerical Research Use only;
disguise your or their location through IP proxying or other methods;
use or download Materials if you or they are: (a) located in a comprehensively sanctioned jurisdiction, (b) currently listed on any U.S. or non-U.S. restricted parties list, or (c) will use Materials for any purpose prohibited by Trade Control Laws; or
directly or indirectly export, re-export, provide, or otherwise transfer Materials: (a) to any individual, entity, or country prohibited by Trade Control Laws; (b) to anyone on U.S. or non-U.S. government restricted parties lists; or (c) for any purpose prohibited by Trade Control Laws, including nuclear, chemical or biological weapons, or missile technology applications.
4. User Support. Your Noncommercial Research Use of the Materials is done at your own discretion; Meta does not process any information nor provide any service in relation to such use.  Meta is under no obligation to provide any support services for the Materials. Any support provided is “as is”, “with all faults”, and without warranty of any kind.
5. Disclaimer of Warranty. UNLESS REQUIRED BY APPLICABLE LAW, THE MATERIALS AND ANY OUTPUT AND RESULTS THEREFROM ARE PROVIDED ON AN “AS IS” BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. YOU ARE SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USING OR REDISTRIBUTING THE MATERIALS AND ASSUME ANY RISKS ASSOCIATED WITH YOUR USE OF THE MATERIALS AND ANY OUTPUT AND RESULTS.
6. Limitation of Liability. IN NO EVENT WILL META OR ITS AFFILIATES BE LIABLE UNDER ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, TORT, NEGLIGENCE, PRODUCTS LIABILITY, OR OTHERWISE, ARISING OUT OF THIS AGREEMENT, FOR ANY LOST PROFITS OR ANY DIRECT OR INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL, EXEMPLARY OR PUNITIVE DAMAGES, EVEN IF META OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF ANY OF THE FOREGOING.
7. Intellectual Property.
No trademark licenses are granted under this Agreement, and in connection with the Materials, neither Meta nor Licensee may use any name or mark owned by or associated with the other or any of its affiliates, except as required for reasonable and customary use in describing and redistributing the Materials.
Subject to Meta’s ownership of Materials and derivatives made by or for Meta, with respect to any derivative works and modifications of the Materials that are made by you, as between you and Meta, you are and will be the owner of such derivative works and modifications.
If you institute litigation or other proceedings against Meta or any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Materials or outputs or results, or any portion of any of the foregoing, constitutes infringement of intellectual property or other rights owned or licensable by you, then any licenses and rights  granted to you under this Agreement shall terminate as of the date such litigation or claim is filed or instituted. You will indemnify and hold harmless Meta from and against any claim by any third party arising out of or related to your use or distribution of the Materials.
8. Term and Termination. The term of this Agreement will commence upon your acceptance of this Agreement or access to the Materials and will continue in full force and effect until terminated in accordance with the terms and conditions herein. Meta may terminate this Agreement if you are in breach of any term or condition of this Agreement. Upon termination of this Agreement, you shall delete and cease use of the Materials. Sections 3, 4, 5, 6,  7,  8 and 9 shall survive the termination of this Agreement.
9. Governing Law and Jurisdiction. This Agreement will be governed and construed under the laws of the State of California without regard to choice of law principles, and the UN Convention on Contracts for the International Sale of Goods does not apply to this Agreement. The courts of California shall have exclusive jurisdiction of any dispute arising out of this Agreement.
10. Modifications and Amendments. Meta may modify this Agreement from time to time by posting a revised version at [https://ai.meta.com/resources/models-and-libraries/raydino-license/]; provided that they are similar in spirit to the current version of the Agreement, but may differ in detail to address new problems or concerns. All such changes will be effective immediately. Your continued use of the Materials after any modification to this Agreement constitutes your agreement to such modification. Except as provided in this Agreement, no other modification or addition to any provision of this Agreement will be binding unless it is in writing and signed by an authorized representative of both you and Meta.


================================================
FILE: MODEL_CARD.md
================================================
# Model Card for DINOv2-S/B/L/g

These are Vision Transformer models trained following the method described in the papers:
"DINOv2: Learning Robust Visual Features without Supervision"
and
"Vision Transformers Need Registers".

We provide 8 models: 
- 1 ViT-g trained from scratch with 3 ViT-S/B/L models distilled from the ViT-g, without registers.
- 1 ViT-g trained from scratch with 3 ViT-S/B/L models distilled from the ViT-g, with registers.

## Model Details
The model takes an image as input and returns a class token and patch tokens, and optionally 4 register tokens.

The embedding dimension is: 
- 384 for ViT-S.
- 768 for ViT-B.
- 1024 for ViT-L.
- 1536 for ViT-g.

The models follow a Transformer architecture, with a patch size of 14. In the case of registers, we add 4 register tokens, learned during training, to the input sequence after the patch embedding.

For a 224x224 image, this results in 1 class token + 256 patch tokens, and optionally 4 register tokens.

The models can accept larger images provided the image shapes are multiples of the patch size (14). 
If this condition is not verified, the model will crop to the closest smaller multiple of the patch size.

### Model Description

- **Developed by:** Meta AI
- **Model type:** Vision Transformer
- **License:** Apache License 2.0

- **Repository:** https://github.com/facebookresearch/dinov2
- **Paper:** https://arxiv.org/abs/2304.07193
- **Demo:** https://dinov2.metademolab.com/

## Uses

The models are vision backbones providing multi-purpose features for downstream tasks.

### Direct Use

The models can be used without fine-tuning, with downstream classifiers as simple as linear layers, to obtain competitive results:
- on depth estimation, semantic segmentation, using linear layers.
- on image classification, using k-NN classifiers on the class token.
- on image classification, with logistic regression classifiers applied on the class token.
- on image classification, with a linear layer applied on the class token and the average of the patch tokens.
- on image retrieval using nearest neighbors.

### Downstream Use

It is technically possible to perform fine-tuning on the models, for small gains (we measured +2% on ImageNet-1k classification). 
We recommend keeping this as a very last step and only when necessary, as the features already provide good performance out-of-the-box.

## Bias, Risks, and Limitations

Despite improvements thanks to the training method not using annotations, we still observe significant biases in our models toward rich households from Western countries.

### Recommendations

We expect fine-tuning will increase the biases in the features produced by the model as they will be tuned to the fine-tuning labels.

## How to Get Started with the Model

Use the code below to get started with the model.

```python
import torch

# DINOv2
dinov2_vits14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vits14')
dinov2_vitb14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitb14')
dinov2_vitl14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitl14')
dinov2_vitg14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitg14')

# DINOv2 with registers
dinov2_vits14_reg = torch.hub.load('facebookresearch/dinov2', 'dinov2_vits14_reg')
dinov2_vitb14_reg = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitb14_reg')
dinov2_vitl14_reg = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitl14_reg')
dinov2_vitg14_reg = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitg14_reg')
```

## Training Details

### Training Data

- **Training data:** LVD-142M (see paper)
- **Training regime:** fp16 using PyTorch-FSDP mixed-precision.

### Training Procedure 

- **Training objective:**
  - DINO self-distillation loss with multi-crop
  - iBOT masked-image modeling loss
  - KoLeo regularization on [CLS] tokens
- **Architectures:**
  - ViT-S (21M params): Patch size 14, embedding dimension 384, 6 heads, MLP FFN
  - ViT-B (86M params): Patch size 14, embedding dimension 768, 12 heads, MLP FFN
  - ViT-L (0.3B params): Patch size 14, embedding dimension 1024, 16 heads, MLP FFN
  - ViT-g (1.1B params): Patch size 14, embedding dimension 1536, 24 heads, SwiGLU FFN
- **Distillation:**
  - Distillation follows the standard DINOv2 pretraining procedure, except the teacher is a pretrained ViT-g, frozen.

## Evaluation

We refer users to the associated papers for the evaluation protocols.

<table>
  <tr>
    <th colspan="2"></th>
    <th colspan="3">ImageNet-1k</th>
    <th>NYU-Depth v2</th>
    <th>SUN-RGBD</th>
    <th>ADE20k</th>
    <th>iNaturalist 2018</th>
    <th>Oxford-H</th>
  </tr>
  <tr>
    <th rowspan="2">model</th>
    <th rowspan="2">with <br /> registers</th>
    <th>classif. (acc)</th>
    <th>classif. (acc)</th>
    <th>classif. V2 (acc)</th>
    <th>depth (RMSE)</th>
    <th>depth (RMSE)</th>
    <th>segm. (mAP)</th>
    <th>classif. (acc)</th>
    <th>retrieval (mAP)</th>
  </tr>
  <tr>
    <!-- <th>^</th> -->
    <th>k-NN</th>
    <th>linear</th>
    <th>linear</th>
    <th>linear<br />4 layers</th>
    <th>NYU-D transfer</th>
    <th>multiscale</th>
    <th>linear</th>
    <th>nearest neighbor</th>
  </tr>
  <tr>
    <td>ViT-S/14</td>
    <td align="center">:x:</td>
    <td align="right">79.0%</td>
    <td align="right">81.1%</td>
    <td align="right">70.8%</td> 
    <td align="right">0.417</td> 
    <td align="right">0.431</td> 
    <td align="right">47.2</td> 
    <td align="right">69.5%</td> 
    <td align="right">43.2</td> 
  </tr>
  <tr>
    <td>ViT-S/14</td>
    <td align="center">:white_check_mark:</td>
    <td align="right">79.1%</td>
    <td align="right">80.9%</td>
    <td align="right">71.0%</td> 
    <td align="right">N/A</td> 
    <td align="right">N/A</td> 
    <td align="right">N/A</td> 
    <td align="right">67.6%</td> 
    <td align="right">39.5</td> 
  </tr>
  <tr>
    <td>ViT-B/14</td>
    <td align="center">:x:</td>
    <td align="right">82.1%</td>
    <td align="right">84.5%</td>
    <td align="right">74.9%</td>
    <td align="right">0.362</td> 
    <td align="right">0.400</td> 
    <td align="right">51.3</td> 
    <td align="right">76.3%</td> 
    <td align="right">49.5</td> 
  </tr>
    <td>ViT-B/14</td>
    <td align="center">:white_check_mark:</td>
    <td align="right">82.0%</td>
    <td align="right">84.6%</td>
    <td align="right">75.6%</td>
    <td align="right">N/A</td> 
    <td align="right">N/A</td> 
    <td align="right">N/A</td> 
    <td align="right">73.8%</td> 
    <td align="right">51.0</td> 
  </tr>
  <tr>
    <td>ViT-L/14</td>
    <td align="center">:x:</td>
    <td align="right">83.5%</td>
    <td align="right">86.3%</td>
    <td align="right">77.6%</td>
    <td align="right">0.333</td> 
    <td align="right">0.396</td> 
    <td align="right">53.1</td> 
    <td align="right">79.8%</td> 
    <td align="right">54.0</td> 
  </tr>
  <tr>
    <td>ViT-L/14</td>
    <td align="center">:white_check_mark:</td>
    <td align="right">83.8%</td>
    <td align="right">86.7%</td>
    <td align="right">78.5%</td>
    <td align="right">N/A</td> 
    <td align="right">N/A</td> 
    <td align="right">N/A</td> 
    <td align="right">80.9%</td> 
    <td align="right">55.7</td> 
  </tr>
  <tr>
    <td>ViT-g/14</td>
    <td align="center">:x:</td>
    <td align="right">83.5%</td>
    <td align="right">86.5%</td>
    <td align="right">78.4%</td>
    <td align="right">0.298</td> 
    <td align="right">0.362</td> 
    <td align="right">53.0</td> 
    <td align="right">81.6%</td> 
    <td align="right">52.3</td> 
  </tr>
  <tr>
  <tr>
    <td>ViT-g/14</td>
    <td align="center">:white_check_mark:</td>
    <td align="right">83.7%</td>
    <td align="right">87.1%</td>
    <td align="right">78.8%</td>
    <td align="right">N/A</td> 
    <td align="right">N/A</td> 
    <td align="right">N/A</td> 
    <td align="right">81.5%</td> 
    <td align="right">58.2</td> 
  </tr>
</table>

## Environmental Impact

- **Hardware Type:** Nvidia A100
- **Hours used:** 22,000 for ViT-g, 4,500 for ViT-S distillation, 5,300 for ViT-B distillation, 8,000 for ViT-L distillation
- **Cloud Provider:** Private infra
- **Compute Region:** USA
- **Carbon Emitted:** 7t CO2eq

#### Hardware

Nvidia A100 GPUs

#### Software

PyTorch 2.0,
xFormers 0.0.18

**BibTeX**

```
@misc{oquab2023dinov2,
  title={DINOv2: Learning Robust Visual Features without Supervision},
  author={Oquab, Maxime and Darcet, Timothée and Moutakanni, Theo and Vo, Huy and Szafraniec, Marc and Khalidov, Vasil and Fernandez, Pierre and Haziza, Daniel and Massa, Francisco and El-Nouby, Alaaeldin and Howes, Russell and Huang, Po-Yao and Xu, Hu and Sharma, Vasu and Li, Shang-Wen and Galuba, Wojciech and Rabbat, Mike and Assran, Mido and Ballas, Nicolas and Synnaeve, Gabriel and Misra, Ishan and Jegou, Herve and Mairal, Julien and Labatut, Patrick and Joulin, Armand and Bojanowski, Piotr},
  journal={arXiv:2304.07193},
  year={2023}
}
@misc{darcet2023vitneedreg,
  title={Vision Transformers Need Registers},
  author={Darcet, Timothée and Oquab, Maxime and Mairal, Julien and Bojanowski, Piotr},
  journal={arXiv:2309.16588},
  year={2023}
}
```


================================================
FILE: README.md
================================================
:new: [2025-12-18] *Added support for loading XRay-DINO backbone following [Advancing human-centric AI for robust X-ray analysis through holistic self-supervised learning](https://arxiv.org/pdf/2405.01469), more details are [here](#pretrained-backbone-xray-dino)*

:new: [2025-12-16] *Added Channel-Adaptive DINO code following [Scaling Channel-Adaptive Self-Supervised Learning](https://openreview.net/forum?id=pT8sgtRVAf), more details are [here](#dinov2-for-biology)*

:new: [2025-12-16] *Added Cell-DINO code following [Cell-DINO: Self-Supervised Image-based Embeddings for Cell Fluorescent Microscopy](to appear in Plos One Computational Biology), more details are [here](#dinov2-for-biology)*

[2025-08-14] *Please check out the more recent [DINOv3](https://github.com/facebookresearch/dinov3) effort continuing this line of work.*

[2025-06-11] *Added dino.txt inference code, following [DINOv2 Meets Text: A Unified Framework for Image- and Pixel-Level Vision-Language Alignment](https://arxiv.org/abs/2412.16334).*

[2023-10-26] *Added DINOv2 backbones with registers, following [Vision Transformers Need Registers](https://arxiv.org/abs/2309.16588).*

# DINOv2: Learning Robust Visual Features without Supervision

**[Meta AI Research, FAIR](https://ai.facebook.com/research/)**

Maxime Oquab,
Timothée Darcet,
Théo Moutakanni,
Huy V. Vo,
Marc Szafraniec,
Vasil Khalidov,
Patrick Labatut,
Armand Joulin,
Piotr Bojanowski

[[`Paper #1`](https://arxiv.org/abs/2304.07193)] [`Paper #2`](https://arxiv.org/abs/2309.16588)] [[`Blog`](https://ai.facebook.com/blog/dino-v2-computer-vision-self-supervised-learning/)] [[`Demo`](https://dinov2.metademolab.com)] [[`BibTeX`](#citing-dinov2)]

PyTorch implementation and pretrained models for DINOv2. For details, see the papers: **[DINOv2: Learning Robust Visual Features without Supervision](https://arxiv.org/abs/2304.07193)** and **[Vision Transformers Need Registers](https://arxiv.org/abs/2309.16588)**.

DINOv2 models produce high-performance visual features that can be directly employed with classifiers as simple as linear layers on a variety of computer vision tasks; these visual features are robust and perform well across domains without any requirement for fine-tuning. The models were pretrained on a dataset of 142 M images without using any labels or annotations.

https://github.com/facebookresearch/dinov2/assets/60359573/f168823e-7922-415a-b429-578badf5c356

<div align="center">
  Visualization of the three first principal components of the patch features of all frames, mapped to RGB values.
</div>

## Pretrained models

<table style="margin: auto">
  <thead>
    <tr>
      <th>model</th>
      <th># of<br />params</th>
      <th>with<br />registers</th>
      <th>ImageNet<br />k-NN</th>
      <th>ImageNet<br />linear</th>
      <th>download</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>ViT-S/14 distilled</td>
      <td align="right">21 M</td>
      <td align="center">:x:</td>
      <td align="right">79.0%</td>
      <td align="right">81.1%</td>
      <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_pretrain.pth">backbone only</a></td>
    </tr>
    <tr>
      <td>ViT-S/14 distilled</td>
      <td align="right">21 M</td>
      <td align="center">:white_check_mark:</td>
      <td align="right">79.1%</td>
      <td align="right">80.9%</td>
      <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_reg4_pretrain.pth">backbone only</a></td>
    </tr>
    <tr>
      <td>ViT-B/14 distilled</td>
      <td align="right">86 M</td>
      <td align="center">:x:</td>
      <td align="right">82.1%</td>
      <td align="right">84.5%</td>
      <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_pretrain.pth">backbone only</a></td>
    </tr>
    <tr>
      <td>ViT-B/14 distilled</td>
      <td align="right">86 M</td>
      <td align="center">:white_check_mark:</td>
      <td align="right">82.0%</td>
      <td align="right">84.6%</td>
      <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_reg4_pretrain.pth">backbone only</a></td>
    </tr>
    <tr>
      <td>ViT-L/14 distilled</td>
      <td align="right">300 M</td>
      <td align="center">:x:</td>
      <td align="right">83.5%</td>
      <td align="right">86.3%</td>
      <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_pretrain.pth">backbone only</a></td>
    </tr>
    <tr>
      <td>ViT-L/14 distilled</td>
      <td align="right">300 M</td>
      <td align="center">:white_check_mark:</td>
      <td align="right">83.8%</td>
      <td align="right">86.7%</td>
      <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_reg4_pretrain.pth">backbone only</a></td>
    </tr>
    <tr>
      <td>ViT-g/14</td>
      <td align="right">1,100 M</td>
      <td align="center">:x:</td>
      <td align="right">83.5%</td>
      <td align="right">86.5%</td>
      <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_pretrain.pth">backbone only</a></td>
    </tr>
    <tr>
      <td>ViT-g/14</td>
      <td align="right">1,100 M</td>
      <td align="center">:white_check_mark:</td>
      <td align="right">83.7%</td>
      <td align="right">87.1%</td>
      <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_reg4_pretrain.pth">backbone only</a></td>
    </tr>
  </tbody>
</table>

### Pretrained backbones (via PyTorch Hub)

Please follow the instructions [here](https://pytorch.org/get-started/locally/) to install PyTorch (the only required dependency for loading the model). Installing PyTorch with CUDA support is strongly recommended.

A corresponding [model card](MODEL_CARD.md) is included in the repository.

```python
import torch

# DINOv2
dinov2_vits14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vits14')
dinov2_vitb14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitb14')
dinov2_vitl14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitl14')
dinov2_vitg14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitg14')

# DINOv2 with registers
dinov2_vits14_reg = torch.hub.load('facebookresearch/dinov2', 'dinov2_vits14_reg')
dinov2_vitb14_reg = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitb14_reg')
dinov2_vitl14_reg = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitl14_reg')
dinov2_vitg14_reg = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitg14_reg')
```

### Pretrained backbone: XRay-DINO

Request for downloading the model is here:

https://ai.meta.com/resources/models-and-libraries/raydino-downloads/


After filling the form, you will get an email with a temporary link. You can either download it using `wget` and indicate the checkpoint path in your local filesystem, or you can directly use the URL from the email in the following code:

```python
import torch

REPO_DIR = <PATH/TO/A/LOCAL/DIRECTORY/WHERE/THE/DINOV2/REPO/WAS/CLONED>

xray_dino_vitl16 = torch.hub.load(REPO_DIR, 'xray_dino_vitl16', source='local', weights=<CHECKPOINT/URL/OR/PATH>)
```

**License**
Model weights are released under the FAIR Noncommercial Research License. See LICENSE_XRAY_DINO_MODEL for additional details.


### Pretrained heads - Image classification

<table style="margin: auto">
  <thead>
    <tr>
      <th rowspan="2">backbone</th>
      <th rowspan="2">with<br />registers</th>
      <th>download</th>
    </tr>
    <tr>
      <th>ImageNet</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>ViT-S/14 distilled</td>
      <td align="center">:x:</td>
      <td>
        linear head (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_linear4_head.pth">4 layers</a>)
      </td>
    </tr>
    <tr>
      <td>ViT-S/14 distilled</td>
      <td align="center">:white_check_mark:</td>
      <td>
        linear head (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_reg4_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_reg4_linear4_head.pth">4 layers</a>)
      </td>
    </tr>
    <tr>
      <td>ViT-B/14 distilled</td>
      <td align="center">:x:</td>
      <td>
        linear head (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_linear4_head.pth">4 layers</a>)
    </tr>
    <tr>
      <td>ViT-B/14 distilled</td>
      <td align="center">:white_check_mark:</td>
      <td>
        linear head (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_reg4_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_reg4_linear4_head.pth">4 layers</a>)
    </tr>
    <tr>
      <td>ViT-L/14 distilled</td>
      <td align="center">:x:</td>
      <td>
        linear head (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_linear4_head.pth">4 layers</a>)
    </tr>
    <tr>
      <td>ViT-L/14 distilled</td>
      <td align="center">:white_check_mark:</td>
      <td>
        linear head (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_reg4_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_reg4_linear4_head.pth">4 layers</a>)
    </tr>
    <tr>
      <td>ViT-g/14</td>
      <td align="center">:x:</td>
      <td>
        linear head (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_linear4_head.pth">4 layers</a>)
    </tr>
    <tr>
      <td>ViT-g/14</td>
      <td align="center">:white_check_mark:</td>
      <td>
        linear head (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_lreg4_inear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_reg4_linear4_head.pth">4 layers</a>)
    </tr>
  </tbody>
</table>

The (full) classifier models can be loaded via PyTorch Hub:

```python
import torch

# DINOv2
dinov2_vits14_lc = torch.hub.load('facebookresearch/dinov2', 'dinov2_vits14_lc')
dinov2_vitb14_lc = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitb14_lc')
dinov2_vitl14_lc = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitl14_lc')
dinov2_vitg14_lc = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitg14_lc')

# DINOv2 with registers
dinov2_vits14_reg_lc = torch.hub.load('facebookresearch/dinov2', 'dinov2_vits14_reg_lc')
dinov2_vitb14_reg_lc = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitb14_reg_lc')
dinov2_vitl14_reg_lc = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitl14_reg_lc')
dinov2_vitg14_reg_lc = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitg14_reg_lc')
```

### Pretrained heads - Depth estimation

<table style="margin: auto">
  <thead>
    <tr>
      <th rowspan="2">backbone</th>
      <th colspan="2">download head</th>
    </tr>
    <tr>
      <th>NYUd</th>
      <th>KITTI</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>ViT-S/14 distilled</td>
      <td>
        linear (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_nyu_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_nyu_linear4_head.pth">4 layers</a>),
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_nyu_dpt_head.pth">DPT</a>
      </td>
      <td>
        linear (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_kitti_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_kitti_linear4_head.pth">4 layers</a>),
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_kitti_dpt_head.pth">DPT</a>
      </td>
    </tr>
    <tr>
      <td>ViT-B/14 distilled</td>
      <td>
        linear (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_nyu_linear4_head.pth">4 layers</a>),
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_nyu_dpt_head.pth">DPT</a>
      </td>
      <td>
        linear (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_kitti_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_kitti_linear4_head.pth">4 layers</a>),
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_kitti_dpt_head.pth">DPT</a>
      </td>
    </tr>
    <tr>
      <td>ViT-L/14 distilled</td>
      <td>
        linear (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_nyu_linear4_head.pth">4 layers</a>),
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_nyu_dpt_head.pth">DPT</a>
      </td>
      <td>
        linear (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_kitti_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_kitti_linear4_head.pth">4 layers</a>),
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_kitti_dpt_head.pth">DPT</a>
      </td>
    </tr>
    <tr>
      <td>ViT-g/14</td>
      <td>
        linear (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_nyu_linear4_head.pth">4 layers</a>),
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_nyu_dpt_head.pth">DPT</a>
      </td>
      <td>
        linear (<a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_kitti_linear_head.pth">1 layer</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_kitti_linear4_head.pth">4 layers</a>),
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_kitti_dpt_head.pth">DPT</a>
      </td>
    </tr>
  </tbody>
</table>

### Pretrained heads - Semantic segmentation

<table style="margin: auto">
  <thead>
    <tr>
      <th rowspan="2">backbone</th>
      <th>download model</th>
      <th colspan="2">download head</th>
    </tr>
    <tr>
      <th>ADE20K</th>
      <th>ADE20K</th>
      <th>VOC2012</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>ViT-S/14 distilled</td>
      <td></td>
      <td>
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_ade20k_linear_head.pth">linear</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_ade20k_ms_head.pth">multi-scale</a>
      </td>
      <td>
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_voc2012_linear_head.pth">linear</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_voc2012_ms_head.pth">multi-scale</a>
      </td>
    </tr>
    <tr>
      <td>ViT-B/14 distilled</td>
      <td></td>
      <td>
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_ade20k_linear_head.pth">linear</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_ade20k_ms_head.pth">multi-scale</a>
      </td>
      <td>
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_voc2012_linear_head.pth">linear</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_voc2012_ms_head.pth">multi-scale</a>
      </td>
    </tr>
    <tr>
      <td>ViT-L/14 distilled</td>
      <td></td>
      <td>
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_ade20k_linear_head.pth">linear</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_ade20k_ms_head.pth">multi-scale</a>
      </td>
      <td>
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_voc2012_linear_head.pth">linear</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_voc2012_ms_head.pth">multi-scale</a>
      </td>
    </tr>
    <tr>
      <td>ViT-g/14</td>
      <td>
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_ade20k_m2f.pth">Mask2Former</a>
      </td>
      <td>
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_ade20k_linear_head.pth">linear</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_ade20k_ms_head.pth">multi-scale</a>
      </td>
      <td>
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_voc2012_linear_head.pth">linear</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_voc2012_ms_head.pth">multi-scale</a>
      </td>
    </tr>
  </tbody>
</table>


### Pretrained heads - Zero-shot tasks with dino.txt

<table style="margin: auto">
  <thead>
    <tr>
      <th rowspan="2">backbone</th>
      <th rowspan="2">with<br />registers</th>
      <th>download</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>ViT-L/14 distilled</td>
      <td align="center">:white_check_mark:</td>
      <td>
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_reg4_dinotxt_tet1280d20h24l_vision_head.pth">vision head</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_reg4_dinotxt_tet1280d20h24l_text_encoder.pth">text model</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/thirdparty/bpe_simple_vocab_16e6.txt.gz">vocabulary</a>,
        <a href="https://dl.fbaipublicfiles.com/dinov2/thirdparty/LICENSE">vocabulary license</a>
      </td>
    </tr>
  </tbody>
</table>

The (full) dino.txt model can be loaded via PyTorch Hub:

```python
import torch

# DINOv2
dinov2_vitl14_reg4_dinotxt_tet1280d20h24l = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitl14_reg4_dinotxt_tet1280d20h24l')
```


## Installation

The training and evaluation code requires PyTorch 2.0 and [xFormers](https://github.com/facebookresearch/xformers) 0.0.18 as well as a number of other 3rd party packages. Note that the code has only been tested with the specified versions and also expects a Linux environment. To setup all the required dependencies for training and evaluation, please follow the instructions below:

*[conda](https://docs.conda.io/projects/conda/en/latest/user-guide/getting-started.html)* **(Recommended)** - Clone the repository and then create and activate a `dinov2` conda environment using the provided environment definition:

```shell
conda env create -f conda.yaml
conda activate dinov2
```

*[pip](https://pip.pypa.io/en/stable/getting-started/)* - Clone the repository and then use the provided `requirements.txt` to install the dependencies:

```shell
pip install -r requirements.txt
```

For dense tasks (depth estimation and semantic segmentation), there are additional dependencies (specific versions of `mmcv` and `mmsegmentation`) which are captured in the `extras` dependency specifications:

*[conda](https://docs.conda.io/projects/conda/en/latest/user-guide/getting-started.html)* **(Recommended)**:

```shell
conda env create -f conda-extras.yaml
conda activate dinov2-extras
```

*[pip](https://pip.pypa.io/en/stable/getting-started/)*:

```shell
pip install -r requirements.txt -r requirements-extras.txt
```

## Data preparation

### ImageNet-1k

The root directory of the dataset should hold the following contents:

- `<ROOT>/test/ILSVRC2012_test_00000001.JPEG`
- `<ROOT>/test/[..]`
- `<ROOT>/test/ILSVRC2012_test_00100000.JPEG`
- `<ROOT>/train/n01440764/n01440764_10026.JPEG`
- `<ROOT>/train/[...]`
- `<ROOT>/train/n15075141/n15075141_9993.JPEG`
- `<ROOT>/val/n01440764/ILSVRC2012_val_00000293.JPEG`
- `<ROOT>/val/[...]`
- `<ROOT>/val/n15075141/ILSVRC2012_val_00049174.JPEG`
- `<ROOT>/labels.txt`

The provided dataset implementation expects a few additional metadata files to be present under the extra directory:

- `<EXTRA>/class-ids-TRAIN.npy`
- `<EXTRA>/class-ids-VAL.npy`
- `<EXTRA>/class-names-TRAIN.npy`
- `<EXTRA>/class-names-VAL.npy`
- `<EXTRA>/entries-TEST.npy`
- `<EXTRA>/entries-TRAIN.npy`
- `<EXTRA>/entries-VAL.npy`

These metadata files can be generated (once) with the following lines of Python code:

```python
from dinov2.data.datasets import ImageNet

for split in ImageNet.Split:
    dataset = ImageNet(split=split, root="<ROOT>", extra="<EXTRA>")
    dataset.dump_extra()
```

Note that the root and extra directories do not have to be distinct directories.

### ImageNet-22k

Please adapt the [dataset class](dinov2/data/datasets/image_net_22k.py) to match your local setup.

<br />

:warning: To execute the commands provided in the next sections for training and evaluation, the `dinov2` package should be included in the Python module search path, i.e. simply prefix the command to run with `PYTHONPATH=.`.

## Training

### Fast setup: training DINOv2 ViT-L/16 on ImageNet-1k

Run DINOv2 training on 4 A100-80GB nodes (32 GPUs) in a SLURM cluster environment with submitit:

```shell
python dinov2/run/train/train.py \
    --nodes 4 \
    --config-file dinov2/configs/train/vitl16_short.yaml \
    --output-dir <PATH/TO/OUTPUT/DIR> \
    train.dataset_path=ImageNet:split=TRAIN:root=<PATH/TO/DATASET>:extra=<PATH/TO/DATASET>
```

Training time is approximately 1 day and the resulting checkpoint should reach 81.6% on k-NN eval and 82.9% on linear eval.

The training code saves the weights of the teacher in the `eval` folder every 12500 iterations for evaluation.

### Long setup: training DINOv2 ViT-L/14 on ImageNet-22k

Run DINOv2 training on 12 A100-80GB nodes (96 GPUs) in a SLURM cluster environment with submitit:

```shell
python dinov2/run/train/train.py \
    --nodes 12 \
    --config-file dinov2/configs/train/vitl14.yaml \
    --output-dir <PATH/TO/OUTPUT/DIR> \
    train.dataset_path=ImageNet22k:root=<PATH/TO/DATASET>:extra=<PATH/TO/DATASET>
```

Training time is approximately 3.3 days and the resulting checkpoint should reach 82.0% on k-NN eval and 84.5% on linear eval.

The training code saves the weights of the teacher in the `eval` folder every 12500 iterations for evaluation.


## Evaluation

The training code regularly saves the teacher weights. In order to evaluate the model, run the following evaluation on a single node:

### k-NN classification on ImageNet-1k

```shell
python dinov2/run/eval/knn.py \
    --config-file <PATH/TO/OUTPUT/DIR>/config.yaml \
    --pretrained-weights <PATH/TO/OUTPUT/DIR>/eval/training_24999/teacher_checkpoint.pth \
    --output-dir <PATH/TO/OUTPUT/DIR>/eval/training_24999/knn \
    --train-dataset ImageNet:split=TRAIN:root=<PATH/TO/DATASET>:extra=<PATH/TO/DATASET> \
    --val-dataset ImageNet:split=VAL:root=<PATH/TO/DATASET>:extra=<PATH/TO/DATASET>
```

### Logistic regression classification on ImageNet-1k

```shell
python dinov2/run/eval/log_regression.py \
    --config-file <PATH/TO/OUTPUT/DIR>/config.yaml \
    --pretrained-weights <PATH/TO/OUTPUT/DIR>/eval/training_24999/teacher_checkpoint.pth \
    --output-dir <PATH/TO/OUTPUT/DIR>/eval/training_24999/logreg \
    --train-dataset ImageNet:split=TRAIN:root=<PATH/TO/DATASET>:extra=<PATH/TO/DATASET> \
    --val-dataset ImageNet:split=VAL:root=<PATH/TO/DATASET>:extra=<PATH/TO/DATASET>
```

### Linear classification with data augmentation on ImageNet-1k

```shell
python dinov2/run/eval/linear.py \
    --config-file <PATH/TO/OUTPUT/DIR>/config.yaml \
    --pretrained-weights <PATH/TO/OUTPUT/DIR>/eval/training_24999/teacher_checkpoint.pth \
    --output-dir <PATH/TO/OUTPUT/DIR>/eval/training_24999/linear \
    --train-dataset ImageNet:split=TRAIN:root=<PATH/TO/DATASET>:extra=<PATH/TO/DATASET> \
    --val-dataset ImageNet:split=VAL:root=<PATH/TO/DATASET>:extra=<PATH/TO/DATASET>
```

We release the weights from evaluating the different models:

<table style="margin: auto">
  <tr>
    <th>model</th>
    <th>with<br />registers</th>
    <th>ImageNet<br />top-1</th>
    <th>linear evaluation</th>
  </tr>
  <tr>
    <td>ViT-S/14 distilled</td>
    <td align="center">:x:</td>
    <td align="right">81.1%</td>
    <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_linear_head.pth">linear head weights</a></td>
  </tr>
  <tr>
    <td>ViT-S/14 distilled</td>
    <td align="center">:white_check_mark:</td>
    <td align="right">80.8%</td>
    <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_reg4_linear_head.pth">linear head weights</a></td>
  </tr>
  <tr>
    <td>ViT-B/14 distilled</td>
    <td align="center">:x:</td>
    <td align="right">84.5%</td>
    <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_linear_head.pth">linear head weights</a></td>
  </tr>
  <tr>
    <td>ViT-B/14 distilled</td>
    <td align="center">:white_check_mark:</td>
    <td align="right">84.4%</td>
    <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitb14/dinov2_vitb14_reg4_linear_head.pth">linear head weights</a></td>
  </tr>
  <tr>
    <td>ViT-L/14 distilled</td>
    <td align="center">:x:</td>
    <td align="right">86.3%</td>
    <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_linear_head.pth">linear head weights</a></td>
  </tr>
  <tr>
    <td>ViT-L/14 distilled</td>
    <td align="center">:white_check_mark:</td>
    <td align="right">86.5%</td>
    <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitl14/dinov2_vitl14_reg4_linear_head.pth">linear head weights</a></td>
  </tr>
  <tr>
    <td>ViT-g/14</td>
    <td align="center">:x:</td>
    <td align="right">86.5%</td>
    <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_linear_head.pth">linear head weights</a></td>
  </tr>
  <tr>
    <td>ViT-g/14</td>
    <td align="center">:white_check_mark:</td>
    <td align="right">87.0%</td>
    <td><a href="https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_reg4_linear_head.pth">linear head weights</a></td>
  </tr>
</table>

The performance of the provided pretrained model weights can be evaluated as follows on ImageNet-1k:

```shell
python dinov2/run/eval/linear.py \
    --config-file dinov2/configs/eval/vitg14_pretrain.yaml \
    --pretrained-weights https://dl.fbaipublicfiles.com/dinov2/dinov2_vitg14/dinov2_vitg14_pretrain.pth \
    --train-dataset ImageNet:split=TRAIN:root=<PATH/TO/DATASET>:extra=<PATH/TO/DATASET> \
    --val-dataset ImageNet:split=VAL:root=<PATH/TO/DATASET>:extra=<PATH/TO/DATASET>
```

## Notebooks

A few notebooks are provided to help the community leverage the models and code:

<ul>
  <li><a href="https://github.com/facebookresearch/dinov2/blob/main/notebooks/depth_estimation.ipynb">Depth estimation</a> - How to load and use the depth heads in combination with a matching backbone via mmcv</li>
  <li><a href="https://github.com/facebookresearch/dinov2/blob/main/notebooks/semantic_segmentation.ipynb">Semantic segmentation</a> - How to load and use the segmentation heads in combination with a matching backbone via mmcv, and also how to load and use the Mask2Former-based segmentation model trained on ADE20K</li>
</ul>

## License

DINOv2 code and model weights are released under the Apache License 2.0. See [LICENSE](LICENSE) for additional details.

## Contributing

See [contributing](CONTRIBUTING.md) and the [code of conduct](CODE_OF_CONDUCT.md).

## Citing DINOv2

If you find this repository useful, please consider giving a star :star: and citation :t-rex::

```
@misc{oquab2023dinov2,
  title={DINOv2: Learning Robust Visual Features without Supervision},
  author={Oquab, Maxime and Darcet, Timothée and Moutakanni, Theo and Vo, Huy V. and Szafraniec, Marc and Khalidov, Vasil and Fernandez, Pierre and Haziza, Daniel and Massa, Francisco and El-Nouby, Alaaeldin and Howes, Russell and Huang, Po-Yao and Xu, Hu and Sharma, Vasu and Li, Shang-Wen and Galuba, Wojciech and Rabbat, Mike and Assran, Mido and Ballas, Nicolas and Synnaeve, Gabriel and Misra, Ishan and Jegou, Herve and Mairal, Julien and Labatut, Patrick and Joulin, Armand and Bojanowski, Piotr},
  journal={arXiv:2304.07193},
  year={2023}
}
```

```
@misc{darcet2023vitneedreg,
  title={Vision Transformers Need Registers},
  author={Darcet, Timothée and Oquab, Maxime and Mairal, Julien and Bojanowski, Piotr},
  journal={arXiv:2309.16588},
  year={2023}
}
```

```
@misc{jose2024dinov2meetstextunified,
  title={DINOv2 Meets Text: A Unified Framework for Image- and Pixel-Level Vision-Language Alignment},
  author={Cijo Jose and Théo Moutakanni and Dahyun Kang and Federico Baldassarre and Timothée Darcet and Hu Xu and Daniel Li and Marc Szafraniec and Michaël Ramamonjisoa and Maxime Oquab and Oriane Siméoni and Huy V. Vo and Patrick Labatut and Piotr Bojanowski},
  journal={arXiv:2412.16334},
  year={2024}
}
```


# DINOv2 for Biology

The contents of the source code contained in the cell_dino folders, including the code and model weights, are intended for research use only. It is not for use in medical procedures, including any diagnostics, treatment, or curative applications. Do not use this model for any clinical purpose or as a substitute for professional medical judgement.


## Scaling Channel-Adaptive Self-Supervised Learning (Channel-Adaptive DINO)

 [[`Paper `](https://openreview.net/forum?id=pT8sgtRVAf))] [[`BibTeX`](#citing-channeladaptivedino-and-dinov2)]

Alice V. De Lorenci, Seungeun Yi, Théo Moutakanni, Piotr Bojanowski, Camille Couprie, Juan C. Caicedo, Wolfgang M. Pernice,

with special thanks to Elouan Gardes for his contributions to the codebase.

 [README](https://github.com/facebookresearch/dinov2/blob/main/docs/README_CHANNEL_ADAPTIVE_DINO.md)



## Cell-DINO: Self-Supervised Image-based Embeddings for Cell Fluorescent Microscopy (Cell-DINO)

Théo Moutakanni, Camille Couprie, Seungeun Yi, Elouan Gardes, Piotr Bojanowski, Hugo Touvron, Michael Doron, Zitong S. Chen, Nikita Moshkov, Mathilde Caron, Armand Joulin,  Wolfgang M. Pernice, Juan C. Caicedo

to appear soon.

 [README](https://github.com/facebookresearch/dinov2/blob/main/docs/README_CELL_DINO.md)


## Pretrained models

ℹ️ Please follow the link provided below to get access to all the model weights: once accepted, an e-mail will be sent with the complete list of URLs pointing to all the available model weights. These URLs can then be used to either:

- download the model or adapter weights to a local filesystem and point `torch.hub.load()` to these local weights via the `pretrained_path` parameters, or
- directly invoke `torch.hub.load()` to download and load a backbone from its URL via also the `pretrained_url` parameter.

⚠️ Please use wget instead of a web browser to download the weights.

**Download link:**
https://ai.meta.com/resources/models-and-libraries/cell-dino-downloads/

```python
import torch

REPO_DIR = <PATH/TO/A/LOCAL/DIRECTORY/WHERE/THE/DINOV2/REPO/WAS/CLONED>

# You can either download the URL link first, then load:
cell_dino_vits8 = torch.hub.load(REPO_DIR, 'cell_dino_cp_vits8', source='local', pretrained_path=<CHECKPOINT/PATH>)
# Or directly download the URL while using `torch.hub.load`:
cell_dino_vits8 = torch.hub.load(REPO_DIR, 'cell_dino_cp_vits8', source='local', pretrained_url=<CHECKPOINT/URL>)

# Similarily for other models:
cell_dino_vitl16_hpa_sc = torch.hub.load(REPO_DIR, 'cell_dino_hpa_vitl16', source='local', pretrained_path=<CHECKPOINT/PATH>)
cell_dino_vitl16_hpa_fov = torch.hub.load(REPO_DIR, 'cell_dino_hpa_vitl16', source='local', pretrained_path=<CHECKPOINT/PATH>)
channel_adaptive_dino_vitl16 = torch.hub.load(REPO_DIR, 'channel_adaptive_dino_vitl16', source='local', pretrained_path=<CHECKPOINT/PATH>)
cell_dino_vitl14 = torch.hub.load(REPO_DIR, 'cell_dino_hpa_vitl14', source='local', pretrained_path=<CHECKPOINT/PATH>)
```


 ## Licenses

 Code is released under the CC BY NC License. See [LICENSE_CELL_DINO_CODE](LICENSE_CELL_DINO_CODE) for additional details.
 Model weights are released under the FAIR Noncommercial Research License. See [LICENSE_CELL_DINO_CODE_WEIGHTS](LICENSE_CELL_DINO_CODE_WEIGHTS) for additional details.


================================================
FILE: conda-extras.yaml
================================================
name: dinov2-extras
channels:
  - defaults
  - pytorch
  - nvidia
  - xformers
  - conda-forge
dependencies:
  - python=3.9
  - pytorch::pytorch=2.0.0
  - pytorch::pytorch-cuda=11.7.0
  - pytorch::torchvision=0.15.0
  - omegaconf
  - torchmetrics=0.10.3
  - fvcore
  - iopath
  - xformers::xformers=0.0.18
  - pip
  - pip:
    - git+https://github.com/facebookincubator/submitit
    - --extra-index-url https://pypi.nvidia.com
    - cuml-cu11
    - mmcv-full==1.5.0
    - mmsegmentation==0.27.0


================================================
FILE: conda.yaml
================================================
name: dinov2
channels:
  - defaults
  - pytorch
  - nvidia
  - xformers
  - conda-forge
dependencies:
  - python=3.9
  - pytorch::pytorch=2.0.0
  - pytorch::pytorch-cuda=11.7.0
  - pytorch::torchvision=0.15.0
  - omegaconf
  - torchmetrics=0.10.3
  - fvcore
  - iopath
  - xformers::xformers=0.0.18
  - pip
  - pip:
    - git+https://github.com/facebookincubator/submitit
    - --extra-index-url https://pypi.nvidia.com
    - cuml-cu11


================================================
FILE: dinov2/__init__.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

__version__ = "0.0.1"


================================================
FILE: dinov2/configs/__init__.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

import pathlib

from omegaconf import OmegaConf


def load_config(config_name: str):
    config_filename = config_name + ".yaml"
    return OmegaConf.load(pathlib.Path(__file__).parent.resolve() / config_filename)


dinov2_default_config = load_config("ssl_default_config")


def load_and_merge_config(config_name: str):
    default_config = OmegaConf.create(dinov2_default_config)
    loaded_config = load_config(config_name)
    return OmegaConf.merge(default_config, loaded_config)


================================================
FILE: dinov2/configs/eval/cell_dino/vitl16_channel_adaptive_pretrain.yaml
================================================
train: 
  batch_size_per_gpu: 32
  OFFICIAL_EPOCH_LENGTH: 450
  cell_augmentation: true
  channel_adaptive: true
student:
  arch: vit_large
  patch_size: 16
  num_register_tokens: 0
  interpolate_antialias: false
  interpolate_offset: 0.1
  drop_path_rate: 0.1
  in_chans: 1
  block_chunks: 4
  channel_adaptive: true
teacher:
  momentum_teacher: 0.996
  warmup_teacher_temp_epochs: 20
  in_chans: 1
  channel_adaptive: true
crops:
  global_crops_scale:
  - 0.4
  - 1.0
  local_crops_number: 8
  local_crops_scale:
  - 0.005
  - 0.4
  global_crops_size: 224
  local_crops_size: 96
optim:
  weight_decay_end: 0.2
  base_lr: 5.0e-4 
  warmup_epochs: 20
  epochs: 400

================================================
FILE: dinov2/configs/eval/cell_dino/vitl16_pretrain.yaml
================================================
student:
  arch: vit_large
  patch_size: 16
  num_register_tokens: 0
  interpolate_antialias: false
  interpolate_offset: 0.1
  drop_path_rate: 0.1
  in_chans: 4
  block_chunks: 4
teacher:
  in_chans: 4  
crops:
  global_crops_size: 224
  local_crops_size: 96


================================================
FILE: dinov2/configs/eval/vitb14_pretrain.yaml
================================================
student:
  arch: vit_base
  patch_size: 14
crops:
  global_crops_size: 518  # this is to set up the position embeddings properly
  local_crops_size: 98

================================================
FILE: dinov2/configs/eval/vitb14_reg4_pretrain.yaml
================================================
student:
  arch: vit_base
  patch_size: 14
  num_register_tokens: 4
  interpolate_antialias: true
  interpolate_offset: 0.0
crops:
  global_crops_size: 518  # this is to set up the position embeddings properly
  local_crops_size: 98

================================================
FILE: dinov2/configs/eval/vitg14_pretrain.yaml
================================================
student:
  arch: vit_giant2
  patch_size: 14
  ffn_layer: swiglufused
crops:
  global_crops_size: 518  # this is to set up the position embeddings properly
  local_crops_size: 98

================================================
FILE: dinov2/configs/eval/vitg14_reg4_pretrain.yaml
================================================
student:
  arch: vit_giant2
  patch_size: 14
  ffn_layer: swiglufused
  num_register_tokens: 4
  interpolate_antialias: true
  interpolate_offset: 0.0
crops:
  global_crops_size: 518  # this is to set up the position embeddings properly
  local_crops_size: 98

================================================
FILE: dinov2/configs/eval/vitl14_pretrain.yaml
================================================
student:
  arch: vit_large
  patch_size: 14
crops:
  global_crops_size: 518  # this is to set up the position embeddings properly
  local_crops_size: 98

================================================
FILE: dinov2/configs/eval/vitl14_reg4_pretrain.yaml
================================================
student:
  arch: vit_large
  patch_size: 14
  num_register_tokens: 4
  interpolate_antialias: true
  interpolate_offset: 0.0
crops:
  global_crops_size: 518  # this is to set up the position embeddings properly
  local_crops_size: 98

================================================
FILE: dinov2/configs/eval/vits14_pretrain.yaml
================================================
student:
  arch: vit_small
  patch_size: 14
crops:
  global_crops_size: 518  # this is to set up the position embeddings properly
  local_crops_size: 98

================================================
FILE: dinov2/configs/eval/vits14_reg4_pretrain.yaml
================================================
student:
  arch: vit_small
  patch_size: 14
  num_register_tokens: 4
  interpolate_antialias: true
  interpolate_offset: 0.0
crops:
  global_crops_size: 518  # this is to set up the position embeddings properly
  local_crops_size: 98

================================================
FILE: dinov2/configs/ssl_default_config.yaml
================================================
MODEL:
  WEIGHTS: ''
compute_precision:
  grad_scaler: true
  teacher:
    backbone:
      sharding_strategy: SHARD_GRAD_OP
      mixed_precision:
        param_dtype: fp16
        reduce_dtype: fp16
        buffer_dtype: fp32
    dino_head:
      sharding_strategy: SHARD_GRAD_OP
      mixed_precision:
        param_dtype: fp16
        reduce_dtype: fp16
        buffer_dtype: fp32
    ibot_head:
      sharding_strategy: SHARD_GRAD_OP
      mixed_precision:
        param_dtype: fp16
        reduce_dtype: fp16
        buffer_dtype: fp32
  student:
    backbone:
      sharding_strategy: SHARD_GRAD_OP
      mixed_precision:
        param_dtype: fp16
        reduce_dtype: fp16
        buffer_dtype: fp32
    dino_head:
      sharding_strategy: SHARD_GRAD_OP
      mixed_precision:
        param_dtype: fp16
        reduce_dtype: fp32
        buffer_dtype: fp32
    ibot_head:
      sharding_strategy: SHARD_GRAD_OP
      mixed_precision:
        param_dtype: fp16
        reduce_dtype: fp32
        buffer_dtype: fp32
dino:
  loss_weight: 1.0
  head_n_prototypes: 65536
  head_bottleneck_dim: 256
  head_nlayers: 3
  head_hidden_dim: 2048
  koleo_loss_weight: 0.1
ibot:
  loss_weight: 1.0
  mask_sample_probability: 0.5
  mask_ratio_min_max:
  - 0.1
  - 0.5
  separate_head: false
  head_n_prototypes: 65536
  head_bottleneck_dim: 256
  head_nlayers: 3
  head_hidden_dim: 2048
train:
  batch_size_per_gpu: 64
  dataset_path: ImageNet:split=TRAIN
  output_dir: .
  saveckp_freq: 20
  seed: 0
  num_workers: 10
  OFFICIAL_EPOCH_LENGTH: 1250
  cache_dataset: true
  centering: "centering" # or "sinkhorn_knopp"
  cell_augmentation: false
student:
  arch: vit_large
  patch_size: 16
  drop_path_rate: 0.3
  layerscale: 1.0e-05
  drop_path_uniform: true
  pretrained_weights: ''
  ffn_layer: "mlp"
  block_chunks: 0
  qkv_bias: true
  proj_bias: true
  ffn_bias: true
  num_register_tokens: 0
  interpolate_antialias: false
  interpolate_offset: 0.1
  in_chans: 3
  channel_adaptive: false
teacher:
  momentum_teacher: 0.992
  final_momentum_teacher: 1
  warmup_teacher_temp: 0.04
  teacher_temp: 0.07
  warmup_teacher_temp_epochs: 30
  in_chans: 3
  channel_adaptive: false
optim:
  epochs: 100
  weight_decay: 0.04
  weight_decay_end: 0.4
  base_lr: 0.004  # learning rate for a batch size of 1024
  lr: 0.  # will be set after applying scaling rule
  warmup_epochs: 10
  min_lr: 1.0e-06
  clip_grad: 3.0
  freeze_last_layer_epochs: 1
  scaling_rule: sqrt_wrt_1024
  patch_embed_lr_mult: 0.2
  layerwise_decay: 0.9
  adamw_beta1: 0.9
  adamw_beta2: 0.999
crops:
  global_crops_scale:
  - 0.32
  - 1.0
  local_crops_number: 8
  local_crops_scale:
  - 0.05
  - 0.32
  global_crops_size: 224
  local_crops_size: 96
evaluation:
  eval_period_iterations: 12500


================================================
FILE: dinov2/configs/train/cell_dino/vitl16_boc_hpafov.yaml
================================================
train: 
  batch_size_per_gpu: 16
  OFFICIAL_EPOCH_LENGTH: 450
  cell_augmentation: true
  channel_adaptive: true
student: 
  arch: vit_large
  patch_size: 16
  in_chans: 1
  drop_path_rate: 0.1
  block_chunks: 4
teacher:
  momentum_teacher: 0.996
  warmup_teacher_temp_epochs: 20
  in_chans: 1
crops:
  global_crops_scale:
  - 0.4
  - 1.0
  local_crops_number: 8
  local_crops_scale:
  - 0.005
  - 0.4
  global_crops_size: 224
  local_crops_size: 96
optim:
  weight_decay_end: 0.2
  base_lr: 5.0e-4 
  warmup_epochs: 20
  epochs: 400  
  

================================================
FILE: dinov2/configs/train/cell_dino/vitl16_hpafov.yaml
================================================
train: 
  batch_size_per_gpu: 16
  OFFICIAL_EPOCH_LENGTH: 450
  cell_augmentation: true
student: 
  arch: vit_large
  patch_size: 16
  in_chans: 4
  drop_path_rate: 0.1
  block_chunks: 4
teacher:
  momentum_teacher: 0.996
  warmup_teacher_temp_epochs: 20
  in_chans: 4
optim:
  weight_decay_end: 0.2
  base_lr: 5.0e-4 
  warmup_epochs: 20   
crops:
  global_crops_scale:
  - 0.4
  - 1.0
  local_crops_number: 8
  local_crops_scale:
  - 0.005
  - 0.4
  global_crops_size: 224
  local_crops_size: 96
evaluation:  
  eval_period_iterations: 9000

  

================================================
FILE: dinov2/configs/train/cell_dino/vitl16_hpaone.yaml
================================================
train: 
  batch_size_per_gpu: 16
  OFFICIAL_EPOCH_LENGTH: 1756
  cell_augmentation: true
student: 
  arch: vit_large
  patch_size: 16
  in_chans: 4
  drop_path_rate: 0.1
  block_chunks: 4
teacher:
  momentum_teacher: 0.996
  warmup_teacher_temp_epochs: 20
  in_chans: 4
optim:
  weight_decay_end: 0.2
  base_lr: 5.0e-4 
  warmup_epochs: 20
crops:
  global_crops_scale:
  - 0.4
  - 1.0
  local_crops_number: 8
  local_crops_scale:
  - 0.005
  - 0.4
  global_crops_size: 224
  local_crops_size: 96
evaluation:  
  eval_period_iterations: 9000

================================================
FILE: dinov2/configs/train/vitg14.yaml
================================================
dino:
  head_n_prototypes: 131072
  head_bottleneck_dim: 384
ibot:
  separate_head: true
  head_n_prototypes: 131072
train:
  batch_size_per_gpu: 12
  dataset_path: ImageNet22k
  centering: sinkhorn_knopp
student:
  arch: vit_giant2
  patch_size: 14
  drop_path_rate: 0.4
  ffn_layer: swiglufused
  block_chunks: 4
teacher:
  momentum_teacher: 0.994
optim:
  epochs: 500
  weight_decay_end: 0.2
  base_lr: 2.0e-04  # learning rate for a batch size of 1024
  warmup_epochs: 80
  layerwise_decay: 1.0
crops:
  local_crops_size: 98

================================================
FILE: dinov2/configs/train/vitl14.yaml
================================================
dino:
  head_n_prototypes: 131072
  head_bottleneck_dim: 384
ibot:
  separate_head: true
  head_n_prototypes: 131072
train:
  batch_size_per_gpu: 32
  dataset_path: ImageNet22k
  centering: sinkhorn_knopp
student:
  arch: vit_large
  patch_size: 14
  drop_path_rate: 0.4
  ffn_layer: swiglufused
  block_chunks: 4
teacher:
  momentum_teacher: 0.994
optim:
  epochs: 500
  weight_decay_end: 0.2
  base_lr: 2.0e-04  # learning rate for a batch size of 1024
  warmup_epochs: 80
  layerwise_decay: 1.0
crops:
  local_crops_size: 98

================================================
FILE: dinov2/configs/train/vitl16_short.yaml
================================================
# this corresponds to the default config
train:
  dataset_path: ImageNet:split=TRAIN
  batch_size_per_gpu: 64
student:
  block_chunks: 4


================================================
FILE: dinov2/data/__init__.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

from .adapters import DatasetWithEnumeratedTargets
from .loaders import make_data_loader, make_dataset, SamplerType
from .collate import collate_data_and_cast
from .masking import MaskingGenerator
from .augmentations import DataAugmentationDINO
from .cell_dino.augmentations import CellAugmentationDINO
from .accumulators import NoOpAccumulator, ResultsAccumulator


================================================
FILE: dinov2/data/accumulators.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

from collections import defaultdict
from typing import Dict, List, Optional, Any

import torch
from torch import Tensor
from torch.nn import functional as F

import torch.distributed as dist
from dinov2.distributed import get_global_size


def _simple_gather_all_tensors(result: torch.Tensor, group: Any, world_size: int) -> List[torch.Tensor]:
    gathered_result = [torch.zeros_like(result) for _ in range(world_size)]
    dist.all_gather(gathered_result, result, group)
    return gathered_result


def gather_all_tensors(result: torch.Tensor, group: Optional[Any] = None) -> List[torch.Tensor]:
    """
    Copied from https://github.com/Lightning-AI/torchmetrics/blob/master/src/torchmetrics/utilities/distributed.py
    Gather all tensors from several ddp processes onto a list that is broadcasted to all processes.

    Works on tensors that have the same number of dimensions, but where each dimension may differ. In this case
    tensors are padded, gathered and then trimmed to secure equal workload for all processes.

    Args:
        result: the value to sync
        group: the process group to gather results from. Defaults to all processes (world)

    Return:
        list with size equal to the process group where element i corresponds to result tensor from process i
    """
    # convert tensors to contiguous format
    result = result.contiguous()

    world_size = get_global_size()
    dist.barrier(group=group)

    # if the tensor is scalar, things are easy
    if result.ndim == 0:
        return _simple_gather_all_tensors(result, group, world_size)

    # 1. Gather sizes of all tensors
    local_size = torch.tensor(result.shape, device=result.device)
    local_sizes = [torch.zeros_like(local_size) for _ in range(world_size)]
    dist.all_gather(local_sizes, local_size, group=group)
    max_size = torch.stack(local_sizes).max(dim=0).values
    all_sizes_equal = all(all(ls == max_size) for ls in local_sizes)

    # 2. If shapes are all the same, then do a simple gather:
    if all_sizes_equal:
        return _simple_gather_all_tensors(result, group, world_size)

    # 3. If not, we need to pad each local tensor to maximum size, gather and then truncate
    pad_dims = []
    pad_by = (max_size - local_size).detach().cpu()
    for val in reversed(pad_by):
        pad_dims.append(0)
        pad_dims.append(val.item())
    result_padded = F.pad(result, pad_dims)
    gathered_result = [torch.zeros_like(result_padded) for _ in range(world_size)]
    dist.all_gather(gathered_result, result_padded, group)
    for idx, item_size in enumerate(local_sizes):
        slice_param = [slice(dim_size) for dim_size in item_size]
        gathered_result[idx] = gathered_result[idx][slice_param]
    return gathered_result


def _cat_and_gather_tensor_list(tensor_list: List[Tensor]) -> Tensor:
    local_cat = torch.cat(tensor_list)
    return torch.cat(gather_all_tensors(local_cat))


class Accumulator:
    def __init__(self) -> None:
        pass

    def update(self, preds: Tensor, target: Tensor, index: Tensor) -> None:
        raise NotImplementedError

    def accumulate(self) -> Optional[Dict[str, Tensor]]:
        raise NotImplementedError


class NoOpAccumulator(Accumulator):
    def __init__(self) -> None:
        pass

    def update(self, preds: Tensor, target: Tensor, index: Tensor) -> None:
        pass

    def accumulate(self) -> None:
        return None


class ResultsAccumulator(Accumulator):
    """
    Accumulate predictions and targets across processes
    """

    def __init__(self) -> None:
        self._local_values: Dict[str, List[Tensor]] = defaultdict(list)
        self._gathered_values: Dict[str, Tensor] = {}
        self._gathered = False

    def update(self, preds: Tensor, target: Tensor, index: Tensor) -> None:
        assert len(preds) == len(target) == len(index)
        assert not self._gathered, "Tensors have already been gathered in this helper"
        self._local_values["preds"].append(preds)
        self._local_values["target"].append(target)
        self._local_values["index"].append(index)
        self._gathered = False

    def _gather_tensors(self):
        for k, tensor_list in self._local_values.items():
            self._gathered_values[k] = _cat_and_gather_tensor_list(tensor_list)
        self._gathered = True

    def accumulate(self) -> Dict[str, Tensor]:
        if not self._gathered:
            self._gather_tensors()
        preds, target, index = [self._gathered_values[k] for k in ["preds", "target", "index"]]
        assert len(preds) == len(target) == len(index) and index.min() == 0
        preds_ordered = torch.zeros((index.max() + 1, *preds.shape[1:]), dtype=preds.dtype, device=preds.device)
        preds_ordered[index] = preds
        target_ordered = torch.zeros((index.max() + 1, *target.shape[1:]), dtype=target.dtype, device=target.device)
        target_ordered[index] = target
        return {"preds": preds_ordered, "target": target_ordered}


================================================
FILE: dinov2/data/adapters.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

from typing import Any, Tuple, Optional

from torch.utils.data import Dataset


class DatasetWithEnumeratedTargets(Dataset):
    """
    If pad_dataset is set, pads based on torch's DistributedSampler implementation, which
    with drop_last=False pads the last batch to be a multiple of the world size.
    https://github.com/pytorch/pytorch/blob/main/torch/utils/data/distributed.py#L91
    """

    def __init__(self, dataset: Dataset, pad_dataset: bool = False, num_replicas: Optional[int] = None):
        self._dataset = dataset
        self._size = len(self._dataset)
        self._padded_size = self._size
        self._pad_dataset = pad_dataset
        if self._pad_dataset:
            assert num_replicas is not None, "num_replicas should be set if pad_dataset is True"
            self._padded_size = num_replicas * ((len(dataset) + num_replicas - 1) // num_replicas)

    def get_image_relpath(self, index: int) -> str:
        assert self._pad_dataset or index < self._size
        return self._dataset.get_image_relpath(index % self._size)

    def get_image_data(self, index: int) -> bytes:
        assert self._pad_dataset or index < self._size
        return self._dataset.get_image_data(index % self._size)

    def get_target(self, index: int) -> Tuple[Any, int]:
        target = self._dataset.get_target(index % self._size)
        if index >= self._size:
            assert self._pad_dataset
            return (-1, target)
        return (index, target)

    def __getitem__(self, index: int) -> Tuple[Any, Tuple[Any, int]]:
        image, target = self._dataset[index % self._size]
        if index >= self._size:
            assert self._pad_dataset
            return image, (-1, target)
        target = index if target is None else target
        return image, (index, target)

    def __len__(self) -> int:
        return self._padded_size


================================================
FILE: dinov2/data/augmentations.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

import logging

from torchvision import transforms

from .transforms import (
    GaussianBlur,
    make_normalize_transform,
)


logger = logging.getLogger("dinov2")


class DataAugmentationDINO(object):
    def __init__(
        self,
        global_crops_scale,
        local_crops_scale,
        local_crops_number,
        global_crops_size=224,
        local_crops_size=96,
    ):
        self.global_crops_scale = global_crops_scale
        self.local_crops_scale = local_crops_scale
        self.local_crops_number = local_crops_number
        self.global_crops_size = global_crops_size
        self.local_crops_size = local_crops_size

        logger.info("###################################")
        logger.info("Using data augmentation parameters:")
        logger.info(f"global_crops_scale: {global_crops_scale}")
        logger.info(f"local_crops_scale: {local_crops_scale}")
        logger.info(f"local_crops_number: {local_crops_number}")
        logger.info(f"global_crops_size: {global_crops_size}")
        logger.info(f"local_crops_size: {local_crops_size}")
        logger.info("###################################")

        # random resized crop and flip
        self.geometric_augmentation_global = transforms.Compose(
            [
                transforms.RandomResizedCrop(
                    global_crops_size, scale=global_crops_scale, interpolation=transforms.InterpolationMode.BICUBIC
                ),
                transforms.RandomHorizontalFlip(p=0.5),
            ]
        )

        self.geometric_augmentation_local = transforms.Compose(
            [
                transforms.RandomResizedCrop(
                    local_crops_size, scale=local_crops_scale, interpolation=transforms.InterpolationMode.BICUBIC
                ),
                transforms.RandomHorizontalFlip(p=0.5),
            ]
        )

        # color distorsions / blurring
        color_jittering = transforms.Compose(
            [
                transforms.RandomApply(
                    [transforms.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.2, hue=0.1)],
                    p=0.8,
                ),
                transforms.RandomGrayscale(p=0.2),
            ]
        )

        global_transfo1_extra = GaussianBlur(p=1.0)

        global_transfo2_extra = transforms.Compose(
            [
                GaussianBlur(p=0.1),
                transforms.RandomSolarize(threshold=128, p=0.2),
            ]
        )

        local_transfo_extra = GaussianBlur(p=0.5)

        # normalization
        self.normalize = transforms.Compose(
            [
                transforms.ToTensor(),
                make_normalize_transform(),
            ]
        )

        self.global_transfo1 = transforms.Compose([color_jittering, global_transfo1_extra, self.normalize])
        self.global_transfo2 = transforms.Compose([color_jittering, global_transfo2_extra, self.normalize])
        self.local_transfo = transforms.Compose([color_jittering, local_transfo_extra, self.normalize])

    def __call__(self, image):
        output = {}

        # global crops:
        im1_base = self.geometric_augmentation_global(image)
        global_crop_1 = self.global_transfo1(im1_base)

        im2_base = self.geometric_augmentation_global(image)
        global_crop_2 = self.global_transfo2(im2_base)

        output["global_crops"] = [global_crop_1, global_crop_2]

        # global crops for teacher:
        output["global_crops_teacher"] = [global_crop_1, global_crop_2]

        # local crops:
        local_crops = [
            self.local_transfo(self.geometric_augmentation_local(image)) for _ in range(self.local_crops_number)
        ]
        output["local_crops"] = local_crops
        output["offsets"] = ()

        return output


================================================
FILE: dinov2/data/cell_dino/augmentations.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the CC-by-NC licence,
# found in the LICENSE_CELL_DINO_CODE file in the root directory of this source tree.

import logging
import torchvision
from torchvision import transforms

from .transforms import (
    RandomContrastProteinChannel,
    RandomRemoveChannelExceptProtein,
    RandomBrightness,
    RandomContrast,
    Div255,
    SelfNormalizeNoDiv,
)

logger = logging.getLogger("dinov2")


class CellAugmentationDINO(object):
    def __init__(
        self,
        global_crops_scale,
        local_crops_scale,
        local_crops_number,
        global_crops_size=224,
        local_crops_size=96,
    ):
        self.global_crops_scale = global_crops_scale
        self.local_crops_scale = local_crops_scale
        self.local_crops_number = local_crops_number
        self.global_crops_size = global_crops_size
        self.local_crops_size = local_crops_size

        logger.info("###################################")
        logger.info("Using data augmentation parameters:")
        logger.info(f"global_crops_scale: {global_crops_scale}")
        logger.info(f"local_crops_scale: {local_crops_scale}")
        logger.info(f"local_crops_number: {local_crops_number}")
        logger.info(f"global_crops_size: {global_crops_size}")
        logger.info(f"local_crops_size: {local_crops_size}")
        logger.info("###################################")

        additional_transforms_list = [
            torchvision.transforms.RandomHorizontalFlip(),
            torchvision.transforms.RandomVerticalFlip(),
            RandomBrightness(),
            RandomContrast(),
            SelfNormalizeNoDiv(),
        ]

        first_transforms_list = [
            Div255(),
            RandomRemoveChannelExceptProtein(),
            RandomContrastProteinChannel(),
        ]

        global_transforms_list = first_transforms_list.copy()
        global_transforms_list.append(
            torchvision.transforms.RandomResizedCrop(size=global_crops_size, scale=global_crops_scale)
        )
        global_transforms_list = global_transforms_list + additional_transforms_list

        local_transforms_list = first_transforms_list
        local_transforms_list.append(
            torchvision.transforms.RandomResizedCrop(size=local_crops_size, scale=local_crops_scale)
        )
        local_transforms_list = local_transforms_list + additional_transforms_list

        self.global_transform = transforms.Compose(global_transforms_list)
        self.local_transform = transforms.Compose(local_transforms_list)

    def __call__(self, image):
        output = {}

        global_crop1 = self.global_transform(image)
        global_crop2 = self.global_transform(image)

        output["global_crops"] = [global_crop1, global_crop2]

        local_crops = []
        for _ in range(self.local_crops_number):
            local_crops.append(self.local_transform(image))

        output["local_crops"] = local_crops
        output["global_crops_teacher"] = [global_crop1, global_crop2]
        output["offsets"] = ()

        return output


================================================
FILE: dinov2/data/cell_dino/transforms.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the CC-by-NC licence,
# found in the LICENSE_CELL_DINO_CODE file in the root directory of this source tree.

import torch
from torchvision import transforms
import numpy as np
from enum import Enum


class NormalizationType(Enum):
    SELF_NORM_AUG_DECODER = "self_norm_aug_decoder"
    SELF_NORM_CENTER_CROP = "self_norm_center_crop"


class Div255(torch.nn.Module):
    def forward(self, x):
        x = x / 255
        return x


class SelfNormalizeNoDiv(torch.nn.Module):
    def forward(self, x):
        m = x.mean((-2, -1), keepdim=True)
        s = x.std((-2, -1), unbiased=False, keepdim=True)
        x -= m
        x /= s + 1e-7
        return x


class SelfNormalize(torch.nn.Module):
    def forward(self, x):
        x = x / 255
        m = x.mean((-2, -1), keepdim=True)
        s = x.std((-2, -1), unbiased=False, keepdim=True)
        x -= m
        x /= s + 1e-7
        return x


class RandomContrastProteinChannel(torch.nn.Module):
    """
    Random constrast rescaling of the protein channel only.
    RescaleProtein function in Dino4cell codebase.
    """

    def __init__(self, p=0.2):
        super().__init__()
        self.p = p

    def forward(self, img):
        if img.max() == 0:
            return img
        if len(img) == 1:
            return img
        if np.random.rand() <= self.p:
            random_factor = (np.random.rand() * 2) / img.max()  # scaling
            img[1] = img[1] * random_factor
            return img
        else:
            return img


class RandomRemoveChannelExceptProtein(torch.nn.Module):
    """
    dropping a channel at random except the channel 1, corresponding to proteins in HPA datasets.
    """

    def __init__(self, p=0.2):
        super().__init__()
        self.p = p

    def forward(self, img):
        img_size = np.array(img).shape
        if img_size[0] < 4:
            return img
        if np.random.rand() <= self.p:
            channel_to_blacken = np.random.choice(np.array([0, 2, 3]))
            img[channel_to_blacken] = torch.zeros(1, *img.shape[1:])
            return img
        else:
            return img


class RandomRemoveChannel(torch.nn.Module):
    """
    dropping a channel at random
    """

    def __init__(self, p=0.2):
        super().__init__()
        self.p = p

    def forward(self, img):
        img_size = np.array(img).shape
        num_channels = img_size[0]
        if num_channels < 4:
            return img
        if np.random.rand() <= self.p:
            channel_to_blacken = np.random.choice(np.array(list(range(num_channels))))
            img[channel_to_blacken] = torch.zeros(1, *img.shape[1:])
            return img
        else:
            return img


class RandomContrast(torch.nn.Module):
    def __init__(self, p=0.2):
        super().__init__()
        self.p = p

    def forward(self, img):
        if img.max() == 0:
            return img
        n_channels = img.shape[0]
        for ind in range(n_channels):
            factor = max(np.random.normal(1, self.p), 0.5)
            img[ind] = transforms.functional.adjust_contrast(img[ind][None, ...], factor)
        return img


class RandomBrightness(torch.nn.Module):
    def __init__(self, p=0.2):
        super().__init__()
        self.p = p

    def forward(self, img):
        if img.max() == 0:
            return img
        n_channels = img.shape[0]
        for ind in range(n_channels):
            factor = max(np.random.normal(1, self.p), 0.5)
            img[ind] = transforms.functional.adjust_brightness(img[ind], factor)
        return img


def make_classification_eval_cell_transform(
    *,
    resize_size: int = 0,
    interpolation=transforms.InterpolationMode.BICUBIC,
    crop_size: int = 384,
    normalization_type: Enum = NormalizationType.SELF_NORM_CENTER_CROP,
) -> transforms.Compose:

    from .transforms import (
        Div255,
        SelfNormalizeNoDiv,
    )

    transforms_list = [Div255()]
    if resize_size > 0:
        transforms_list.append(transforms.Resize(resize_size, interpolation=interpolation))

    if normalization_type == NormalizationType.SELF_NORM_AUG_DECODER:
        transforms_list.extend(
            [
                transforms.RandomCrop(size=crop_size, pad_if_needed=True),
                transforms.RandomHorizontalFlip(),
                transforms.RandomVerticalFlip(),
            ]
        )
    elif normalization_type == NormalizationType.SELF_NORM_CENTER_CROP:
        transforms_list.append(transforms.CenterCrop(size=crop_size))
    else:
        raise ValueError("f{normalization_type}: unknown NormalizationType")
    transforms_list.append(SelfNormalizeNoDiv())

    return transforms.Compose(transforms_list)


================================================
FILE: dinov2/data/collate.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

import torch
import random


def collate_data_and_cast(samples_list, mask_ratio_tuple, mask_probability, dtype, n_tokens=None, mask_generator=None):
    # dtype = torch.half  # TODO: Remove

    n_global_crops = len(samples_list[0][0]["global_crops"])
    n_local_crops = len(samples_list[0][0]["local_crops"])

    collated_global_crops = torch.stack([s[0]["global_crops"][i] for i in range(n_global_crops) for s in samples_list])

    collated_local_crops = torch.stack([s[0]["local_crops"][i] for i in range(n_local_crops) for s in samples_list])

    B = len(collated_global_crops)
    N = n_tokens
    n_samples_masked = int(B * mask_probability)
    probs = torch.linspace(*mask_ratio_tuple, n_samples_masked + 1)
    upperbound = 0
    masks_list = []
    for i in range(0, n_samples_masked):
        prob_min = probs[i]
        prob_max = probs[i + 1]
        masks_list.append(torch.BoolTensor(mask_generator(int(N * random.uniform(prob_min, prob_max)))))
        upperbound += int(N * prob_max)
    for i in range(n_samples_masked, B):
        masks_list.append(torch.BoolTensor(mask_generator(0)))

    random.shuffle(masks_list)

    collated_masks = torch.stack(masks_list).flatten(1)
    mask_indices_list = collated_masks.flatten().nonzero().flatten()

    masks_weight = (1 / collated_masks.sum(-1).clamp(min=1.0)).unsqueeze(-1).expand_as(collated_masks)[collated_masks]

    return {
        "collated_global_crops": collated_global_crops.to(dtype),
        "collated_local_crops": collated_local_crops.to(dtype),
        "collated_masks": collated_masks,
        "mask_indices_list": mask_indices_list,
        "masks_weight": masks_weight,
        "upperbound": upperbound,
        "n_masked_patches": torch.full((1,), fill_value=mask_indices_list.shape[0], dtype=torch.long),
    }


================================================
FILE: dinov2/data/datasets/__init__.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

from .image_net import ImageNet
from .image_net_22k import ImageNet22k
from .cell_dino.hpaone import HPAone
from .cell_dino.hpafov import HPAFoV
from .cell_dino.chammi_cp import CHAMMI_CP
from .cell_dino.chammi_hpa import CHAMMI_HPA
from .cell_dino.chammi_wtc import CHAMMI_WTC


================================================
FILE: dinov2/data/datasets/cell_dino/chammi_cp.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the CC-by-NC licence,
# found in the LICENSE_CELL_DINO_CODE file in the root directory of this source tree.

import csv
from enum import Enum
import logging
import os
from typing import Any, Callable, Optional, Union

import numpy as np

from ..extended import ExtendedVisionDataset
from ..decoders import DecoderType

logger = logging.getLogger("dinov2")


METADATA_FILE = "morphem70k_v2.csv"

CLASS_LABELS = {
    "BRD-A29260609": 0,
    "BRD-K04185004": 1,
    "BRD-K21680192": 2,
    "DMSO": 3,
    "BRD-K11129031": 4,  # labels only seen in TASK_FOUR
    "BRD-K62310379": 5,
    "BRD-K77947974": 6,
}


class _Split(Enum):
    TRAIN = "Train"
    TASK_ONE = "Task_one"
    TASK_TWO = "Task_two"
    TASK_THREE = "Task_three"
    TASK_FOUR = "Task_four"


def _load_file_names_and_targets(
    root: str,
    split: _Split,
):
    image_paths = []
    labels = []
    with open(os.path.join(root, METADATA_FILE)) as metadata:
        metadata_reader = csv.DictReader(metadata)
        for row in metadata_reader:
            row_dataset = row["file_path"].split("/")[0]

            if row["train_test_split"].upper() == split and row_dataset == "CP":
                image_paths.append(row["file_path"])
                labels.append(CLASS_LABELS[row["label"]])

    return image_paths, labels  # to debug


class CHAMMI_CP(ExtendedVisionDataset):
    """
    Implementation of the CP (Cell-Painting) subset of the CHAMMI benchmark dataset,
    following the CHAMMI paper: https://arxiv.org/pdf/2310.19224
    Github code: https://github.com/chaudatascience/channel_adaptive_models
    """

    Split = Union[_Split]

    def __init__(
        self,
        *,
        split: "CHAMMI_CP.Split",
        root: str,
        transforms: Optional[Callable] = None,
        transform: Optional[Callable] = None,
        target_transform: Optional[Callable] = None,
        image_decoder_type: DecoderType = DecoderType.XChannelsDecoder,
        **kwargs: Any,
    ) -> None:
        super().__init__(
            root,
            transforms,
            transform,
            target_transform,
            image_decoder_type=image_decoder_type,
            **kwargs,
        )
        self.split = split
        self.root = root
        self.num_additional_labels_loo_eval = 3
        self._image_paths, self._targets = _load_file_names_and_targets(
            root,
            split,
        )

    def get_image_relpath(self, index: int) -> str:
        return self._image_paths[index]

    def get_image_data(self, index: int) -> bytes:
        image_relpath = self.get_image_relpath(index)
        image_full_path = os.path.join(self.root, image_relpath)
        with open(image_full_path, mode="rb") as f:
            image_data = f.read()
        return image_data

    def get_target(self, index: int) -> Any:
        return self._targets[index]

    def get_targets(self) -> np.ndarray:
        return np.array(self._targets)

    def __len__(self) -> int:
        return len(self._image_paths)


================================================
FILE: dinov2/data/datasets/cell_dino/chammi_hpa.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the CC-by-NC licence,
# found in the LICENSE_CELL_DINO_CODE file in the root directory of this source tree.

import csv
from enum import Enum
import logging
import os
from typing import Any, Callable, Optional, Union

import numpy as np

from ..extended import ExtendedVisionDataset
from ..decoders import DecoderType

logger = logging.getLogger("dinov2")


METADATA_FILE = "morphem70k_v2.csv"

CLASS_LABELS = {
    "golgi apparatus": 0,
    "microtubules": 1,
    "mitochondria": 2,
    "nuclear speckles": 3,
    "cytosol": 4,  # labels only seen in TASK_THREE
    "endoplasmic reticulum": 5,
    "nucleoplasm": 6,
}


class _Split(Enum):
    TRAIN = "Train"
    TASK_ONE = "Task_one"
    TASK_TWO = "Task_two"
    TASK_THREE = "Task_three"


def _load_file_names_and_targets(
    root: str,
    split: _Split,
):
    image_paths = []
    labels = []
    with open(os.path.join(root, METADATA_FILE)) as metadata:
        metadata_reader = csv.DictReader(metadata)
        for row in metadata_reader:
            row_dataset = row["file_path"].split("/")[0]
            if row["train_test_split"].upper() == split and row_dataset == "HPA":
                image_paths.append(row["file_path"])
                labels.append(CLASS_LABELS[row["label"]])

    return image_paths, labels


class CHAMMI_HPA(ExtendedVisionDataset):
    """
    Implementation of the CP (Cell-Painting) subset of the CHAMMI benchmark dataset,
    following the CHAMMI paper: https://arxiv.org/pdf/2310.19224
    Github code: https://github.com/chaudatascience/channel_adaptive_models
    """

    Split = Union[_Split]

    def __init__(
        self,
        *,
        split: "CHAMMI_HPA.Split",
        root: str,
        transforms: Optional[Callable] = None,
        transform: Optional[Callable] = None,
        target_transform: Optional[Callable] = None,
        image_decoder_type: DecoderType = DecoderType.XChannelsDecoder,
        **kwargs: Any,
    ) -> None:
        super().__init__(
            root,
            transforms,
            transform,
            target_transform,
            image_decoder_type=image_decoder_type,
            **kwargs,
        )
        self.split = split
        self.root = root
        self.num_additional_labels_loo_eval = 3

        self._image_paths, self._targets = _load_file_names_and_targets(
            root,
            split,
        )

    def get_image_relpath(self, index: int) -> str:
        return self._image_paths[index]

    def get_image_data(self, index: int) -> bytes:
        image_relpath = self.get_image_relpath(index)
        image_full_path = os.path.join(self.root, image_relpath)
        with open(image_full_path, mode="rb") as f:
            image_data = f.read()
        return image_data

    def get_target(self, index: int) -> Any:
        return self._targets[index]

    def get_targets(self) -> np.ndarray:
        return np.array(self._targets)

    def __len__(self) -> int:
        return len(self._image_paths)


================================================
FILE: dinov2/data/datasets/cell_dino/chammi_wtc.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the CC-by-NC licence,
# found in the LICENSE_CELL_DINO_CODE file in the root directory of this source tree.

import csv
from enum import Enum
import logging
import os
from typing import Any, Callable, Optional, Union

import numpy as np

from ..extended import ExtendedVisionDataset
from ..decoders import DecoderType

logger = logging.getLogger("dinov2")


METADATA_FILE = "morphem70k_v2.csv"

CLASS_LABELS = {
    "M0": 0,
    "M1M2": 1,
    "M3": 2,
    "M4M5": 3,
    "M6M7_complete": 4,
    "M6M7_single": 5,
}


class _Split(Enum):
    TRAIN = "Train"
    TASK_ONE = "Task_one"
    TASK_TWO = "Task_two"


def _load_file_names_and_targets(
    root: str,
    split: _Split,
):
    image_paths = []
    labels = []
    with open(os.path.join(root, METADATA_FILE)) as metadata:
        metadata_reader = csv.DictReader(metadata)
        for row in metadata_reader:
            row_dataset = row["file_path"].split("/")[0]
            if row["train_test_split"].upper() == split and row_dataset == "Allen":
                image_paths.append(row["file_path"])
                labels.append(CLASS_LABELS[row["label"]])

    return image_paths, labels


class CHAMMI_WTC(ExtendedVisionDataset):
    """
    Implementation of the CP (Cell-Painting) subset of the CHAMMI benchmark dataset,
    following the CHAMMI paper: https://arxiv.org/pdf/2310.19224
    Github code: https://github.com/chaudatascience/channel_adaptive_models
    """

    Split = Union[_Split]

    def __init__(
        self,
        *,
        split: "CHAMMI_WTC.Split",
        root: str,
        transforms: Optional[Callable] = None,
        transform: Optional[Callable] = None,
        target_transform: Optional[Callable] = None,
        image_decoder_type: DecoderType = DecoderType.XChannelsTIFFDecoder,
        **kwargs: Any,
    ) -> None:
        super().__init__(
            root,
            transforms,
            transform,
            target_transform,
            image_decoder_type=image_decoder_type,
            **kwargs,
        )
        self.split = split
        self.root = root

        self._image_paths, self._targets = _load_file_names_and_targets(
            root,
            split,
        )

    def get_image_relpath(self, index: int) -> str:
        return self._image_paths[index]

    def get_image_data(self, index: int) -> bytes:
        image_relpath = self.get_image_relpath(index)
        image_full_path = os.path.join(self.root, image_relpath)
        with open(image_full_path, mode="rb") as f:
            image_data = f.read()
        return image_data

    def get_target(self, index: int) -> Any:
        return self._targets[index]

    def get_targets(self) -> np.ndarray:
        return np.array(self._targets)

    def __len__(self) -> int:
        return len(self._image_paths)


================================================
FILE: dinov2/data/datasets/cell_dino/hpafov.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the CC-by-NC licence,
# found in the LICENSE_CELL_DINO_CODE file in the root directory of this source tree.

import csv
from enum import Enum
import logging
import os
from typing import Any, Callable, List, Optional, Tuple, Union, Dict

import numpy as np

from ..extended import ExtendedVisionDataset
from ..decoders import DecoderType

logger = logging.getLogger("dinov2")

CELL_TYPE = [
    "BJ",  # 1
    "LHCN-M2",
    "RH-30",
    "SH-SY5Y",
    "U-2 OS",  # 5
    "ASC TERT1",
    "HaCaT",
    "A-431",
    "U-251 MG",
    "HEK 293",  # 10
    "A549",
    "RT4",
    "HeLa",
    "MCF7",
    "PC-3",  # 15
    "hTERT-RPE1",
    "SK-MEL-30",
    "EFO-21",
    "AF22",
    "HEL",  # 20
    "Hep G2",
    "HUVEC TERT2",
    "THP-1",
    "CACO-2",
    "JURKAT",  # 25
    "RPTEC TERT1",
    "SuSa",
    "REH",
    "HDLM-2",
    "K-562",  # 30
    "hTCEpi",
    "NB-4",
    "HAP1",
    "OE19",
    "SiHa",  # 35
]

PROTEIN_LOCALIZATION = [  # matches https://www.kaggle.com/c/human-protein-atlas-image-classification/data
    "nucleoplasm",
    "nuclear membrane",
    "nucleoli",
    "nucleoli fibrillar center",
    "nuclear speckles",  # 5
    "nuclear bodies",
    "endoplasmic reticulum",
    "golgi apparatus",
    "peroxisomes",
    "endosomes",  # 10
    "lysosomes",
    "intermediate filaments",
    "actin filaments",
    "focal adhesion sites",
    "microtubules",  # 15
    "microtubule ends",
    "cytokinetic bridge",
    "mitotic spindle",
    "microtubule organizing center",
    "centrosome",  # 20
    "lipid droplets",
    "plasma membrane",
    "cell junctions",
    "mitochondria",
    "aggresome",  # 25
    "cytosol",
    "cytoplasmic bodies",
    "rods & rings",
]


class _Split(Enum):
    TRAIN = "train"
    VAL = "val"
    SSL = "ssl"


def get_csv_fpath(split):
    """
    Path to data relative to root
    """
    if split == _Split.TRAIN.value.upper() or split == _Split.TRAIN or split == "TRAIN":
        return "whole_images_512_train.csv"
    elif split == _Split.VAL.value.upper() or split == _Split.VAL or split == "VAL":
        return "whole_images_512_test.csv"


class _WildCard(Enum):
    NONE = "none"
    SEPARATECHANNELS = "separate_channels"  # each channel from each image is treated as an independent sample, overrides chosen channel configuration


class _Mode(Enum):
    """
    Targets:
    - ALL: tuple, (one hot encoding of multilabel protein localization, categorical encoding of cell type)
    - PROTEIN_LOCALIZATION: one hot encoding of multilabel protein localization
    - CELL_TYPE: categorical encoding of cell type
    """

    ALL = "all"
    PROTEIN_LOCALIZATION = "protein_localization"
    CELL_TYPE = "cell_type"

    @property
    def nb_labels(self):
        if self == _Mode.CELL_TYPE:
            return len(CELL_TYPE)
        elif self == _Mode.PROTEIN_LOCALIZATION:
            return len(PROTEIN_LOCALIZATION)
        else:
            return None


def _list_images_from_csv(img_path, csv_path):
    L = []
    with open(csv_path) as filename:
        reader = csv.DictReader(filename)
        for row in reader:
            L.append(os.path.join(img_path, row["ID"] + ".png"))
    return L


def _load_file_names_and_labels_ssl(
    root: str,
) -> Tuple[List[str], List[Any]]:

    curr_img_path = os.path.join(root, "normalized_data")
    csv_train_ssl = os.path.join(root, "whole_images_names.csv")
    image_paths = _list_images_from_csv(curr_img_path, csv_train_ssl)
    labels = [i for i in range(len(image_paths))]
    return image_paths, labels


def _load_file_names_and_labels(
    root: str,
    split: _Split,
    mode: _Mode,
) -> Tuple[List[str], List[Any], np.ndarray]:

    data_path = os.path.join(root, "512_whole_images")
    csv_fpath = os.path.join(root, get_csv_fpath(split))

    image_paths = []
    labels = []

    with open(csv_fpath) as filename:
        reader = csv.DictReader(filename)
        for row in reader:

            add_sample = True
            if mode != _Mode.PROTEIN_LOCALIZATION.value.upper():
                # categorical
                if row["cell_type"] in CELL_TYPE:
                    cell_type = CELL_TYPE.index(row["cell_type"])
                else:
                    cell_type = np.nan

            if mode != _Mode.CELL_TYPE.value.upper():
                # one hot encoding
                prot_loc = np.zeros(len(PROTEIN_LOCALIZATION), dtype=np.int_)
                for k in range(len(PROTEIN_LOCALIZATION)):
                    if row[PROTEIN_LOCALIZATION[k]] == "True":
                        prot_loc[k] = 1
                if prot_loc.max() < 0.5:
                    add_sample = False

            if add_sample:
                if mode == _Mode.PROTEIN_LOCALIZATION.value.upper():
                    labels.append(prot_loc)
                elif mode == _Mode.CELL_TYPE.value.upper():
                    labels.append(cell_type)
                else:
                    labels.append({"prot_loc": prot_loc, "cell_type": cell_type})

                candidate_path = os.path.join(data_path, row["file"].split("/")[-1])
                if os.path.exists(candidate_path):
                    image_paths.append(candidate_path)
                else:
                    candidate_path = os.path.join(
                        data_path, row["file"].split("/")[-1].split(".")[0] + ".tiff"
                    )  # _blue.png") # some images on the normalized_data folder have a _blue suffix on their names
                    if os.path.exists(candidate_path):
                        image_paths.append(candidate_path)
                    else:
                        raise FileNotFoundError(f"File {candidate_path} not found.")

        return image_paths, labels


class HPAFoV(ExtendedVisionDataset):
    Split = Union[_Split]
    Mode = Union[_Mode]
    WildCard = Union[_WildCard]

    def __init__(
        self,
        *,
        split: "HPAFoV.Split" = _Split.TRAIN,
        mode: "HPAFoV.Mode" = _Mode.ALL,
        wildcard: "HPAFoV.WildCard" = _WildCard.NONE,
        root: str,
        transforms: Optional[Callable] = None,
        transform: Optional[Callable] = None,
        target_transform: Optional[Callable] = None,
        image_decoder_type: DecoderType = DecoderType.ChannelSelectDecoder,
        image_decoder_params: Dict[str, Any] = {},
        **kwargs: Any,
    ) -> None:
        super().__init__(
            root,
            transforms,
            transform,
            target_transform,
            image_decoder_type=image_decoder_type,
            image_decoder_params={
                "select_channel": True
                if wildcard == _WildCard.SEPARATECHANNELS or wildcard == "SEPARATE_CHANNELS"
                else False
            },
            **kwargs,
        )
        self.mode = mode
        self.split = split
        self.root = root
        self.wildcard = wildcard
        self.channel_adaptive = True
        if split == _Split.SSL.value.upper() or split == _Split.SSL or split == "SSL":
            self._image_paths, self._labels = _load_file_names_and_labels_ssl(root)
        else:
            self._image_paths, self._labels = _load_file_names_and_labels(root, self.split, self.mode)

        self._channels = np.repeat(np.array([[0, 1, 2, 3]]), len(self._image_paths), axis=0).tolist()

        if self.wildcard == _WildCard.SEPARATECHANNELS.value.upper():
            image_paths, labels, channels = self._image_paths, self._labels, self._channels
            channels = np.array(channels)
            # separate and stack the columns of the channels array
            C = channels.shape[1]
            channels = np.concatenate([channels[:, i] for i in range(C)])
            self._channels = np.expand_dims(channels, 1).tolist()
            self.image_paths = image_paths * C
            self.labels = labels * C

    def get_image_relpath(self, index: int) -> str:
        return self._image_paths[index]

    def get_image_data(self, index: int) -> bytes:
        image_relpath = self.get_image_relpath(index)
        image_full_path = os.path.join(self.root, image_relpath)
        with open(image_full_path, mode="rb") as f:
            image_data = f.read()
        if self.channel_adaptive:
            channels = self._channels[index]
            return image_data + bytes(channels) + (len(channels)).to_bytes(1, byteorder="big")
        else:
            return image_data

    def get_target(self, index: int) -> Any:
        return self._labels[index]

    def get_targets(self) -> np.ndarray:
        return np.array(self._labels)

    def __len__(self) -> int:
        return len(self._image_paths)


================================================
FILE: dinov2/data/datasets/cell_dino/hpaone.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the CC-by-NC licence,
# found in the LICENSE_CELL_DINO_CODE file in the root directory of this source tree.

import csv
from enum import Enum
import logging
import os
from typing import Any, Callable, List, Optional, Tuple, Union

import numpy as np

from ..extended import ExtendedVisionDataset
from ..decoders import DecoderType

logger = logging.getLogger("dinov2")

PROTEIN_LOCALIZATION = [
    "actin filaments,focal adhesion sites",
    "aggresome",
    "centrosome,centriolar satellite",
    "cytosol",
    "endoplasmic reticulum",
    "golgi apparatus",
    "intermediate filaments",
    "microtubules",
    "mitochondria",
    "mitotic spindle",
    "no staining",
    "nuclear bodies",
    "nuclear membrane",
    "nuclear speckles",
    "nucleoli",
    "nucleoli fibrillar center",
    "nucleoplasm",
    "plasma membrane,cell junctions",
    "vesicles,peroxisomes,endosomes,lysosomes,lipid droplets,cytoplasmic bodies",
]  # 19


CELL_TYPE = [
    "A-431",  # 0
    "A549",
    "AF22",
    "ASC TERT1",
    "BJ",
    "CACO-2",
    "EFO-21",
    "HAP1",
    "HDLM-2",
    "HEK 293",  # 9
    "HEL",
    "HUVEC TERT2",
    "HaCaT",
    "HeLa",
    "Hep G2",
    "JURKAT",
    "K-562",
    "MCF7",
    "PC-3",
    "REH",
    "RH-30",  # 20
    "RPTEC TERT1",
    "RT4",
    "SH-SY5Y",
    "SK-MEL-30",
    "SiHa",
    "U-2 OS",
    "U-251 MG",
    "hTCEpi",  # 28
]  # 29 cell types


class _Split(Enum):
    VAL = "val"
    TRAIN = "train"
    ALL = "all"  # images without labels, for encoder training


class _Mode(Enum):
    PROTEIN_LOCALIZATION = "protein_localization"
    CELL_TYPE = "cell_type"

    @property
    def num_labels(self):
        if self == _Mode.CELL_TYPE.value.upper():
            return len(CELL_TYPE)
        return len(PROTEIN_LOCALIZATION)


def _simple_parse_csv(img_rootdir, csv_filepath: str):
    samples = []
    with open(csv_filepath) as filename:
        template = csv.DictReader(filename)
        samples = [(os.path.join(img_rootdir, row["img_path"]), 0) for row in template]
    return samples


def _parse_csv(img_rootdir, csv_labels_path: str):
    nb_protein_location = len(PROTEIN_LOCALIZATION)
    nb_cell_type = len(CELL_TYPE)
    samples = []
    with open(csv_labels_path) as filename:
        reader = csv.DictReader(filename)
        for row in reader:
            protein_location = np.zeros(nb_protein_location, dtype=np.int_)
            for k in range(nb_protein_location):
                if row[PROTEIN_LOCALIZATION[k]] == "True":
                    protein_location[k] = 1

            cell_type = 0
            for k in range(nb_cell_type):
                if row[CELL_TYPE[k]] == "True":
                    cell_type = k

            samples.append(
                (
                    img_rootdir + "/" + row["file"].rsplit("/", 1)[1],
                    protein_location,
                    cell_type,
                )
            )
    return samples


def _load_file_names_and_labels_ssl(
    root: str,
) -> Tuple[List[str], List[Any]]:
    curr_dir_train = os.path.join(root, "varied_size_masked_single_cells_HPA")
    csv_all_path = os.path.join(root, "varied_size_masked_single_cells_pretrain_20240507.csv")
    samples = _simple_parse_csv(curr_dir_train, csv_all_path)
    image_paths, fake_labels = zip(*samples)
    lab = list(fake_labels)
    return image_paths, lab


def _load_file_names_and_labels_train_or_test(
    root: str,
    split: _Split,
    mode: _Mode,
) -> Tuple[List[str], List[Any]]:

    if split == _Split.TRAIN.value.upper() or split == _Split.TRAIN:
        csv_labels_path = os.path.join(root, "fixed_size_masked_single_cells_pretrain_20240507.csv")
    elif split == _Split.VAL.value.upper() or split == _Split.VAL:
        csv_labels_path = os.path.join(root, "fixed_size_masked_single_cells_evaluation_20240507.csv")
    else:
        print("wrong split name")
    curr_dir_val = os.path.join(root, "fixed_size_masked_single_cells_HPA")

    samples = _parse_csv(curr_dir_val, csv_labels_path)
    image_paths, protein_location, cell_type = zip(*samples)
    if mode == _Mode.PROTEIN_LOCALIZATION.value.upper():
        lab = protein_location
    elif mode == _Mode.CELL_TYPE.value.upper():
        lab = cell_type
    else:
        lab = protein_location, cell_type
    image_paths = list(image_paths)
    return image_paths, lab


class HPAone(ExtendedVisionDataset):
    Split = Union[_Split]
    Mode = Union[_Mode]

    def __init__(
        self,
        *,
        split: "HPAone.Split" = _Split.ALL,
        mode: "HPAone.Mode" = None,
        root: str,
        transforms: Optional[Callable] = None,
        transform: Optional[Callable] = None,
        target_transform: Optional[Callable] = None,
        image_decoder_type: DecoderType = DecoderType.XChannelsDecoder,
        **kwargs: Any,
    ) -> None:
        super().__init__(
            root,
            transforms,
            transform,
            target_transform,
            image_decoder_type=image_decoder_type,
            **kwargs,
        )
        self.mode = mode
        self.split = split
        self.root = root

        if (
            split in {_Split.TRAIN.value.upper(), _Split.VAL.value.upper()}
            or split == _Split.TRAIN
            or split == _Split.VAL
        ):
            (
                self._image_paths,
                self._labels,
            ) = _load_file_names_and_labels_train_or_test(root, split, mode)
        elif split == _Split.ALL.value.upper() or split == _Split.ALL:
            self._image_paths, self._labels = _load_file_names_and_labels_ssl(root)
        else:
            logger.info(f"unknown split: {split}, {_Split.ALL.value.upper()}")

    def get_image_relpath(self, index: int) -> str:
        return self._image_paths[index]

    def get_image_data(self, index: int) -> bytes:
        image_relpath = self.get_image_relpath(index)
        image_full_path = os.path.join(self.root, image_relpath)
        with open(image_full_path, mode="rb") as f:
            image_data = f.read()
        return image_data

    def get_target(self, index: int) -> Any:
        return self._labels[index]

    def get_targets(self) -> np.ndarray:
        return np.array(self._labels)

    def __len__(self) -> int:
        return len(self._image_paths)


================================================
FILE: dinov2/data/datasets/decoders.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

from io import BytesIO
from typing import Any, Type

from PIL import Image
import numpy as np
import torch
from enum import Enum

try:
    import tifffile
except ImportError:
    print("Could not import `tifffile`, TIFFImageDataDecoder will be disabled")


class Decoder:
    def decode(self) -> Any:
        raise NotImplementedError


class DecoderType(Enum):
    ImageDataDecoder = "ImageDataDecoder"
    XChannelsDecoder = "XChannelsDecoder"
    XChannelsTIFFDecoder = "XChannelsTIFFDecoder"
    ChannelSelectDecoder = "ChannelSelectDecoder"

    def get_class(self) -> Type[Decoder]:  # noqa: C901
        if self == DecoderType.ImageDataDecoder:
            return ImageDataDecoder
        if self == DecoderType.XChannelsDecoder:
            return XChannelsDecoder
        if self == DecoderType.XChannelsTIFFDecoder:
            return XChannelsTIFFDecoder
        if self == DecoderType.ChannelSelectDecoder:
            return ChannelSelectDecoder


class ImageDataDecoder(Decoder):
    def __init__(self, image_data: bytes) -> None:
        self._image_data = image_data

    def decode(self) -> Image:
        f = BytesIO(self._image_data)
        return Image.open(f).convert(mode="RGB")


class TargetDecoder(Decoder):
    def __init__(self, target: Any):
        self._target = target

    def decode(self) -> Any:
        return self._target


class XChannelsDecoder(Decoder):
    def __init__(self, image_data: bytes) -> None:
        self._image_data = image_data

    def decode(self):
        im = np.asarray(Image.open(BytesIO(self._image_data)))
        if len(im.shape) == 2:
            im = np.reshape(im, (im.shape[0], im.shape[0], -1), order="F")
        return torch.Tensor(im).permute(2, 0, 1)


class XChannelsTIFFDecoder(Decoder):
    def __init__(self, image_data: bytes, num_channels: int = 3) -> None:
        self._image_data = image_data
        self._num_channels = num_channels

    def decode(self):
        numpy_array = tifffile.imread(BytesIO(self._image_data))
        numpy_array = np.reshape(numpy_array, (numpy_array.shape[0], -1, self._num_channels), order="F")
        return torch.Tensor(numpy_array).permute(2, 0, 1)


class ChannelSelectDecoder(Decoder):
    def __init__(self, image_data: bytes, select_channel: bool = False) -> None:
        self.select_channel = select_channel
        if select_channel:
            self._image_data = image_data[:-1]
            self._channel = image_data[-1]
        else:
            self._image_data = image_data

    def decode(self):
        im = np.asarray(Image.open(BytesIO(self._image_data)))
        if self.select_channel:
            return torch.Tensor(im).permute(2, 0, 1)[[self._channel]]
        return torch.Tensor(im).permute(2, 0, 1)


================================================
FILE: dinov2/data/datasets/extended.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

from typing import Any, Tuple

from torchvision.datasets import VisionDataset

from .decoders import DecoderType, TargetDecoder


class ExtendedVisionDataset(VisionDataset):
    def __init__(self, *args, **kwargs) -> None:
        image_decoder_type = kwargs.pop("image_decoder_type", DecoderType.ImageDataDecoder)
        self._decoder_params = {}
        self._image_decoder_class = image_decoder_type.get_class()
        if "image_decoder_params" in kwargs:
            self._decoder_params = kwargs.pop("image_decoder_params")

        super().__init__(*args, **kwargs)  # type: ignore

    def get_image_data(self, index: int) -> bytes:
        raise NotImplementedError

    def get_target(self, index: int) -> Any:
        raise NotImplementedError

    def __getitem__(self, index: int) -> Tuple[Any, Any]:
        try:
            image_data = self.get_image_data(index)
            image = self._image_decoder_class(image_data, **self._decoder_params).decode()
        except Exception as e:
            raise RuntimeError(f"can not read image for sample {index}") from e
        target = self.get_target(index)
        target = TargetDecoder(target).decode()

        if self.transforms is not None:
            image, target = self.transforms(image, target)

        return image, target

    def __len__(self) -> int:
        raise NotImplementedError


================================================
FILE: dinov2/data/datasets/image_net.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

import csv
from enum import Enum
import logging
import os
from typing import Callable, List, Optional, Tuple, Union

import numpy as np

from .extended import ExtendedVisionDataset


logger = logging.getLogger("dinov2")
_Target = int


class _Split(Enum):
    TRAIN = "train"
    VAL = "val"
    TEST = "test"  # NOTE: torchvision does not support the test split

    @property
    def length(self) -> int:
        split_lengths = {
            _Split.TRAIN: 1_281_167,
            _Split.VAL: 50_000,
            _Split.TEST: 100_000,
        }
        return split_lengths[self]

    def get_dirname(self, class_id: Optional[str] = None) -> str:
        return self.value if class_id is None else os.path.join(self.value, class_id)

    def get_image_relpath(self, actual_index: int, class_id: Optional[str] = None) -> str:
        dirname = self.get_dirname(class_id)
        if self == _Split.TRAIN:
            basename = f"{class_id}_{actual_index}"
        else:  # self in (_Split.VAL, _Split.TEST):
            basename = f"ILSVRC2012_{self.value}_{actual_index:08d}"
        return os.path.join(dirname, basename + ".JPEG")

    def parse_image_relpath(self, image_relpath: str) -> Tuple[str, int]:
        assert self != _Split.TEST
        dirname, filename = os.path.split(image_relpath)
        class_id = os.path.split(dirname)[-1]
        basename, _ = os.path.splitext(filename)
        actual_index = int(basename.split("_")[-1])
        return class_id, actual_index


class ImageNet(ExtendedVisionDataset):
    Target = Union[_Target]
    Split = Union[_Split]

    def __init__(
        self,
        *,
        split: "ImageNet.Split",
        root: str,
        extra: str,
        transforms: Optional[Callable] = None,
        transform: Optional[Callable] = None,
        target_transform: Optional[Callable] = None,
    ) -> None:
        super().__init__(root, transforms, transform, target_transform)
        self._extra_root = extra
        self._split = split

        self._entries = None
        self._class_ids = None
        self._class_names = None

    @property
    def split(self) -> "ImageNet.Split":
        return self._split

    def _get_extra_full_path(self, extra_path: str) -> str:
        return os.path.join(self._extra_root, extra_path)

    def _load_extra(self, extra_path: str) -> np.ndarray:
        extra_full_path = self._get_extra_full_path(extra_path)
        return np.load(extra_full_path, mmap_mode="r")

    def _save_extra(self, extra_array: np.ndarray, extra_path: str) -> None:
        extra_full_path = self._get_extra_full_path(extra_path)
        os.makedirs(self._extra_root, exist_ok=True)
        np.save(extra_full_path, extra_array)

    @property
    def _entries_path(self) -> str:
        return f"entries-{self._split.value.upper()}.npy"

    @property
    def _class_ids_path(self) -> str:
        return f"class-ids-{self._split.value.upper()}.npy"

    @property
    def _class_names_path(self) -> str:
        return f"class-names-{self._split.value.upper()}.npy"

    def _get_entries(self) -> np.ndarray:
        if self._entries is None:
            self._entries = self._load_extra(self._entries_path)
        assert self._entries is not None
        return self._entries

    def _get_class_ids(self) -> np.ndarray:
        if self._split == _Split.TEST:
            assert False, "Class IDs are not available in TEST split"
        if self._class_ids is None:
            self._class_ids = self._load_extra(self._class_ids_path)
        assert self._class_ids is not None
        return self._class_ids

    def _get_class_names(self) -> np.ndarray:
        if self._split == _Split.TEST:
            assert False, "Class names are not available in TEST split"
        if self._class_names is None:
            self._class_names = self._load_extra(self._class_names_path)
        assert self._class_names is not None
        return self._class_names

    def find_class_id(self, class_index: int) -> str:
        class_ids = self._get_class_ids()
        return str(class_ids[class_index])

    def find_class_name(self, class_index: int) -> str:
        class_names = self._get_class_names()
        return str(class_names[class_index])

    def get_image_data(self, index: int) -> bytes:
        entries = self._get_entries()
        actual_index = entries[index]["actual_index"]

        class_id = self.get_class_id(index)

        image_relpath = self.split.get_image_relpath(actual_index, class_id)
        image_full_path = os.path.join(self.root, image_relpath)
        with open(image_full_path, mode="rb") as f:
            image_data = f.read()
        return image_data

    def get_target(self, index: int) -> Optional[Target]:
        entries = self._get_entries()
        class_index = entries[index]["class_index"]
        return None if self.split == _Split.TEST else int(class_index)

    def get_targets(self) -> Optional[np.ndarray]:
        entries = self._get_entries()
        return None if self.split == _Split.TEST else entries["class_index"]

    def get_class_id(self, index: int) -> Optional[str]:
        entries = self._get_entries()
        class_id = entries[index]["class_id"]
        return None if self.split == _Split.TEST else str(class_id)

    def get_class_name(self, index: int) -> Optional[str]:
        entries = self._get_entries()
        class_name = entries[index]["class_name"]
        return None if self.split == _Split.TEST else str(class_name)

    def __len__(self) -> int:
        entries = self._get_entries()
        assert len(entries) == self.split.length
        return len(entries)

    def _load_labels(self, labels_path: str) -> List[Tuple[str, str]]:
        labels_full_path = os.path.join(self.root, labels_path)
        labels = []

        try:
            with open(labels_full_path, "r") as f:
                reader = csv.reader(f)
                for row in reader:
                    class_id, class_name = row
                    labels.append((class_id, class_name))
        except OSError as e:
            raise RuntimeError(f'can not read labels file "{labels_full_path}"') from e

        return labels

    def _dump_entries(self) -> None:
        split = self.split
        if split == ImageNet.Split.TEST:
            dataset = None
            sample_count = split.length
            max_class_id_length, max_class_name_length = 0, 0
        else:
            labels_path = "labels.txt"
            logger.info(f'loading labels from "{labels_path}"')
            labels = self._load_labels(labels_path)

            # NOTE: Using torchvision ImageFolder for consistency
            from torchvision.datasets import ImageFolder

            dataset_root = os.path.join(self.root, split.get_dirname())
            dataset = ImageFolder(dataset_root)
            sample_count = len(dataset)
            max_class_id_length, max_class_name_length = -1, -1
            for sample in dataset.samples:
                _, class_index = sample
                class_id, class_name = labels[class_index]
                max_class_id_length = max(len(class_id), max_class_id_length)
                max_class_name_length = max(len(class_name), max_class_name_length)

        dtype = np.dtype(
            [
                ("actual_index", "<u4"),
                ("class_index", "<u4"),
                ("class_id", f"U{max_class_id_length}"),
                ("class_name", f"U{max_class_name_length}"),
            ]
        )
        entries_array = np.empty(sample_count, dtype=dtype)

        if split == ImageNet.Split.TEST:
            old_percent = -1
            for index in range(sample_count):
                percent = 100 * (index + 1) // sample_count
                if percent > old_percent:
                    logger.info(f"creating entries: {percent}%")
                    old_percent = percent

                actual_index = index + 1
                class_index = np.uint32(-1)
                class_id, class_name = "", ""
                entries_array[index] = (actual_index, class_index, class_id, class_name)
        else:
            class_names = {class_id: class_name for class_id, class_name in labels}

            assert dataset
            old_percent = -1
            for index in range(sample_count):
                percent = 100 * (index + 1) // sample_count
                if percent > old_percent:
                    logger.info(f"creating entries: {percent}%")
                    old_percent = percent

                image_full_path, class_index = dataset.samples[index]
                image_relpath = os.path.relpath(image_full_path, self.root)
                class_id, actual_index = split.parse_image_relpath(image_relpath)
                class_name = class_names[class_id]
                entries_array[index] = (actual_index, class_index, class_id, class_name)

        logger.info(f'saving entries to "{self._entries_path}"')
        self._save_extra(entries_array, self._entries_path)

    def _dump_class_ids_and_names(self) -> None:
        split = self.split
        if split == ImageNet.Split.TEST:
            return

        entries_array = self._load_extra(self._entries_path)

        max_class_id_length, max_class_name_length, max_class_index = -1, -1, -1
        for entry in entries_array:
            class_index, class_id, class_name = (
                entry["class_index"],
                entry["class_id"],
                entry["class_name"],
            )
            max_class_index = max(int(class_index), max_class_index)
            max_class_id_length = max(len(str(class_id)), max_class_id_length)
            max_class_name_length = max(len(str(class_name)), max_class_name_length)

        class_count = max_class_index + 1
        class_ids_array = np.empty(class_count, dtype=f"U{max_class_id_length}")
        class_names_array = np.empty(class_count, dtype=f"U{max_class_name_length}")
        for entry in entries_array:
            class_index, class_id, class_name = (
                entry["class_index"],
                entry["class_id"],
                entry["class_name"],
            )
            class_ids_array[class_index] = class_id
            class_names_array[class_index] = class_name

        logger.info(f'saving class IDs to "{self._class_ids_path}"')
        self._save_extra(class_ids_array, self._class_ids_path)

        logger.info(f'saving class names to "{self._class_names_path}"')
        self._save_extra(class_names_array, self._class_names_path)

    def dump_extra(self) -> None:
        self._dump_entries()
        self._dump_class_ids_and_names()


================================================
FILE: dinov2/data/datasets/image_net_22k.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

from dataclasses import dataclass
from enum import Enum
from functools import lru_cache
from gzip import GzipFile
from io import BytesIO
from mmap import ACCESS_READ, mmap
import os
from typing import Any, Callable, List, Optional, Set, Tuple
import warnings

import numpy as np

from .extended import ExtendedVisionDataset


_Labels = int

_DEFAULT_MMAP_CACHE_SIZE = 16  # Warning: This can exhaust file descriptors


@dataclass
class _ClassEntry:
    block_offset: int
    maybe_filename: Optional[str] = None


@dataclass
class _Entry:
    class_index: int  # noqa: E701
    start_offset: int
    end_offset: int
    filename: str


class _Split(Enum):
    TRAIN = "train"
    VAL = "val"

    @property
    def length(self) -> int:
        return {
            _Split.TRAIN: 11_797_647,
            _Split.VAL: 561_050,
        }[self]

    def entries_path(self):
        return f"imagenet21kp_{self.value}.txt"


def _get_tarball_path(class_id: str) -> str:
    return f"{class_id}.tar"


def _make_mmap_tarball(tarballs_root: str, mmap_cache_size: int):
    @lru_cache(maxsize=mmap_cache_size)
    def _mmap_tarball(class_id: str) -> mmap:
        tarball_path = _get_tarball_path(class_id)
        tarball_full_path = os.path.join(tarballs_root, tarball_path)
        with open(tarball_full_path) as f:
            return mmap(fileno=f.fileno(), length=0, access=ACCESS_READ)

    return _mmap_tarball


class ImageNet22k(ExtendedVisionDataset):
    _GZIPPED_INDICES: Set[int] = {
        841_545,
        1_304_131,
        2_437_921,
        2_672_079,
        2_795_676,
        2_969_786,
        6_902_965,
        6_903_550,
        6_903_628,
        7_432_557,
        7_432_589,
        7_813_809,
        8_329_633,
        10_296_990,
        10_417_652,
        10_492_265,
        10_598_078,
        10_782_398,
        10_902_612,
        11_203_736,
        11_342_890,
        11_397_596,
        11_589_762,
        11_705_103,
        12_936_875,
        13_289_782,
    }
    Labels = _Labels

    def __init__(
        self,
        *,
        root: str,
        extra: str,
        transforms: Optional[Callable] = None,
        transform: Optional[Callable] = None,
        target_transform: Optional[Callable] = None,
        mmap_cache_size: int = _DEFAULT_MMAP_CACHE_SIZE,
    ) -> None:
        super().__init__(root, transforms, transform, target_transform)
        self._extra_root = extra

        entries_path = self._get_entries_path(root)
        self._entries = self._load_extra(entries_path)

        class_ids_path = self._get_class_ids_path(root)
        self._class_ids = self._load_extra(class_ids_path)

        self._gzipped_indices = ImageNet22k._GZIPPED_INDICES
        self._mmap_tarball = _make_mmap_tarball(self._tarballs_root, mmap_cache_size)

    def _get_entries_path(self, root: Optional[str] = None) -> str:
        return "entries.npy"

    def _get_class_ids_path(self, root: Optional[str] = None) -> str:
        return "class-ids.npy"

    def _find_class_ids(self, path: str) -> List[str]:
        class_ids = []

        with os.scandir(path) as entries:
            for entry in entries:
                root, ext = os.path.splitext(entry.name)
                if ext != ".tar":
                    continue
                class_ids.append(root)

        return sorted(class_ids)

    def _load_entries_class_ids(self, root: Optional[str] = None) -> Tuple[List[_Entry], List[str]]:
        root = self.get_root(root)
        entries: List[_Entry] = []
        class_ids = self._find_class_ids(root)

        for class_index, class_id in enumerate(class_ids):
            path = os.path.join(root, "blocks", f"{class_id}.log")
            class_entries = []

            try:
                with open(path) as f:
                    for line in f:
                        line = line.rstrip()
                        block, filename = line.split(":")
                        block_offset = int(block[6:])
                        filename = filename[1:]

                        maybe_filename = None
                        if filename != "** Block of NULs **":
                            maybe_filename = filename
                            _, ext = os.path.splitext(filename)
                            # assert ext == ".JPEG"

                        class_entry = _ClassEntry(block_offset, maybe_filename)
                        class_entries.append(class_entry)
            except OSError as e:
                raise RuntimeError(f'can not read blocks file "{path}"') from e

            assert class_entries[-1].maybe_filename is None

            for class_entry1, class_entry2 in zip(class_entries, class_entries[1:]):
                assert class_entry1.block_offset <= class_entry2.block_offset
                start_offset = 512 * class_entry1.block_offset
                end_offset = 512 * class_entry2.block_offset
                assert class_entry1.maybe_filename is not None
                filename = class_entry1.maybe_filename
                entry = _Entry(class_index, start_offset, end_offset, filename)
                # Skip invalid image files (PIL throws UnidentifiedImageError)
                if filename == "n06470073_47249.JPEG":
                    continue
                entries.append(entry)

        return entries, class_ids

    def _load_extra(self, extra_path: str) -> np.ndarray:
        extra_root = self._extra_root
        extra_full_path = os.path.join(extra_root, extra_path)
        return np.load(extra_full_path, mmap_mode="r")

    def _save_extra(self, extra_array: np.ndarray, extra_path: str) -> None:
        extra_root = self._extra_root
        extra_full_path = os.path.join(extra_root, extra_path)
        os.makedirs(extra_root, exist_ok=True)
        np.save(extra_full_path, extra_array)

    @property
    def _tarballs_root(self) -> str:
        return self.root

    def find_class_id(self, class_index: int) -> str:
        return str(self._class_ids[class_index])

    def get_image_data(self, index: int) -> bytes:
        entry = self._entries[index]
        class_id = entry["class_id"]
        class_mmap = self._mmap_tarball(class_id)

        start_offset, end_offset = entry["start_offset"], entry["end_offset"]
        try:
            mapped_data = class_mmap[start_offset:end_offset]
            data = mapped_data[512:]  # Skip entry header block

            if len(data) >= 2 and tuple(data[:2]) == (0x1F, 0x8B):
                assert index in self._gzipped_indices, f"unexpected gzip header for sample {index}"
                with GzipFile(fileobj=BytesIO(data)) as g:
                    data = g.read()
        except Exception as e:
            raise RuntimeError(f"can not retrieve image data for sample {index} " f'from "{class_id}" tarball') from e

        return data

    def get_target(self, index: int) -> Any:
        return int(self._entries[index]["class_index"])

    def get_targets(self) -> np.ndarray:
        return self._entries["class_index"]

    def get_class_id(self, index: int) -> str:
        return str(self._entries[index]["class_id"])

    def get_class_ids(self) -> np.ndarray:
        return self._entries["class_id"]

    def __getitem__(self, index: int) -> Tuple[Any, Any]:
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            return super().__getitem__(index)

    def __len__(self) -> int:
        return len(self._entries)

    def _dump_entries(self, *args, **kwargs) -> None:
        entries, class_ids = self._load_entries_class_ids(*args, **kwargs)

        max_class_id_length, max_filename_length, max_class_index = -1, -1, -1
        for entry in entries:
            class_id = class_ids[entry.class_index]
            max_class_index = max(entry.class_index, max_class_index)
            max_class_id_length = max(len(class_id), max_class_id_length)
            max_filename_length = max(len(entry.filename), max_filename_length)

        dtype = np.dtype(
            [
                ("class_index", "<u4"),
                ("class_id", f"U{max_class_id_length}"),
                ("start_offset", "<u4"),
                ("end_offset", "<u4"),
                ("filename", f"U{max_filename_length}"),
            ]
        )
        sample_count = len(entries)
        entries_array = np.empty(sample_count, dtype=dtype)
        for i, entry in enumerate(entries):
            class_index = entry.class_index
            class_id = class_ids[class_index]
            start_offset = entry.start_offset
            end_offset = entry.end_offset
            filename = entry.filename
            entries_array[i] = (
                class_index,
                class_id,
                start_offset,
                end_offset,
                filename,
            )

        entries_path = self._get_entries_path(*args, **kwargs)
        self._save_extra(entries_array, entries_path)

    def _dump_class_ids(self, *args, **kwargs) -> None:
        entries_path = self._get_entries_path(*args, **kwargs)
        entries_array = self._load_extra(entries_path)

        max_class_id_length, max_class_index = -1, -1
        for entry in entries_array:
            class_index, class_id = entry["class_index"], entry["class_id"]
            max_class_index = max(int(class_index), max_class_index)
            max_class_id_length = max(len(str(class_id)), max_class_id_length)

        class_ids_array = np.empty(max_class_index + 1, dtype=f"U{max_class_id_length}")
        for entry in entries_array:
            class_index, class_id = entry["class_index"], entry["class_id"]
            class_ids_array[class_index] = class_id
        class_ids_path = self._get_class_ids_path(*args, **kwargs)
        self._save_extra(class_ids_array, class_ids_path)

    def _dump_extra(self, *args, **kwargs) -> None:
        self._dump_entries(*args, *kwargs)
        self._dump_class_ids(*args, *kwargs)

    def dump_extra(self, root: Optional[str] = None) -> None:
        return self._dump_extra(root)


================================================
FILE: dinov2/data/loaders.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

import logging
from enum import Enum
from typing import Any, Callable, List, Optional, TypeVar

import torch
from torch.utils.data import Sampler

from .datasets import ImageNet, ImageNet22k, HPAone, HPAFoV, CHAMMI_CP, CHAMMI_HPA, CHAMMI_WTC
from .samplers import EpochSampler, InfiniteSampler, ShardedInfiniteSampler


logger = logging.getLogger("dinov2")


class SamplerType(Enum):
    DISTRIBUTED = 0
    EPOCH = 1
    INFINITE = 2
    SHARDED_INFINITE = 3
    SHARDED_INFINITE_NEW = 4


def _make_bool_str(b: bool) -> str:
    return "yes" if b else "no"


def _make_sample_transform(image_transform: Optional[Callable] = None, target_transform: Optional[Callable] = None):
    def transform(sample):
        image, target = sample
        if image_transform is not None:
            image = image_transform(image)
        if target_transform is not None:
            target = target_transform(target)
        return image, target

    return transform


def _parse_dataset_str(dataset_str: str):
    tokens = dataset_str.split(":")

    name = tokens[0]
    kwargs = {}

    for token in tokens[1:]:
        key, value = token.split("=")
        assert key in ("root", "extra", "split", "mode", "wildcard")
        kwargs[key] = value

    if name == "ImageNet":
        class_ = ImageNet
        if "split" in kwargs:
            kwargs["split"] = ImageNet.Split[kwargs["split"]]
    elif name == "ImageNet22k":
        class_ = ImageNet22k
    elif name == "HPAone":
        class_ = HPAone
    elif name == "HPAFoV":
        class_ = HPAFoV
    elif name == "CHAMMI_CP":
        class_ = CHAMMI_CP
    elif name == "CHAMMI_WTC":
        class_ = CHAMMI_WTC
    elif name == "CHAMMI_HPA":
        class_ = CHAMMI_HPA
    else:
        raise ValueError(f'Unsupported dataset "{name}"')

    return class_, kwargs


def make_dataset(
    *,
    dataset_str: str,
    transform: Optional[Callable] = None,
    target_transform: Optional[Callable] = None,
):
    """
    Creates a dataset with the specified parameters.

    Args:
        dataset_str: A dataset string description (e.g. ImageNet:split=TRAIN).
        transform: A transform to apply to images.
        target_transform: A transform to apply to targets.

    Returns:
        The created dataset.
    """
    logger.info(f'using dataset: "{dataset_str}"')

    class_, kwargs = _parse_dataset_str(dataset_str)
    dataset = class_(transform=transform, target_transform=target_transform, **kwargs)

    logger.info(f"# of dataset samples: {len(dataset):,d}")

    # Aggregated datasets do not expose (yet) these attributes, so add them.
    if not hasattr(dataset, "transform"):
        setattr(dataset, "transform", transform)
    if not hasattr(dataset, "target_transform"):
        setattr(dataset, "target_transform", target_transform)

    return dataset


def _make_sampler(
    *,
    dataset,
    type: Optional[SamplerType] = None,
    shuffle: bool = False,
    seed: int = 0,
    size: int = -1,
    advance: int = 0,
) -> Optional[Sampler]:
    sample_count = len(dataset)

    if type == SamplerType.INFINITE:
        logger.info("sampler: infinite")
        if size > 0:
            raise ValueError("sampler size > 0 is invalid")
        return InfiniteSampler(
            sample_count=sample_count,
            shuffle=shuffle,
            seed=seed,
            advance=advance,
        )
    elif type in (SamplerType.SHARDED_INFINITE, SamplerType.SHARDED_INFINITE_NEW):
        logger.info("sampler: sharded infinite")
        if size > 0:
            raise ValueError("sampler size > 0 is invalid")
        # TODO: Remove support for old shuffling
        use_new_shuffle_tensor_slice = type == SamplerType.SHARDED_INFINITE_NEW
        return ShardedInfiniteSampler(
            sample_count=sample_count,
            shuffle=shuffle,
            seed=seed,
            advance=advance,
            use_new_shuffle_tensor_slice=use_new_shuffle_tensor_slice,
        )
    elif type == SamplerType.EPOCH:
        logger.info("sampler: epoch")
        if advance > 0:
            raise NotImplementedError("sampler advance > 0 is not supported")
        size = size if size > 0 else sample_count
        logger.info(f"# of samples / epoch: {size:,d}")
        return EpochSampler(
            size=size,
            sample_count=sample_count,
            shuffle=shuffle,
            seed=seed,
        )
    elif type == SamplerType.DISTRIBUTED:
        logger.info("sampler: distributed")
        if size > 0:
            raise ValueError("sampler size > 0 is invalid")
        if advance > 0:
            raise ValueError("sampler advance > 0 is invalid")
        return torch.utils.data.DistributedSampler(
            dataset=dataset,
            shuffle=shuffle,
            seed=seed,
            drop_last=False,
        )

    logger.info("sampler: none")
    return None


T = TypeVar("T")


def make_data_loader(
    *,
    dataset,
    batch_size: int,
    num_workers: int,
    shuffle: bool = True,
    seed: int = 0,
    sampler_type: Optional[SamplerType] = SamplerType.INFINITE,
    sampler_size: int = -1,
    sampler_advance: int = 0,
    drop_last: bool = True,
    persistent_workers: bool = False,
    collate_fn: Optional[Callable[[List[T]], Any]] = None,
):
    """
    Creates a data loader with the specified parameters.

    Args:
        dataset: A dataset (third party, LaViDa or WebDataset).
        batch_size: The size of batches to generate.
        num_workers: The number of workers to use.
        shuffle: Whether to shuffle samples.
        seed: The random seed to use.
        sampler_type: Which sampler to use: EPOCH, INFINITE, SHARDED_INFINITE, SHARDED_INFINITE_NEW, DISTRIBUTED or None.
        sampler_size: The number of images per epoch (when applicable) or -1 for the entire dataset.
        sampler_advance: How many samples to skip (when applicable).
        drop_last: Whether the last non-full batch of data should be dropped.
        persistent_workers: maintain the workers Dataset instances alive after a dataset has been consumed once.
        collate_fn: Function that performs batch collation
    """

    sampler = _make_sampler(
        dataset=dataset,
        type=sampler_type,
        shuffle=shuffle,
        seed=seed,
        size=sampler_size,
        advance=sampler_advance,
    )

    logger.info("using PyTorch data loader")
    data_loader = torch.utils.data.DataLoader(
        dataset,
        sampler=sampler,
        batch_size=batch_size,
        num_workers=num_workers,
        pin_memory=True,
        drop_last=drop_last,
        persistent_workers=persistent_workers,
        collate_fn=collate_fn,
    )

    try:
        logger.info(f"# of batches: {len(data_loader):,d}")
    except TypeError:  # data loader has no length
        logger.info("infinite data loader")
    return data_loader


================================================
FILE: dinov2/data/masking.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

import random
import math
import numpy as np


class MaskingGenerator:
    def __init__(
        self,
        input_size,
        num_masking_patches=None,
        min_num_patches=4,
        max_num_patches=None,
        min_aspect=0.3,
        max_aspect=None,
    ):
        if not isinstance(input_size, tuple):
            input_size = (input_size,) * 2
        self.height, self.width = input_size

        self.num_patches = self.height * self.width
        self.num_masking_patches = num_masking_patches

        self.min_num_patches = min_num_patches
        self.max_num_patches = num_masking_patches if max_num_patches is None else max_num_patches

        max_aspect = max_aspect or 1 / min_aspect
        self.log_aspect_ratio = (math.log(min_aspect), math.log(max_aspect))

    def __repr__(self):
        repr_str = "Generator(%d, %d -> [%d ~ %d], max = %d, %.3f ~ %.3f)" % (
            self.height,
            self.width,
            self.min_num_patches,
            self.max_num_patches,
            self.num_masking_patches,
            self.log_aspect_ratio[0],
            self.log_aspect_ratio[1],
        )
        return repr_str

    def get_shape(self):
        return self.height, self.width

    def _mask(self, mask, max_mask_patches):
        delta = 0
        for _ in range(10):
            target_area = random.uniform(self.min_num_patches, max_mask_patches)
            aspect_ratio = math.exp(random.uniform(*self.log_aspect_ratio))
            h = int(round(math.sqrt(target_area * aspect_ratio)))
            w = int(round(math.sqrt(target_area / aspect_ratio)))
            if w < self.width and h < self.height:
                top = random.randint(0, self.height - h)
                left = random.randint(0, self.width - w)

                num_masked = mask[top : top + h, left : left + w].sum()
                # Overlap
                if 0 < h * w - num_masked <= max_mask_patches:
                    for i in range(top, top + h):
                        for j in range(left, left + w):
                            if mask[i, j] == 0:
                                mask[i, j] = 1
                                delta += 1

                if delta > 0:
                    break
        return delta

    def __call__(self, num_masking_patches=0):
        mask = np.zeros(shape=self.get_shape(), dtype=bool)
        mask_count = 0
        while mask_count < num_masking_patches:
            max_mask_patches = num_masking_patches - mask_count
            max_mask_patches = min(max_mask_patches, self.max_num_patches)

            delta = self._mask(mask, max_mask_patches)
            if delta == 0:
                break
            else:
                mask_count += delta

        return mask


================================================
FILE: dinov2/data/samplers.py
================================================
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the Apache License, Version 2.0
# found in the LICENSE file in the root directory of this source tree.

import itertools
from typing import Any, Optional
import warnings

import numpy as np
import torch
from torch.utils.data.sampler import Sampler

import dinov2.distributed as distributed


class EpochSampler(Sampler):
    def __init__(
        self,
        *,
        size: int,
        sample_count: int,
        shuffle: bool = False,
        seed: int = 0,
        start: Optional[int] = None,
        step: Optional[int] = None,
    ):
        self._size = size
        self._sample_count = sample_count
        self._shuffle = shuffle
        self._seed = seed
        self._start = distributed.get_global_rank() if start is None else start
        self._step = distributed.get_global_size() if step is None else step
        self._epoch = 0

    def __iter__(self):
        count = (self._size + self._sample_count - 1) // self._sample_count
        tiled_indices = np.tile(np.arange(self._sample_count), count)
        if self._shuffle:
            seed = self._seed * self._epoch if self._seed != 0 else self._epoch
            rng = np.random.default_rng(seed)
            iterable = rng.choice(tiled_indices, self._size, replace=False)
        else:
            iterable = tiled_indices[: self._size]

        yield from itertools.islice(iterable, self._start, None, self._step)

    def __len__(self):
        return (self._size - self._start + self._step - 1) // self._step

    def set_epoch(self, epoch):
        self._epoch = epoch


def _get_numpy_dtype(size: int) -> Any:
    return np.int32 if size <= 2**31 else np.int64


def _get_torch_dtype(size: int) -> Any:
    return torch.int32 if size <= 2**31 else torch.int64


def _generate_randperm_indices(*, size: int, generator: torch.Generator):
    """Generate the indices of a random permutation."""
    dtype = _get_torch_dtype(size)
    # This is actually matching PyTorch's CPU implementation, see: https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/TensorFactories.cpp#L900-L921
    perm = torch.arange(size, dtype=dtype)
  
Download .txt
gitextract_rhfo6abb/

├── .github/
│   └── workflows/
│       └── lint.yaml
├── .gitignore
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── LICENSE_CELL_DINO_CODE
├── LICENSE_CELL_DINO_MODELS
├── LICENSE_XRAY_DINO_MODEL
├── MODEL_CARD.md
├── README.md
├── conda-extras.yaml
├── conda.yaml
├── dinov2/
│   ├── __init__.py
│   ├── configs/
│   │   ├── __init__.py
│   │   ├── eval/
│   │   │   ├── cell_dino/
│   │   │   │   ├── vitl16_channel_adaptive_pretrain.yaml
│   │   │   │   └── vitl16_pretrain.yaml
│   │   │   ├── vitb14_pretrain.yaml
│   │   │   ├── vitb14_reg4_pretrain.yaml
│   │   │   ├── vitg14_pretrain.yaml
│   │   │   ├── vitg14_reg4_pretrain.yaml
│   │   │   ├── vitl14_pretrain.yaml
│   │   │   ├── vitl14_reg4_pretrain.yaml
│   │   │   ├── vits14_pretrain.yaml
│   │   │   └── vits14_reg4_pretrain.yaml
│   │   ├── ssl_default_config.yaml
│   │   └── train/
│   │       ├── cell_dino/
│   │       │   ├── vitl16_boc_hpafov.yaml
│   │       │   ├── vitl16_hpafov.yaml
│   │       │   └── vitl16_hpaone.yaml
│   │       ├── vitg14.yaml
│   │       ├── vitl14.yaml
│   │       └── vitl16_short.yaml
│   ├── data/
│   │   ├── __init__.py
│   │   ├── accumulators.py
│   │   ├── adapters.py
│   │   ├── augmentations.py
│   │   ├── cell_dino/
│   │   │   ├── augmentations.py
│   │   │   └── transforms.py
│   │   ├── collate.py
│   │   ├── datasets/
│   │   │   ├── __init__.py
│   │   │   ├── cell_dino/
│   │   │   │   ├── chammi_cp.py
│   │   │   │   ├── chammi_hpa.py
│   │   │   │   ├── chammi_wtc.py
│   │   │   │   ├── hpafov.py
│   │   │   │   └── hpaone.py
│   │   │   ├── decoders.py
│   │   │   ├── extended.py
│   │   │   ├── image_net.py
│   │   │   └── image_net_22k.py
│   │   ├── loaders.py
│   │   ├── masking.py
│   │   ├── samplers.py
│   │   └── transforms.py
│   ├── distributed/
│   │   └── __init__.py
│   ├── eval/
│   │   ├── __init__.py
│   │   ├── cell_dino/
│   │   │   ├── knn.py
│   │   │   ├── linear.py
│   │   │   └── utils.py
│   │   ├── depth/
│   │   │   ├── __init__.py
│   │   │   ├── models/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── backbones/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   └── vision_transformer.py
│   │   │   │   ├── builder.py
│   │   │   │   ├── decode_heads/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── decode_head.py
│   │   │   │   │   ├── dpt_head.py
│   │   │   │   │   └── linear_head.py
│   │   │   │   ├── depther/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── base.py
│   │   │   │   │   └── encoder_decoder.py
│   │   │   │   └── losses/
│   │   │   │       ├── __init__.py
│   │   │   │       ├── gradientloss.py
│   │   │   │       └── sigloss.py
│   │   │   └── ops/
│   │   │       ├── __init__.py
│   │   │       └── wrappers.py
│   │   ├── knn.py
│   │   ├── linear.py
│   │   ├── log_regression.py
│   │   ├── metrics.py
│   │   ├── segmentation/
│   │   │   ├── __init__.py
│   │   │   ├── hooks/
│   │   │   │   ├── __init__.py
│   │   │   │   └── optimizer.py
│   │   │   ├── models/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── backbones/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   └── vision_transformer.py
│   │   │   │   └── decode_heads/
│   │   │   │       ├── __init__.py
│   │   │   │       └── linear_head.py
│   │   │   └── utils/
│   │   │       ├── __init__.py
│   │   │       └── colormaps.py
│   │   ├── segmentation_m2f/
│   │   │   ├── __init__.py
│   │   │   ├── core/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── anchor/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── builder.py
│   │   │   │   │   └── point_generator.py
│   │   │   │   ├── box/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── builder.py
│   │   │   │   │   └── samplers/
│   │   │   │   │       ├── __init__.py
│   │   │   │   │       ├── base_sampler.py
│   │   │   │   │       ├── mask_pseudo_sampler.py
│   │   │   │   │       ├── mask_sampling_result.py
│   │   │   │   │       └── sampling_result.py
│   │   │   │   └── utils/
│   │   │   │       ├── __init__.py
│   │   │   │       ├── dist_utils.py
│   │   │   │       └── misc.py
│   │   │   ├── models/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── backbones/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── adapter_modules.py
│   │   │   │   │   ├── drop_path.py
│   │   │   │   │   ├── vit.py
│   │   │   │   │   └── vit_adapter.py
│   │   │   │   ├── builder.py
│   │   │   │   ├── decode_heads/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   └── mask2former_head.py
│   │   │   │   ├── losses/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── cross_entropy_loss.py
│   │   │   │   │   ├── dice_loss.py
│   │   │   │   │   └── match_costs.py
│   │   │   │   ├── plugins/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   └── msdeformattn_pixel_decoder.py
│   │   │   │   ├── segmentors/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   └── encoder_decoder_mask2former.py
│   │   │   │   └── utils/
│   │   │   │       ├── __init__.py
│   │   │   │       ├── assigner.py
│   │   │   │       ├── point_sample.py
│   │   │   │       ├── positional_encoding.py
│   │   │   │       └── transformer.py
│   │   │   └── ops/
│   │   │       └── modules/
│   │   │           ├── __init__.py
│   │   │           └── ms_deform_attn.py
│   │   ├── setup.py
│   │   └── utils.py
│   ├── fsdp/
│   │   └── __init__.py
│   ├── hub/
│   │   ├── __init__.py
│   │   ├── backbones.py
│   │   ├── cell_dino/
│   │   │   └── backbones.py
│   │   ├── classifiers.py
│   │   ├── depth/
│   │   │   ├── __init__.py
│   │   │   ├── decode_heads.py
│   │   │   ├── encoder_decoder.py
│   │   │   └── ops.py
│   │   ├── depthers.py
│   │   ├── dinotxt.py
│   │   ├── text/
│   │   │   ├── dinotxt_model.py
│   │   │   ├── dinov2_wrapper.py
│   │   │   ├── text_tower.py
│   │   │   ├── text_transformer.py
│   │   │   ├── tokenizer.py
│   │   │   └── vision_tower.py
│   │   ├── utils.py
│   │   └── xray_dino/
│   │       └── backbones.py
│   ├── layers/
│   │   ├── __init__.py
│   │   ├── attention.py
│   │   ├── block.py
│   │   ├── dino_head.py
│   │   ├── drop_path.py
│   │   ├── layer_scale.py
│   │   ├── mlp.py
│   │   ├── patch_embed.py
│   │   └── swiglu_ffn.py
│   ├── logging/
│   │   ├── __init__.py
│   │   └── helpers.py
│   ├── loss/
│   │   ├── __init__.py
│   │   ├── dino_clstoken_loss.py
│   │   ├── ibot_patch_loss.py
│   │   └── koleo_loss.py
│   ├── models/
│   │   ├── __init__.py
│   │   └── vision_transformer.py
│   ├── run/
│   │   ├── __init__.py
│   │   ├── eval/
│   │   │   ├── cell_dino/
│   │   │   │   ├── knn.py
│   │   │   │   └── linear.py
│   │   │   ├── knn.py
│   │   │   ├── linear.py
│   │   │   └── log_regression.py
│   │   ├── submit.py
│   │   └── train/
│   │       └── train.py
│   ├── thirdparty/
│   │   └── CLIP/
│   │       ├── LICENSE
│   │       └── clip/
│   │           └── simple_tokenizer.py
│   ├── train/
│   │   ├── __init__.py
│   │   ├── ssl_meta_arch.py
│   │   └── train.py
│   └── utils/
│       ├── __init__.py
│       ├── checkpoint.py
│       ├── cluster.py
│       ├── config.py
│       ├── dtype.py
│       ├── param_groups.py
│       └── utils.py
├── docs/
│   ├── README_CELL_DINO.md
│   └── README_CHANNEL_ADAPTIVE_DINO.md
├── hubconf.py
├── notebooks/
│   ├── cell_dino/
│   │   └── inference.ipynb
│   ├── depth_estimation.ipynb
│   ├── dinotxt.ipynb
│   └── semantic_segmentation.ipynb
├── pyproject.toml
├── requirements-dev.txt
├── requirements-extras.txt
├── requirements.txt
├── scripts/
│   ├── cell_dino/
│   │   ├── launcher_knn_eval_on_chammi.sh
│   │   └── launcher_linear_eval_on_chammi.sh
│   └── lint.sh
├── setup.cfg
└── setup.py
Download .txt
SYMBOL INDEX (1094 symbols across 117 files)

FILE: dinov2/configs/__init__.py
  function load_config (line 11) | def load_config(config_name: str):
  function load_and_merge_config (line 19) | def load_and_merge_config(config_name: str):

FILE: dinov2/data/accumulators.py
  function _simple_gather_all_tensors (line 17) | def _simple_gather_all_tensors(result: torch.Tensor, group: Any, world_s...
  function gather_all_tensors (line 23) | def gather_all_tensors(result: torch.Tensor, group: Optional[Any] = None...
  function _cat_and_gather_tensor_list (line 74) | def _cat_and_gather_tensor_list(tensor_list: List[Tensor]) -> Tensor:
  class Accumulator (line 79) | class Accumulator:
    method __init__ (line 80) | def __init__(self) -> None:
    method update (line 83) | def update(self, preds: Tensor, target: Tensor, index: Tensor) -> None:
    method accumulate (line 86) | def accumulate(self) -> Optional[Dict[str, Tensor]]:
  class NoOpAccumulator (line 90) | class NoOpAccumulator(Accumulator):
    method __init__ (line 91) | def __init__(self) -> None:
    method update (line 94) | def update(self, preds: Tensor, target: Tensor, index: Tensor) -> None:
    method accumulate (line 97) | def accumulate(self) -> None:
  class ResultsAccumulator (line 101) | class ResultsAccumulator(Accumulator):
    method __init__ (line 106) | def __init__(self) -> None:
    method update (line 111) | def update(self, preds: Tensor, target: Tensor, index: Tensor) -> None:
    method _gather_tensors (line 119) | def _gather_tensors(self):
    method accumulate (line 124) | def accumulate(self) -> Dict[str, Tensor]:

FILE: dinov2/data/adapters.py
  class DatasetWithEnumeratedTargets (line 11) | class DatasetWithEnumeratedTargets(Dataset):
    method __init__ (line 18) | def __init__(self, dataset: Dataset, pad_dataset: bool = False, num_re...
    method get_image_relpath (line 27) | def get_image_relpath(self, index: int) -> str:
    method get_image_data (line 31) | def get_image_data(self, index: int) -> bytes:
    method get_target (line 35) | def get_target(self, index: int) -> Tuple[Any, int]:
    method __getitem__ (line 42) | def __getitem__(self, index: int) -> Tuple[Any, Tuple[Any, int]]:
    method __len__ (line 50) | def __len__(self) -> int:

FILE: dinov2/data/augmentations.py
  class DataAugmentationDINO (line 19) | class DataAugmentationDINO(object):
    method __init__ (line 20) | def __init__(
    method __call__ (line 96) | def __call__(self, image):

FILE: dinov2/data/cell_dino/augmentations.py
  class CellAugmentationDINO (line 22) | class CellAugmentationDINO(object):
    method __init__ (line 23) | def __init__(
    method __call__ (line 75) | def __call__(self, image):

FILE: dinov2/data/cell_dino/transforms.py
  class NormalizationType (line 12) | class NormalizationType(Enum):
  class Div255 (line 17) | class Div255(torch.nn.Module):
    method forward (line 18) | def forward(self, x):
  class SelfNormalizeNoDiv (line 23) | class SelfNormalizeNoDiv(torch.nn.Module):
    method forward (line 24) | def forward(self, x):
  class SelfNormalize (line 32) | class SelfNormalize(torch.nn.Module):
    method forward (line 33) | def forward(self, x):
  class RandomContrastProteinChannel (line 42) | class RandomContrastProteinChannel(torch.nn.Module):
    method __init__ (line 48) | def __init__(self, p=0.2):
    method forward (line 52) | def forward(self, img):
  class RandomRemoveChannelExceptProtein (line 65) | class RandomRemoveChannelExceptProtein(torch.nn.Module):
    method __init__ (line 70) | def __init__(self, p=0.2):
    method forward (line 74) | def forward(self, img):
  class RandomRemoveChannel (line 86) | class RandomRemoveChannel(torch.nn.Module):
    method __init__ (line 91) | def __init__(self, p=0.2):
    method forward (line 95) | def forward(self, img):
  class RandomContrast (line 108) | class RandomContrast(torch.nn.Module):
    method __init__ (line 109) | def __init__(self, p=0.2):
    method forward (line 113) | def forward(self, img):
  class RandomBrightness (line 123) | class RandomBrightness(torch.nn.Module):
    method __init__ (line 124) | def __init__(self, p=0.2):
    method forward (line 128) | def forward(self, img):
  function make_classification_eval_cell_transform (line 138) | def make_classification_eval_cell_transform(

FILE: dinov2/data/collate.py
  function collate_data_and_cast (line 10) | def collate_data_and_cast(samples_list, mask_ratio_tuple, mask_probabili...

FILE: dinov2/data/datasets/cell_dino/chammi_cp.py
  class _Split (line 33) | class _Split(Enum):
  function _load_file_names_and_targets (line 41) | def _load_file_names_and_targets(
  class CHAMMI_CP (line 59) | class CHAMMI_CP(ExtendedVisionDataset):
    method __init__ (line 68) | def __init__(
    method get_image_relpath (line 95) | def get_image_relpath(self, index: int) -> str:
    method get_image_data (line 98) | def get_image_data(self, index: int) -> bytes:
    method get_target (line 105) | def get_target(self, index: int) -> Any:
    method get_targets (line 108) | def get_targets(self) -> np.ndarray:
    method __len__ (line 111) | def __len__(self) -> int:

FILE: dinov2/data/datasets/cell_dino/chammi_hpa.py
  class _Split (line 33) | class _Split(Enum):
  function _load_file_names_and_targets (line 40) | def _load_file_names_and_targets(
  class CHAMMI_HPA (line 57) | class CHAMMI_HPA(ExtendedVisionDataset):
    method __init__ (line 66) | def __init__(
    method get_image_relpath (line 94) | def get_image_relpath(self, index: int) -> str:
    method get_image_data (line 97) | def get_image_data(self, index: int) -> bytes:
    method get_target (line 104) | def get_target(self, index: int) -> Any:
    method get_targets (line 107) | def get_targets(self) -> np.ndarray:
    method __len__ (line 110) | def __len__(self) -> int:

FILE: dinov2/data/datasets/cell_dino/chammi_wtc.py
  class _Split (line 32) | class _Split(Enum):
  function _load_file_names_and_targets (line 38) | def _load_file_names_and_targets(
  class CHAMMI_WTC (line 55) | class CHAMMI_WTC(ExtendedVisionDataset):
    method __init__ (line 64) | def __init__(
    method get_image_relpath (line 91) | def get_image_relpath(self, index: int) -> str:
    method get_image_data (line 94) | def get_image_data(self, index: int) -> bytes:
    method get_target (line 101) | def get_target(self, index: int) -> Any:
    method get_targets (line 104) | def get_targets(self) -> np.ndarray:
    method __len__ (line 107) | def __len__(self) -> int:

FILE: dinov2/data/datasets/cell_dino/hpafov.py
  class _Split (line 89) | class _Split(Enum):
  function get_csv_fpath (line 95) | def get_csv_fpath(split):
  class _WildCard (line 105) | class _WildCard(Enum):
  class _Mode (line 110) | class _Mode(Enum):
    method nb_labels (line 123) | def nb_labels(self):
  function _list_images_from_csv (line 132) | def _list_images_from_csv(img_path, csv_path):
  function _load_file_names_and_labels_ssl (line 141) | def _load_file_names_and_labels_ssl(
  function _load_file_names_and_labels (line 152) | def _load_file_names_and_labels(
  class HPAFoV (line 208) | class HPAFoV(ExtendedVisionDataset):
    method __init__ (line 213) | def __init__(
    method get_image_relpath (line 262) | def get_image_relpath(self, index: int) -> str:
    method get_image_data (line 265) | def get_image_data(self, index: int) -> bytes:
    method get_target (line 276) | def get_target(self, index: int) -> Any:
    method get_targets (line 279) | def get_targets(self) -> np.ndarray:
    method __len__ (line 282) | def __len__(self) -> int:

FILE: dinov2/data/datasets/cell_dino/hpaone.py
  class _Split (line 75) | class _Split(Enum):
  class _Mode (line 81) | class _Mode(Enum):
    method num_labels (line 86) | def num_labels(self):
  function _simple_parse_csv (line 92) | def _simple_parse_csv(img_rootdir, csv_filepath: str):
  function _parse_csv (line 100) | def _parse_csv(img_rootdir, csv_labels_path: str):
  function _load_file_names_and_labels_ssl (line 127) | def _load_file_names_and_labels_ssl(
  function _load_file_names_and_labels_train_or_test (line 138) | def _load_file_names_and_labels_train_or_test(
  class HPAone (line 164) | class HPAone(ExtendedVisionDataset):
    method __init__ (line 168) | def __init__(
    method get_image_relpath (line 206) | def get_image_relpath(self, index: int) -> str:
    method get_image_data (line 209) | def get_image_data(self, index: int) -> bytes:
    method get_target (line 216) | def get_target(self, index: int) -> Any:
    method get_targets (line 219) | def get_targets(self) -> np.ndarray:
    method __len__ (line 222) | def __len__(self) -> int:

FILE: dinov2/data/datasets/decoders.py
  class Decoder (line 20) | class Decoder:
    method decode (line 21) | def decode(self) -> Any:
  class DecoderType (line 25) | class DecoderType(Enum):
    method get_class (line 31) | def get_class(self) -> Type[Decoder]:  # noqa: C901
  class ImageDataDecoder (line 42) | class ImageDataDecoder(Decoder):
    method __init__ (line 43) | def __init__(self, image_data: bytes) -> None:
    method decode (line 46) | def decode(self) -> Image:
  class TargetDecoder (line 51) | class TargetDecoder(Decoder):
    method __init__ (line 52) | def __init__(self, target: Any):
    method decode (line 55) | def decode(self) -> Any:
  class XChannelsDecoder (line 59) | class XChannelsDecoder(Decoder):
    method __init__ (line 60) | def __init__(self, image_data: bytes) -> None:
    method decode (line 63) | def decode(self):
  class XChannelsTIFFDecoder (line 70) | class XChannelsTIFFDecoder(Decoder):
    method __init__ (line 71) | def __init__(self, image_data: bytes, num_channels: int = 3) -> None:
    method decode (line 75) | def decode(self):
  class ChannelSelectDecoder (line 81) | class ChannelSelectDecoder(Decoder):
    method __init__ (line 82) | def __init__(self, image_data: bytes, select_channel: bool = False) ->...
    method decode (line 90) | def decode(self):

FILE: dinov2/data/datasets/extended.py
  class ExtendedVisionDataset (line 13) | class ExtendedVisionDataset(VisionDataset):
    method __init__ (line 14) | def __init__(self, *args, **kwargs) -> None:
    method get_image_data (line 23) | def get_image_data(self, index: int) -> bytes:
    method get_target (line 26) | def get_target(self, index: int) -> Any:
    method __getitem__ (line 29) | def __getitem__(self, index: int) -> Tuple[Any, Any]:
    method __len__ (line 43) | def __len__(self) -> int:

FILE: dinov2/data/datasets/image_net.py
  class _Split (line 21) | class _Split(Enum):
    method length (line 27) | def length(self) -> int:
    method get_dirname (line 35) | def get_dirname(self, class_id: Optional[str] = None) -> str:
    method get_image_relpath (line 38) | def get_image_relpath(self, actual_index: int, class_id: Optional[str]...
    method parse_image_relpath (line 46) | def parse_image_relpath(self, image_relpath: str) -> Tuple[str, int]:
  class ImageNet (line 55) | class ImageNet(ExtendedVisionDataset):
    method __init__ (line 59) | def __init__(
    method split (line 78) | def split(self) -> "ImageNet.Split":
    method _get_extra_full_path (line 81) | def _get_extra_full_path(self, extra_path: str) -> str:
    method _load_extra (line 84) | def _load_extra(self, extra_path: str) -> np.ndarray:
    method _save_extra (line 88) | def _save_extra(self, extra_array: np.ndarray, extra_path: str) -> None:
    method _entries_path (line 94) | def _entries_path(self) -> str:
    method _class_ids_path (line 98) | def _class_ids_path(self) -> str:
    method _class_names_path (line 102) | def _class_names_path(self) -> str:
    method _get_entries (line 105) | def _get_entries(self) -> np.ndarray:
    method _get_class_ids (line 111) | def _get_class_ids(self) -> np.ndarray:
    method _get_class_names (line 119) | def _get_class_names(self) -> np.ndarray:
    method find_class_id (line 127) | def find_class_id(self, class_index: int) -> str:
    method find_class_name (line 131) | def find_class_name(self, class_index: int) -> str:
    method get_image_data (line 135) | def get_image_data(self, index: int) -> bytes:
    method get_target (line 147) | def get_target(self, index: int) -> Optional[Target]:
    method get_targets (line 152) | def get_targets(self) -> Optional[np.ndarray]:
    method get_class_id (line 156) | def get_class_id(self, index: int) -> Optional[str]:
    method get_class_name (line 161) | def get_class_name(self, index: int) -> Optional[str]:
    method __len__ (line 166) | def __len__(self) -> int:
    method _load_labels (line 171) | def _load_labels(self, labels_path: str) -> List[Tuple[str, str]]:
    method _dump_entries (line 186) | def _dump_entries(self) -> None:
    method _dump_class_ids_and_names (line 252) | def _dump_class_ids_and_names(self) -> None:
    method dump_extra (line 288) | def dump_extra(self) -> None:

FILE: dinov2/data/datasets/image_net_22k.py
  class _ClassEntry (line 27) | class _ClassEntry:
  class _Entry (line 33) | class _Entry:
  class _Split (line 40) | class _Split(Enum):
    method length (line 45) | def length(self) -> int:
    method entries_path (line 51) | def entries_path(self):
  function _get_tarball_path (line 55) | def _get_tarball_path(class_id: str) -> str:
  function _make_mmap_tarball (line 59) | def _make_mmap_tarball(tarballs_root: str, mmap_cache_size: int):
  class ImageNet22k (line 70) | class ImageNet22k(ExtendedVisionDataset):
    method __init__ (line 101) | def __init__(
    method _get_entries_path (line 123) | def _get_entries_path(self, root: Optional[str] = None) -> str:
    method _get_class_ids_path (line 126) | def _get_class_ids_path(self, root: Optional[str] = None) -> str:
    method _find_class_ids (line 129) | def _find_class_ids(self, path: str) -> List[str]:
    method _load_entries_class_ids (line 141) | def _load_entries_class_ids(self, root: Optional[str] = None) -> Tuple...
    method _load_extra (line 185) | def _load_extra(self, extra_path: str) -> np.ndarray:
    method _save_extra (line 190) | def _save_extra(self, extra_array: np.ndarray, extra_path: str) -> None:
    method _tarballs_root (line 197) | def _tarballs_root(self) -> str:
    method find_class_id (line 200) | def find_class_id(self, class_index: int) -> str:
    method get_image_data (line 203) | def get_image_data(self, index: int) -> bytes:
    method get_target (line 222) | def get_target(self, index: int) -> Any:
    method get_targets (line 225) | def get_targets(self) -> np.ndarray:
    method get_class_id (line 228) | def get_class_id(self, index: int) -> str:
    method get_class_ids (line 231) | def get_class_ids(self) -> np.ndarray:
    method __getitem__ (line 234) | def __getitem__(self, index: int) -> Tuple[Any, Any]:
    method __len__ (line 239) | def __len__(self) -> int:
    method _dump_entries (line 242) | def _dump_entries(self, *args, **kwargs) -> None:
    method _dump_class_ids (line 280) | def _dump_class_ids(self, *args, **kwargs) -> None:
    method _dump_extra (line 297) | def _dump_extra(self, *args, **kwargs) -> None:
    method dump_extra (line 301) | def dump_extra(self, root: Optional[str] = None) -> None:

FILE: dinov2/data/loaders.py
  class SamplerType (line 20) | class SamplerType(Enum):
  function _make_bool_str (line 28) | def _make_bool_str(b: bool) -> str:
  function _make_sample_transform (line 32) | def _make_sample_transform(image_transform: Optional[Callable] = None, t...
  function _parse_dataset_str (line 44) | def _parse_dataset_str(dataset_str: str):
  function make_dataset (line 77) | def make_dataset(
  function _make_sampler (line 110) | def _make_sampler(
  function make_data_loader (line 176) | def make_data_loader(

FILE: dinov2/data/masking.py
  class MaskingGenerator (line 11) | class MaskingGenerator:
    method __init__ (line 12) | def __init__(
    method __repr__ (line 34) | def __repr__(self):
    method get_shape (line 46) | def get_shape(self):
    method _mask (line 49) | def _mask(self, mask, max_mask_patches):
    method __call__ (line 73) | def __call__(self, num_masking_patches=0):

FILE: dinov2/data/samplers.py
  class EpochSampler (line 17) | class EpochSampler(Sampler):
    method __init__ (line 18) | def __init__(
    method __iter__ (line 36) | def __iter__(self):
    method __len__ (line 48) | def __len__(self):
    method set_epoch (line 51) | def set_epoch(self, epoch):
  function _get_numpy_dtype (line 55) | def _get_numpy_dtype(size: int) -> Any:
  function _get_torch_dtype (line 59) | def _get_torch_dtype(size: int) -> Any:
  function _generate_randperm_indices (line 63) | def _generate_randperm_indices(*, size: int, generator: torch.Generator):
  class InfiniteSampler (line 78) | class InfiniteSampler(Sampler):
    method __init__ (line 79) | def __init__(
    method __iter__ (line 96) | def __iter__(self):
    method _iterator (line 104) | def _iterator(self):
    method _shuffled_iterator (line 111) | def _shuffled_iterator(self):
  function _shuffle_tensor_slice (line 125) | def _shuffle_tensor_slice(
  function _new_shuffle_tensor_slice (line 146) | def _new_shuffle_tensor_slice(
  function _make_seed (line 160) | def _make_seed(seed: int, start: int, iter_count: int) -> int:
  class ShardedInfiniteSampler (line 165) | class ShardedInfiniteSampler(Sampler):
    method __init__ (line 166) | def __init__(
    method __iter__ (line 188) | def __iter__(self):
    method _iterator (line 201) | def _iterator(self):
    method _shuffled_iterator (line 208) | def _shuffled_iterator(self):

FILE: dinov2/data/transforms.py
  class GaussianBlur (line 12) | class GaussianBlur(transforms.RandomApply):
    method __init__ (line 17) | def __init__(self, *, p: float = 0.5, radius_min: float = 0.1, radius_...
  class MaybeToTensor (line 24) | class MaybeToTensor(transforms.ToTensor):
    method __call__ (line 29) | def __call__(self, pic):
  function make_normalize_transform (line 46) | def make_normalize_transform(
  function make_classification_train_transform (line 55) | def make_classification_train_transform(
  function make_classification_eval_transform (line 77) | def make_classification_eval_transform(

FILE: dinov2/distributed/__init__.py
  function is_enabled (line 19) | def is_enabled() -> bool:
  function get_global_size (line 27) | def get_global_size() -> int:
  function get_global_rank (line 35) | def get_global_rank() -> int:
  function get_local_rank (line 43) | def get_local_rank() -> int:
  function get_local_size (line 54) | def get_local_size() -> int:
  function is_main_process (line 66) | def is_main_process() -> bool:
  function _restrict_print_to_main_process (line 74) | def _restrict_print_to_main_process() -> None:
  function _get_master_port (line 90) | def _get_master_port(seed: int = 0) -> int:
  function _get_available_port (line 101) | def _get_available_port() -> int:
  function _collect_env_vars (line 120) | def _collect_env_vars() -> Dict[str, str]:
  function _is_slurm_job_process (line 124) | def _is_slurm_job_process() -> bool:
  function _parse_slurm_node_list (line 128) | def _parse_slurm_node_list(s: str) -> List[str]:
  function _check_env_variable (line 145) | def _check_env_variable(key: str, new_value: str):
  class _TorchDistributedEnvironment (line 151) | class _TorchDistributedEnvironment:
    method __init__ (line 152) | def __init__(self):
    method _set_from_slurm_env (line 181) | def _set_from_slurm_env(self):
    method _set_from_preset_env (line 198) | def _set_from_preset_env(self):
    method _set_from_local (line 210) | def _set_from_local(self):
    method export (line 219) | def export(self, *, overwrite: bool) -> "_TorchDistributedEnvironment":
  function enable (line 239) | def enable(*, set_cuda_current_device: bool = True, overwrite: bool = Fa...

FILE: dinov2/eval/cell_dino/knn.py
  function get_args_parser (line 47) | def get_args_parser(
  class SequentialWithKwargs (line 148) | class SequentialWithKwargs(torch.nn.Sequential):
    method __init__ (line 149) | def __init__(self, *args):
    method forward (line 152) | def forward(self, input, **kwargs):
  function create_train_test_dataset_dict_leave_one_out (line 160) | def create_train_test_dataset_dict_leave_one_out(
  function eval_knn_with_leave_one_out (line 185) | def eval_knn_with_leave_one_out(
  function eval_knn_with_model (line 290) | def eval_knn_with_model(
  function eval_knn (line 372) | def eval_knn(
  function main (line 452) | def main(args):

FILE: dinov2/eval/cell_dino/linear.py
  function get_args_parser (line 63) | def get_args_parser(
  function has_ddp_wrapper (line 239) | def has_ddp_wrapper(m: nn.Module) -> bool:
  function remove_ddp_wrapper (line 243) | def remove_ddp_wrapper(m: nn.Module) -> nn.Module:
  function create_linear_input (line 247) | def create_linear_input(x_tokens_list, use_n_blocks, use_avgpool, bag_of...
  class LinearClassifier (line 273) | class LinearClassifier(nn.Module):
    method __init__ (line 276) | def __init__(
    method forward (line 290) | def forward(self, x_tokens_list):
  class AllClassifiers (line 297) | class AllClassifiers(nn.Module):
    method __init__ (line 298) | def __init__(self, classifiers_dict):
    method forward (line 303) | def forward(self, inputs):
    method __len__ (line 306) | def __len__(self):
  class LinearPostprocessor (line 310) | class LinearPostprocessor(nn.Module):
    method __init__ (line 311) | def __init__(self, linear_classifier, class_mapping=None):
    method forward (line 316) | def forward(self, samples, targets):
  function scale_lr (line 324) | def scale_lr(learning_rates, batch_size):
  function setup_linear_classifiers (line 328) | def setup_linear_classifiers(
  function make_eval_data_loader (line 371) | def make_eval_data_loader(
  class Evaluator (line 411) | class Evaluator:
    method __post_init__ (line 422) | def __post_init__(self):
    method _evaluate_linear_classifiers (line 436) | def _evaluate_linear_classifiers(
    method evaluate_and_maybe_save (line 498) | def evaluate_and_maybe_save(
  function make_evaluators (line 531) | def make_evaluators(
  class SchedulerType (line 570) | class SchedulerType(Enum):
    method get_scheduler (line 574) | def get_scheduler(self, optimizer, optim_param_groups, epoch_length, e...
  function setup_linear_training (line 586) | def setup_linear_training(
  function train_linear_classifiers (line 646) | def train_linear_classifiers(
  function eval_linear_with_model (line 749) | def eval_linear_with_model(
  function main (line 1011) | def main(args):

FILE: dinov2/eval/cell_dino/utils.py
  class LossType (line 26) | class LossType(Enum):
  class BagOfChannelsModelWithNormalize (line 31) | class BagOfChannelsModelWithNormalize(nn.Module):
    method __init__ (line 32) | def __init__(self, model, autocast_ctx, avgpool, n_last_blocks=1):
    method forward (line 39) | def forward(self, samples):
  function evaluate_with_accumulate (line 47) | def evaluate_with_accumulate(
  function all_gather_and_flatten (line 118) | def all_gather_and_flatten(tensor_rank):
  function extract_features_cell_dino (line 130) | def extract_features_cell_dino(
  function extract_features_with_dataloader_cell_dino (line 147) | def extract_features_with_dataloader_cell_dino(model, data_loader, sampl...
  function create_linear_input (line 187) | def create_linear_input(x_tokens_list, avgpool=False, use_n_blocks=1):
  function get_target_transform (line 207) | def get_target_transform(dataset) -> Optional[Callable]:
  function get_labels (line 217) | def get_labels(dataset) -> torch.Tensor:
  function get_num_classes (line 239) | def get_num_classes(dataset) -> int:
  function average_metrics (line 249) | def average_metrics(eval_metrics_dict: dict[Any, dict[str, torch.Tensor]...
  function create_class_indices_mapping (line 265) | def create_class_indices_mapping(labels: torch.Tensor) -> dict[int, torc...
  function _shuffle_dataset (line 282) | def _shuffle_dataset(dataset: torch.Tensor, seed: int = 0):
  function _subset_dataset_per_class (line 292) | def _subset_dataset_per_class(
  function _multilabel_rebalance_subset (line 318) | def _multilabel_rebalance_subset(
  function split_train_val_datasets (line 351) | def split_train_val_datasets(train_dataset, split_percentage: float = 0....
  function create_train_dataset_dict (line 374) | def create_train_dataset_dict(
  function extract_features_for_dataset_dict (line 421) | def extract_features_for_dataset_dict(
  function pad_multilabel_and_collate (line 441) | def pad_multilabel_and_collate(batch, pad_value=-1):
  class KnnModule (line 455) | class KnnModule(torch.nn.Module):
    method __init__ (line 465) | def __init__(self, train_features, train_labels, nb_knn, T, device, nu...
    method _get_knn_sims_and_labels (line 480) | def _get_knn_sims_and_labels(self, similarity, train_labels):
    method _similarity_for_rank (line 487) | def _similarity_for_rank(self, features_rank, source_rank):
    method _gather_all_knn_for_rank (line 502) | def _gather_all_knn_for_rank(self, topk_sims, neighbors_labels, target...
    method compute_neighbors (line 520) | def compute_neighbors(self, features_rank):
    method forward (line 528) | def forward(self, features_rank):

FILE: dinov2/eval/depth/models/backbones/vision_transformer.py
  class DinoVisionTransformer (line 12) | class DinoVisionTransformer(BaseModule):
    method __init__ (line 15) | def __init__(self, *args, **kwargs):

FILE: dinov2/eval/depth/models/builder.py
  function build_backbone (line 23) | def build_backbone(cfg):
  function build_neck (line 28) | def build_neck(cfg):
  function build_head (line 33) | def build_head(cfg):
  function build_loss (line 38) | def build_loss(cfg):
  function build_depther (line 43) | def build_depther(cfg, train_cfg=None, test_cfg=None):

FILE: dinov2/eval/depth/models/decode_heads/decode_head.py
  class DepthBaseDecodeHead (line 19) | class DepthBaseDecodeHead(BaseModule, metaclass=ABCMeta):
    method __init__ (line 52) | def __init__(
    method extra_repr (line 105) | def extra_repr(self):
    method forward (line 112) | def forward(self, inputs, img_metas):
    method forward_train (line 116) | def forward_train(self, img, inputs, img_metas, depth_gt, train_cfg):
    method forward_test (line 139) | def forward_test(self, inputs, img_metas, test_cfg):
    method depth_pred (line 155) | def depth_pred(self, feat):
    method losses (line 187) | def losses(self, depth_pred, depth_gt):
    method log_images (line 204) | def log_images(self, img_path, depth_pred, depth_gt, img_meta):

FILE: dinov2/eval/depth/models/decode_heads/dpt_head.py
  class Interpolate (line 18) | class Interpolate(nn.Module):
    method __init__ (line 19) | def __init__(self, scale_factor, mode, align_corners=False):
    method forward (line 26) | def forward(self, x):
  class HeadDepth (line 31) | class HeadDepth(nn.Module):
    method __init__ (line 32) | def __init__(self, features):
    method forward (line 42) | def forward(self, x):
  class ReassembleBlocks (line 47) | class ReassembleBlocks(BaseModule):
    method __init__ (line 59) | def __init__(
    method forward (line 101) | def forward(self, inputs):
  class PreActResidualConvUnit (line 124) | class PreActResidualConvUnit(BaseModule):
    method __init__ (line 135) | def __init__(self, in_channels, act_cfg, norm_cfg, stride=1, dilation=...
    method forward (line 162) | def forward(self, inputs):
  class FeatureFusionBlock (line 169) | class FeatureFusionBlock(BaseModule):
    method __init__ (line 182) | def __init__(self, in_channels, act_cfg, norm_cfg, expand=False, align...
    method forward (line 198) | def forward(self, *inputs):
  class DPTHead (line 213) | class DPTHead(DepthBaseDecodeHead):
    method __init__ (line 227) | def __init__(
    method forward (line 260) | def forward(self, inputs, img_metas):

FILE: dinov2/eval/depth/models/decode_heads/linear_head.py
  class BNHead (line 15) | class BNHead(DepthBaseDecodeHead):
    method __init__ (line 18) | def __init__(self, input_transform="resize_concat", in_index=(0, 1, 2,...
    method _transform_inputs (line 29) | def _transform_inputs(self, inputs):
    method _forward_feature (line 57) | def _forward_feature(self, inputs, img_metas=None, **kwargs):
    method forward (line 84) | def forward(self, inputs, img_metas=None, **kwargs):

FILE: dinov2/eval/depth/models/depther/base.py
  class BaseDepther (line 14) | class BaseDepther(BaseModule, metaclass=ABCMeta):
    method __init__ (line 17) | def __init__(self, init_cfg=None):
    method with_neck (line 22) | def with_neck(self):
    method with_auxiliary_head (line 27) | def with_auxiliary_head(self):
    method with_decode_head (line 32) | def with_decode_head(self):
    method extract_feat (line 37) | def extract_feat(self, imgs):
    method encode_decode (line 42) | def encode_decode(self, img, img_metas):
    method forward_train (line 48) | def forward_train(self, imgs, img_metas, **kwargs):
    method simple_test (line 53) | def simple_test(self, img, img_meta, **kwargs):
    method aug_test (line 58) | def aug_test(self, imgs, img_metas, **kwargs):
    method forward_test (line 62) | def forward_test(self, imgs, img_metas, **kwargs):
    method forward (line 94) | def forward(self, img, img_metas, return_loss=True, **kwargs):
    method train_step (line 109) | def train_step(self, data_batch, optimizer, **kwargs):
    method val_step (line 152) | def val_step(self, data_batch, **kwargs):
    method _parse_losses (line 163) | def _parse_losses(losses):

FILE: dinov2/eval/depth/models/depther/encoder_decoder.py
  function add_prefix (line 15) | def add_prefix(inputs, prefix):
  class DepthEncoderDecoder (line 35) | class DepthEncoderDecoder(BaseDepther):
    method __init__ (line 41) | def __init__(self, backbone, decode_head, neck=None, train_cfg=None, t...
    method _init_decode_head (line 57) | def _init_decode_head(self, decode_head):
    method extract_feat (line 62) | def extract_feat(self, img):
    method encode_decode (line 69) | def encode_decode(self, img, img_metas, rescale=True, size=None):
    method _decode_head_forward_train (line 85) | def _decode_head_forward_train(self, img, x, img_metas, depth_gt, **kw...
    method _decode_head_forward_test (line 93) | def _decode_head_forward_test(self, x, img_metas):
    method forward_dummy (line 99) | def forward_dummy(self, img):
    method forward_train (line 105) | def forward_train(self, img, img_metas, depth_gt, **kwargs):
    method whole_inference (line 133) | def whole_inference(self, img, img_meta, rescale, size=None):
    method slide_inference (line 139) | def slide_inference(self, img, img_meta, rescale):
    method inference (line 173) | def inference(self, img, img_meta, rescale, size=None):
    method simple_test (line 208) | def simple_test(self, img, img_meta, rescale=True):
    method aug_test (line 220) | def aug_test(self, imgs, img_metas, rescale=True):

FILE: dinov2/eval/depth/models/losses/gradientloss.py
  class GradientLoss (line 13) | class GradientLoss(nn.Module):
    method __init__ (line 24) | def __init__(self, valid_mask=True, loss_weight=1.0, max_depth=None, l...
    method gradientloss (line 33) | def gradientloss(self, input, target):
    method forward (line 65) | def forward(self, depth_pred, depth_gt):

FILE: dinov2/eval/depth/models/losses/sigloss.py
  class SigLoss (line 13) | class SigLoss(nn.Module):
    method __init__ (line 26) | def __init__(
    method sigloss (line 42) | def sigloss(self, input, target):
    method forward (line 61) | def forward(self, depth_pred, depth_gt):

FILE: dinov2/eval/depth/ops/wrappers.py
  function resize (line 11) | def resize(input, size=None, scale_factor=None, mode="nearest", align_co...

FILE: dinov2/eval/knn.py
  function get_args_parser (line 29) | def get_args_parser(
  class KnnModule (line 99) | class KnnModule(torch.nn.Module):
    method __init__ (line 109) | def __init__(self, train_features, train_labels, nb_knn, T, device, nu...
    method _get_knn_sims_and_labels (line 124) | def _get_knn_sims_and_labels(self, similarity, train_labels):
    method _similarity_for_rank (line 129) | def _similarity_for_rank(self, features_rank, source_rank):
    method _gather_all_knn_for_rank (line 144) | def _gather_all_knn_for_rank(self, topk_sims, neighbors_labels, target...
    method compute_neighbors (line 162) | def compute_neighbors(self, features_rank):
    method forward (line 170) | def forward(self, features_rank):
  class DictKeysModule (line 187) | class DictKeysModule(torch.nn.Module):
    method __init__ (line 188) | def __init__(self, keys):
    method forward (line 192) | def forward(self, features_dict, targets):
  function create_module_dict (line 198) | def create_module_dict(*, module, n_per_class_list, n_tries, nb_knn, tra...
  function filter_train (line 225) | def filter_train(mapping, n_per_class, seed):
  function create_class_indices_mapping (line 234) | def create_class_indices_mapping(labels):
  class ModuleDictWithForward (line 240) | class ModuleDictWithForward(torch.nn.ModuleDict):
    method forward (line 241) | def forward(self, *args, **kwargs):
  function eval_knn (line 245) | def eval_knn(
  function eval_knn_with_model (line 318) | def eval_knn_with_model(
  function main (line 379) | def main(args):

FILE: dinov2/eval/linear.py
  function get_args_parser (line 33) | def get_args_parser(
  function has_ddp_wrapper (line 155) | def has_ddp_wrapper(m: nn.Module) -> bool:
  function remove_ddp_wrapper (line 159) | def remove_ddp_wrapper(m: nn.Module) -> nn.Module:
  function _pad_and_collate (line 163) | def _pad_and_collate(batch):
  function create_linear_input (line 171) | def create_linear_input(x_tokens_list, use_n_blocks, use_avgpool):
  class LinearClassifier (line 186) | class LinearClassifier(nn.Module):
    method __init__ (line 189) | def __init__(self, out_dim, use_n_blocks, use_avgpool, num_classes=1000):
    method forward (line 199) | def forward(self, x_tokens_list):
  class AllClassifiers (line 204) | class AllClassifiers(nn.Module):
    method __init__ (line 205) | def __init__(self, classifiers_dict):
    method forward (line 210) | def forward(self, inputs):
    method __len__ (line 213) | def __len__(self):
  class LinearPostprocessor (line 217) | class LinearPostprocessor(nn.Module):
    method __init__ (line 218) | def __init__(self, linear_classifier, class_mapping=None):
    method forward (line 223) | def forward(self, samples, targets):
  function scale_lr (line 231) | def scale_lr(learning_rates, batch_size):
  function setup_linear_classifiers (line 235) | def setup_linear_classifiers(sample_output, n_last_blocks_list, learning...
  function evaluate_linear_classifiers (line 260) | def evaluate_linear_classifiers(
  function eval_linear (line 313) | def eval_linear(
  function make_eval_data_loader (line 411) | def make_eval_data_loader(test_dataset_str, batch_size, num_workers, met...
  function test_on_datasets (line 429) | def test_on_datasets(
  function run_eval_linear (line 463) | def run_eval_linear(
  function main (line 595) | def main(args):

FILE: dinov2/eval/log_regression.py
  function get_args_parser (line 38) | def get_args_parser(
  class LogRegModule (line 109) | class LogRegModule(nn.Module):
    method __init__ (line 110) | def __init__(
    method forward (line 129) | def forward(self, samples, targets):
    method fit (line 137) | def fit(self, train_features, train_labels):
  function evaluate_model (line 147) | def evaluate_model(*, logreg_model, logreg_metric, test_data_loader, dev...
  function train_for_C (line 153) | def train_for_C(*, C, max_iter, train_features, train_labels, dtype=torc...
  function train_and_evaluate (line 159) | def train_and_evaluate(
  function sweep_C_values (line 187) | def sweep_C_values(
  function eval_log_regression (line 252) | def eval_log_regression(
  function eval_log_regression_with_model (line 362) | def eval_log_regression_with_model(
  function main (line 423) | def main(args):

FILE: dinov2/eval/metrics.py
  class MetricType (line 20) | class MetricType(Enum):
    method accuracy_averaging (line 29) | def accuracy_averaging(self):
    method __str__ (line 32) | def __str__(self):
  class AccuracyAveraging (line 36) | class AccuracyAveraging(Enum):
    method __str__ (line 41) | def __str__(self):
  function build_metric (line 45) | def build_metric(metric_type: MetricType, *, num_classes: int, ks: Optio...
  function build_topk_accuracy_metric (line 65) | def build_topk_accuracy_metric(average_type: AccuracyAveraging, num_clas...
  function build_topk_imagenet_real_accuracy_metric (line 72) | def build_topk_imagenet_real_accuracy_metric(num_classes: int, ks: tuple...
  class ImageNetReaLAccuracy (line 77) | class ImageNetReaLAccuracy(Metric):
    method __init__ (line 82) | def __init__(
    method update (line 93) | def update(self, preds: Tensor, target: Tensor) -> None:  # type: ignore
    method compute (line 117) | def compute(self) -> Tensor:

FILE: dinov2/eval/segmentation/hooks/optimizer.py
  class DistOptimizerHook (line 15) | class DistOptimizerHook(OptimizerHook):
    method __init__ (line 18) | def __init__(self, update_interval=1, grad_clip=None, coalesce=True, b...
    method before_run (line 25) | def before_run(self, runner):
    method after_train_iter (line 28) | def after_train_iter(self, runner):

FILE: dinov2/eval/segmentation/models/backbones/vision_transformer.py
  class DinoVisionTransformer (line 11) | class DinoVisionTransformer(BaseModule):
    method __init__ (line 14) | def __init__(

FILE: dinov2/eval/segmentation/models/decode_heads/linear_head.py
  class BNHead (line 15) | class BNHead(BaseDecodeHead):
    method __init__ (line 18) | def __init__(self, resize_factors=None, **kwargs):
    method _forward_feature (line 24) | def _forward_feature(self, inputs):
    method _transform_inputs (line 42) | def _transform_inputs(self, inputs):
    method forward (line 86) | def forward(self, inputs):

FILE: dinov2/eval/segmentation_m2f/core/anchor/builder.py
  function build_prior_generator (line 15) | def build_prior_generator(cfg, default_args=None):
  function build_anchor_generator (line 19) | def build_anchor_generator(cfg, default_args=None):

FILE: dinov2/eval/segmentation_m2f/core/anchor/point_generator.py
  class MlvlPointGenerator (line 14) | class MlvlPointGenerator:
    method __init__ (line 25) | def __init__(self, strides, offset=0.5):
    method num_levels (line 30) | def num_levels(self):
    method num_base_priors (line 35) | def num_base_priors(self):
    method _meshgrid (line 40) | def _meshgrid(self, x, y, row_major=True):
    method grid_priors (line 50) | def grid_priors(self, featmap_sizes, dtype=torch.float32, device="cuda...
    method single_level_grid_priors (line 82) | def single_level_grid_priors(self, featmap_size, level_idx, dtype=torc...
    method valid_flags (line 130) | def valid_flags(self, featmap_sizes, pad_shape, device="cuda"):
    method single_level_valid_flags (line 156) | def single_level_valid_flags(self, featmap_size, valid_size, device="c...
    method sparse_priors (line 182) | def sparse_priors(self, prior_idxs, featmap_size, level_idx, dtype=tor...

FILE: dinov2/eval/segmentation_m2f/core/box/builder.py
  function build_sampler (line 12) | def build_sampler(cfg, **default_args):
  function build_bbox_coder (line 17) | def build_bbox_coder(cfg, **default_args):

FILE: dinov2/eval/segmentation_m2f/core/box/samplers/base_sampler.py
  class BaseSampler (line 13) | class BaseSampler(metaclass=ABCMeta):
    method __init__ (line 16) | def __init__(self, num, pos_fraction, neg_pos_ub=-1, add_gt_as_proposa...
    method _sample_pos (line 25) | def _sample_pos(self, assign_result, num_expected, **kwargs):
    method _sample_neg (line 30) | def _sample_neg(self, assign_result, num_expected, **kwargs):
    method sample (line 34) | def sample(self, assign_result, bboxes, gt_bboxes, gt_labels=None, **k...

FILE: dinov2/eval/segmentation_m2f/core/box/samplers/mask_pseudo_sampler.py
  class MaskPseudoSampler (line 17) | class MaskPseudoSampler(BaseSampler):
    method __init__ (line 20) | def __init__(self, **kwargs):
    method _sample_pos (line 23) | def _sample_pos(self, **kwargs):
    method _sample_neg (line 27) | def _sample_neg(self, **kwargs):
    method sample (line 31) | def sample(self, assign_result, masks, gt_masks, **kwargs):

FILE: dinov2/eval/segmentation_m2f/core/box/samplers/mask_sampling_result.py
  class MaskSamplingResult (line 14) | class MaskSamplingResult(SamplingResult):
    method __init__ (line 17) | def __init__(self, pos_inds, neg_inds, masks, gt_masks, assign_result,...
    method masks (line 40) | def masks(self):
    method __nice__ (line 44) | def __nice__(self):
    method info (line 53) | def info(self):

FILE: dinov2/eval/segmentation_m2f/core/box/samplers/sampling_result.py
  class SamplingResult (line 9) | class SamplingResult:
    method __init__ (line 28) | def __init__(self, pos_inds, neg_inds, bboxes, gt_bboxes, assign_resul...
    method bboxes (line 54) | def bboxes(self):
    method to (line 58) | def to(self, device):
    method __nice__ (line 73) | def __nice__(self):
    method info (line 82) | def info(self):
    method random (line 95) | def random(cls, rng=None, **kwargs):

FILE: dinov2/eval/segmentation_m2f/core/utils/dist_utils.py
  function reduce_mean (line 9) | def reduce_mean(tensor):

FILE: dinov2/eval/segmentation_m2f/core/utils/misc.py
  function multi_apply (line 9) | def multi_apply(func, *args, **kwargs):
  function add_prefix (line 31) | def add_prefix(inputs, prefix):

FILE: dinov2/eval/segmentation_m2f/models/backbones/adapter_modules.py
  function get_reference_points (line 16) | def get_reference_points(spatial_shapes, device):
  function deform_inputs (line 32) | def deform_inputs(x, patch_size):
  class ConvFFN (line 49) | class ConvFFN(nn.Module):
    method __init__ (line 50) | def __init__(self, in_features, hidden_features=None, out_features=Non...
    method forward (line 60) | def forward(self, x, H, W):
  class DWConv (line 70) | class DWConv(nn.Module):
    method __init__ (line 71) | def __init__(self, dim=768):
    method forward (line 75) | def forward(self, x, H, W):
  class Extractor (line 88) | class Extractor(nn.Module):
    method __init__ (line 89) | def __init__(
    method forward (line 116) | def forward(self, query, reference_points, feat, spatial_shapes, level...
  class Injector (line 136) | class Injector(nn.Module):
    method __init__ (line 137) | def __init__(
    method forward (line 157) | def forward(self, query, reference_points, feat, spatial_shapes, level...
  class InteractionBlock (line 173) | class InteractionBlock(nn.Module):
    method __init__ (line 174) | def __init__(
    method forward (line 235) | def forward(self, x, c, blocks, deform_inputs1, deform_inputs2, H_c, W...
  class InteractionBlockWithCls (line 268) | class InteractionBlockWithCls(nn.Module):
    method __init__ (line 269) | def __init__(
    method forward (line 330) | def forward(self, x, c, cls, blocks, deform_inputs1, deform_inputs2, H...
  class SpatialPriorModule (line 374) | class SpatialPriorModule(nn.Module):
    method __init__ (line 375) | def __init__(self, inplanes=64, embed_dim=384, with_cp=False):
    method forward (line 419) | def forward(self, x):

FILE: dinov2/eval/segmentation_m2f/models/backbones/drop_path.py
  function drop_path (line 13) | def drop_path(x, drop_prob: float = 0.0, training: bool = False):
  class DropPath (line 24) | class DropPath(nn.Module):
    method __init__ (line 27) | def __init__(self, drop_prob: float = 0.0):
    method forward (line 31) | def forward(self, x):

FILE: dinov2/eval/segmentation_m2f/models/backbones/vit.py
  function to_2tuple (line 48) | def to_2tuple(x):
  class Mlp (line 52) | class Mlp(nn.Module):
    method __init__ (line 53) | def __init__(
    method forward (line 70) | def forward(self, x: Tensor) -> Tensor:
  class SwiGLUFFN (line 79) | class SwiGLUFFN(nn.Module):
    method __init__ (line 80) | def __init__(
    method forward (line 98) | def forward(self, x: Tensor) -> Tensor:
  class PatchEmbed (line 105) | class PatchEmbed(nn.Module):
    method __init__ (line 108) | def __init__(
    method forward (line 123) | def forward(self, x):
  class Attention (line 132) | class Attention(nn.Module):
    method __init__ (line 133) | def __init__(self, dim, num_heads=8, qkv_bias=False, attn_drop=0.0, pr...
    method forward (line 144) | def forward(self, x, H, W):
  class MemEffAttention (line 159) | class MemEffAttention(nn.Module):
    method __init__ (line 160) | def __init__(
    method forward (line 178) | def forward(self, x: Tensor, H, W) -> Tensor:
  function window_partition (line 194) | def window_partition(x, window_size):
  function window_reverse (line 208) | def window_reverse(windows, window_size, H, W):
  class WindowedAttention (line 224) | class WindowedAttention(nn.Module):
    method __init__ (line 225) | def __init__(
    method forward (line 240) | def forward(self, x, H, W):
  class Block (line 319) | class Block(nn.Module):
    method __init__ (line 320) | def __init__(
    method forward (line 368) | def forward(self, x, H, W):
  class TIMMVisionTransformer (line 386) | class TIMMVisionTransformer(BaseModule):
    method __init__ (line 396) | def __init__(
    method init_weights (line 503) | def init_weights(self, pretrained=None):
    method forward_features (line 508) | def forward_features(self, x):
    method forward (line 522) | def forward(self, x):
    method resize_pos_embed (line 527) | def resize_pos_embed(pos_embed, input_shpae, pos_shape, mode):

FILE: dinov2/eval/segmentation_m2f/models/backbones/vit_adapter.py
  class ViTAdapter (line 20) | class ViTAdapter(TIMMVisionTransformer):
    method __init__ (line 21) | def __init__(
    method _init_weights (line 92) | def _init_weights(self, m):
    method _get_pos_embed (line 107) | def _get_pos_embed(self, pos_embed, H, W):
    method _init_deform_weights (line 118) | def _init_deform_weights(self, m):
    method _add_level_embed (line 122) | def _add_level_embed(self, c2, c3, c4):
    method forward (line 128) | def forward(self, x):

FILE: dinov2/eval/segmentation_m2f/models/builder.py
  function build_match_cost (line 13) | def build_match_cost(cfg):
  function build_assigner (line 18) | def build_assigner(cfg):
  function build_transformer (line 23) | def build_transformer(cfg):

FILE: dinov2/eval/segmentation_m2f/models/decode_heads/mask2former_head.py
  class Mask2FormerHead (line 24) | class Mask2FormerHead(BaseDecodeHead):
    method __init__ (line 61) | def __init__(
    method init_weights (line 141) | def init_weights(self):
    method get_targets (line 152) | def get_targets(self, cls_scores_list, mask_preds_list, gt_labels_list...
    method _get_target_single (line 200) | def _get_target_single(self, cls_score, mask_pred, gt_labels, gt_masks...
    method loss_single (line 258) | def loss_single(self, cls_scores, mask_preds, gt_labels_list, gt_masks...
    method loss (line 342) | def loss(self, all_cls_scores, all_mask_preds, gt_labels_list, gt_mask...
    method forward_head (line 383) | def forward_head(self, decoder_out, mask_feature, attn_mask_target_size):
    method forward (line 420) | def forward(self, feats, img_metas):
    method forward_train (line 494) | def forward_train(self, x, img_metas, gt_semantic_seg, gt_labels, gt_m...
    method forward_test (line 522) | def forward_test(self, inputs, img_metas, test_cfg):

FILE: dinov2/eval/segmentation_m2f/models/losses/cross_entropy_loss.py
  function cross_entropy (line 15) | def cross_entropy(
  function _expand_onehot_labels (line 65) | def _expand_onehot_labels(labels, label_weights, target_shape, ignore_in...
  function binary_cross_entropy (line 88) | def binary_cross_entropy(
  function mask_cross_entropy (line 149) | def mask_cross_entropy(
  class CrossEntropyLoss (line 182) | class CrossEntropyLoss(nn.Module):
    method __init__ (line 203) | def __init__(
    method extra_repr (line 237) | def extra_repr(self):
    method forward (line 242) | def forward(
    method loss_name (line 267) | def loss_name(self):

FILE: dinov2/eval/segmentation_m2f/models/losses/dice_loss.py
  function dice_loss (line 12) | def dice_loss(pred, target, weight=None, eps=1e-3, reduction="mean", avg...
  function naive_dice_loss (line 46) | def naive_dice_loss(pred, target, weight=None, eps=1e-3, reduction="mean...
  class DiceLoss (line 79) | class DiceLoss(nn.Module):
    method __init__ (line 80) | def __init__(self, use_sigmoid=True, activate=True, reduction="mean", ...
    method forward (line 116) | def forward(self, pred, target, weight=None, reduction_override=None, ...

FILE: dinov2/eval/segmentation_m2f/models/losses/match_costs.py
  class ClassificationCost (line 13) | class ClassificationCost:
    method __init__ (line 33) | def __init__(self, weight=1.0):
    method __call__ (line 36) | def __call__(self, cls_pred, gt_labels):
  class DiceCost (line 56) | class DiceCost:
    method __init__ (line 66) | def __init__(self, weight=1.0, pred_act=False, eps=1e-3):
    method binary_mask_dice_loss (line 71) | def binary_mask_dice_loss(self, mask_preds, gt_masks):
    method __call__ (line 89) | def __call__(self, mask_preds, gt_masks):
  class CrossEntropyLossCost (line 105) | class CrossEntropyLossCost:
    method __init__ (line 114) | def __init__(self, weight=1.0, use_sigmoid=True):
    method _binary_cross_entropy (line 119) | def _binary_cross_entropy(self, cls_pred, gt_labels):
    method __call__ (line 139) | def __call__(self, cls_pred, gt_labels):

FILE: dinov2/eval/segmentation_m2f/models/plugins/msdeformattn_pixel_decoder.py
  class MSDeformAttnPixelDecoder (line 18) | class MSDeformAttnPixelDecoder(BaseModule):
    method __init__ (line 42) | def __init__(
    method init_weights (line 124) | def init_weights(self):
    method forward (line 146) | def forward(self, feats):

FILE: dinov2/eval/segmentation_m2f/models/segmentors/encoder_decoder_mask2former.py
  class EncoderDecoderMask2Former (line 17) | class EncoderDecoderMask2Former(BaseSegmentor):
    method __init__ (line 25) | def __init__(
    method _init_decode_head (line 53) | def _init_decode_head(self, decode_head):
    method _init_auxiliary_head (line 59) | def _init_auxiliary_head(self, auxiliary_head):
    method extract_feat (line 69) | def extract_feat(self, img):
    method encode_decode (line 76) | def encode_decode(self, img, img_metas):
    method _decode_head_forward_train (line 84) | def _decode_head_forward_train(self, x, img_metas, gt_semantic_seg, **...
    method _decode_head_forward_test (line 93) | def _decode_head_forward_test(self, x, img_metas):
    method _auxiliary_head_forward_train (line 99) | def _auxiliary_head_forward_train(self, x, img_metas, gt_semantic_seg):
    method forward_dummy (line 113) | def forward_dummy(self, img):
    method forward_train (line 119) | def forward_train(self, img, img_metas, gt_semantic_seg, **kwargs):
    method slide_inference (line 149) | def slide_inference(self, img, img_meta, rescale):
    method whole_inference (line 192) | def whole_inference(self, img, img_meta, rescale):
    method inference (line 206) | def inference(self, img, img_meta, rescale):
    method simple_test (line 241) | def simple_test(self, img, img_meta, rescale=True):
    method aug_test (line 254) | def aug_test(self, imgs, img_metas, rescale=True):

FILE: dinov2/eval/segmentation_m2f/models/utils/assigner.py
  class AssignResult (line 18) | class AssignResult(metaclass=ABCMeta):
    method __init__ (line 21) | def __init__(self, num_gts, gt_inds, labels):
    method info (line 27) | def info(self):
  class BaseAssigner (line 36) | class BaseAssigner(metaclass=ABCMeta):
    method assign (line 40) | def assign(self, masks, gt_masks, gt_masks_ignore=None, gt_labels=None):
  class MaskHungarianAssigner (line 46) | class MaskHungarianAssigner(BaseAssigner):
    method __init__ (line 67) | def __init__(
    method assign (line 77) | def assign(self, cls_pred, mask_pred, gt_labels, gt_masks, img_meta, g...

FILE: dinov2/eval/segmentation_m2f/models/utils/point_sample.py
  function get_uncertainty (line 10) | def get_uncertainty(mask_pred, labels):
  function get_uncertain_point_coords_with_randomness (line 36) | def get_uncertain_point_coords_with_randomness(

FILE: dinov2/eval/segmentation_m2f/models/utils/positional_encoding.py
  class SinePositionalEncoding (line 15) | class SinePositionalEncoding(BaseModule):
    method __init__ (line 40) | def __init__(
    method forward (line 55) | def forward(self, mask):
    method __repr__ (line 87) | def __repr__(self):
  class LearnedPositionalEncoding (line 99) | class LearnedPositionalEncoding(BaseModule):
    method __init__ (line 113) | def __init__(self, num_feats, row_num_embed=50, col_num_embed=50, init...
    method forward (line 121) | def forward(self, mask):
    method __repr__ (line 146) | def __repr__(self):

FILE: dinov2/eval/segmentation_m2f/models/utils/transformer.py
  class AdaptivePadding (line 35) | class AdaptivePadding(nn.Module):
    method __init__ (line 66) | def __init__(self, kernel_size=1, stride=1, dilation=1, padding="corne...
    method get_pad_shape (line 82) | def get_pad_shape(self, input_shape):
    method forward (line 92) | def forward(self, x):
  class PatchMerging (line 102) | class PatchMerging(BaseModule):
    method __init__ (line 133) | def __init__(
    method forward (line 178) | def forward(self, x, input_size):
  function inverse_sigmoid (line 223) | def inverse_sigmoid(x, eps=1e-5):
  class FFN (line 243) | class FFN(BaseModule):
    method __init__ (line 265) | def __init__(
    method forward (line 298) | def forward(self, x, identity=None):
  class DetrTransformerDecoderLayer (line 316) | class DetrTransformerDecoderLayer(BaseTransformerLayer):
    method __init__ (line 338) | def __init__(
  class DetrTransformerEncoder (line 364) | class DetrTransformerEncoder(TransformerLayerSequence):
    method __init__ (line 372) | def __init__(self, *args, post_norm_cfg=dict(type="LN"), **kwargs):
    method forward (line 380) | def forward(self, *args, **kwargs):
  class DetrTransformerDecoder (line 393) | class DetrTransformerDecoder(TransformerLayerSequence):
    method __init__ (line 402) | def __init__(self, *args, post_norm_cfg=dict(type="LN"), return_interm...
    method forward (line 411) | def forward(self, query, *args, **kwargs):
  class Transformer (line 441) | class Transformer(BaseModule):
    method __init__ (line 463) | def __init__(self, encoder=None, decoder=None, init_cfg=None):
    method init_weights (line 469) | def init_weights(self):
    method forward (line 476) | def forward(self, x, mask, query_embed, pos_embed):
  class DeformableDetrTransformerDecoder (line 517) | class DeformableDetrTransformerDecoder(TransformerLayerSequence):
    method __init__ (line 526) | def __init__(self, *args, return_intermediate=False, **kwargs):
    method forward (line 531) | def forward(self, query, *args, reference_points=None, valid_ratios=No...
  class DeformableDetrTransformer (line 592) | class DeformableDetrTransformer(Transformer):
    method __init__ (line 604) | def __init__(self, as_two_stage=False, num_feature_levels=4, two_stage...
    method init_layers (line 612) | def init_layers(self):
    method init_weights (line 624) | def init_weights(self):
    method gen_encoder_output_proposals (line 636) | def gen_encoder_output_proposals(self, memory, memory_padding_mask, sp...
    method get_reference_points (line 694) | def get_reference_points(spatial_shapes, valid_ratios, device):
    method get_valid_ratio (line 724) | def get_valid_ratio(self, mask):
    method get_proposal_pos_embed (line 734) | def get_proposal_pos_embed(self, proposals, num_pos_feats=128, tempera...
    method forward (line 747) | def forward(
  class DynamicConv (line 886) | class DynamicConv(BaseModule):
    method __init__ (line 913) | def __init__(
    method forward (line 948) | def forward(self, param_feature, input_feature):

FILE: dinov2/eval/segmentation_m2f/ops/modules/ms_deform_attn.py
  class MSDeformAttnFunction (line 17) | class MSDeformAttnFunction(Function):
    method forward (line 20) | def forward(
  function ms_deform_attn_core_pytorch (line 33) | def ms_deform_attn_core_pytorch(value, value_spatial_shapes, sampling_lo...
  function _is_power_of_2 (line 57) | def _is_power_of_2(n):
  class MSDeformAttn (line 63) | class MSDeformAttn(nn.Module):
    method __init__ (line 64) | def __init__(self, d_model=256, n_levels=4, n_heads=8, n_points=4, rat...
    method _reset_parameters (line 99) | def _reset_parameters(self):
    method forward (line 120) | def forward(

FILE: dinov2/eval/setup.py
  function get_args_parser (line 17) | def get_args_parser(
  function get_autocast_dtype (line 52) | def get_autocast_dtype(config):
  function build_model_for_eval (line 62) | def build_model_for_eval(config, pretrained_weights):
  function setup_and_build_model (line 70) | def setup_and_build_model(args) -> Tuple[Any, torch.dtype]:

FILE: dinov2/eval/utils.py
  class ModelWithNormalize (line 21) | class ModelWithNormalize(torch.nn.Module):
    method __init__ (line 22) | def __init__(self, model):
    method forward (line 26) | def forward(self, samples):
  class ModelWithIntermediateLayers (line 30) | class ModelWithIntermediateLayers(nn.Module):
    method __init__ (line 31) | def __init__(self, feature_model, n_last_blocks, autocast_ctx):
    method forward (line 38) | def forward(self, images):
  function evaluate (line 48) | def evaluate(
  function all_gather_and_flatten (line 86) | def all_gather_and_flatten(tensor_rank):
  function extract_features (line 98) | def extract_features(model, dataset, batch_size, num_workers, gather_on_...
  function extract_features_with_dataloader (line 113) | def extract_features_with_dataloader(model, data_loader, sample_count, g...

FILE: dinov2/fsdp/__init__.py
  function get_fsdp_wrapper (line 22) | def get_fsdp_wrapper(model_cfg, modules_to_wrap=set()):
  function is_fsdp (line 57) | def is_fsdp(x):
  function is_sharded_fsdp (line 61) | def is_sharded_fsdp(x):
  function free_if_fsdp (line 65) | def free_if_fsdp(x):
  function get_fsdp_modules (line 72) | def get_fsdp_modules(x):
  function reshard_fsdp_model (line 76) | def reshard_fsdp_model(x):
  function rankstr (line 81) | def rankstr():
  class FSDPCheckpointer (line 85) | class FSDPCheckpointer(Checkpointer):
    method save (line 86) | def save(self, name: str, **kwargs: Any) -> None:
    method load (line 114) | def load(self, *args, **kwargs):
    method has_checkpoint (line 118) | def has_checkpoint(self) -> bool:
    method get_checkpoint_file (line 126) | def get_checkpoint_file(self) -> str:
    method tag_last_checkpoint (line 143) | def tag_last_checkpoint(self, last_filename_basename: str) -> None:

FILE: dinov2/hub/backbones.py
  class Weights (line 16) | class Weights(Enum):
  function is_url (line 21) | def is_url(path: str) -> bool:
  function convert_path_or_url_to_url (line 26) | def convert_path_or_url_to_url(path: str) -> str:
  function _make_dinov2_model (line 32) | def _make_dinov2_model(
  function dinov2_vits14 (line 82) | def dinov2_vits14(*, pretrained: bool = True, weights: Union[Weights, st...
  function dinov2_vitb14 (line 89) | def dinov2_vitb14(*, pretrained: bool = True, weights: Union[Weights, st...
  function dinov2_vitl14 (line 96) | def dinov2_vitl14(*, pretrained: bool = True, weights: Union[Weights, st...
  function dinov2_vitg14 (line 103) | def dinov2_vitg14(*, pretrained: bool = True, weights: Union[Weights, st...
  function dinov2_vits14_reg (line 116) | def dinov2_vits14_reg(*, pretrained: bool = True, weights: Union[Weights...
  function dinov2_vitb14_reg (line 131) | def dinov2_vitb14_reg(*, pretrained: bool = True, weights: Union[Weights...
  function dinov2_vitl14_reg (line 146) | def dinov2_vitl14_reg(*, pretrained: bool = True, weights: Union[Weights...
  function dinov2_vitg14_reg (line 161) | def dinov2_vitg14_reg(*, pretrained: bool = True, weights: Union[Weights...

FILE: dinov2/hub/cell_dino/backbones.py
  class Weights (line 12) | class Weights(Enum):
  function _make_cell_dino_model (line 16) | def _make_cell_dino_model(
  function cell_dino_hpa_vitl16 (line 67) | def cell_dino_hpa_vitl16(
  function cell_dino_hpa_vitl14 (line 96) | def cell_dino_hpa_vitl14(
  function cell_dino_cp_vits8 (line 125) | def cell_dino_cp_vits8(
  function channel_adaptive_dino_vitl16 (line 154) | def channel_adaptive_dino_vitl16(

FILE: dinov2/hub/classifiers.py
  class Weights (line 16) | class Weights(Enum):
  function _make_dinov2_linear_classification_head (line 20) | def _make_dinov2_linear_classification_head(
  class _LinearClassifierWrapper (line 52) | class _LinearClassifierWrapper(nn.Module):
    method __init__ (line 53) | def __init__(self, *, backbone: nn.Module, linear_head: nn.Module, lay...
    method forward (line 59) | def forward(self, x):
  function _make_dinov2_linear_classifier (line 86) | def _make_dinov2_linear_classifier(
  function dinov2_vits14_lc (line 121) | def dinov2_vits14_lc(
  function dinov2_vitb14_lc (line 140) | def dinov2_vitb14_lc(
  function dinov2_vitl14_lc (line 159) | def dinov2_vitl14_lc(
  function dinov2_vitg14_lc (line 178) | def dinov2_vitg14_lc(
  function dinov2_vits14_reg_lc (line 198) | def dinov2_vits14_reg_lc(
  function dinov2_vitb14_reg_lc (line 216) | def dinov2_vitb14_reg_lc(
  function dinov2_vitl14_reg_lc (line 234) | def dinov2_vitl14_reg_lc(
  function dinov2_vitg14_reg_lc (line 252) | def dinov2_vitg14_reg_lc(

FILE: dinov2/hub/depth/decode_heads.py
  function _imdenormalize (line 18) | def _imdenormalize(img, mean, std, to_bgr=True):
  class DepthBaseDecodeHead (line 29) | class DepthBaseDecodeHead(nn.Module):
    method __init__ (line 61) | def __init__(
    method forward (line 108) | def forward(self, inputs, img_metas):
    method forward_train (line 112) | def forward_train(self, img, inputs, img_metas, depth_gt):
    method forward_test (line 134) | def forward_test(self, inputs, img_metas):
    method depth_pred (line 149) | def depth_pred(self, feat):
    method losses (line 180) | def losses(self, depth_pred, depth_gt):
    method log_images (line 197) | def log_images(self, img_path, depth_pred, depth_gt, img_meta):
  class BNHead (line 223) | class BNHead(DepthBaseDecodeHead):
    method __init__ (line 226) | def __init__(self, input_transform="resize_concat", in_index=(0, 1, 2,...
    method _transform_inputs (line 237) | def _transform_inputs(self, inputs):
    method _forward_feature (line 265) | def _forward_feature(self, inputs, img_metas=None, **kwargs):
    method forward (line 292) | def forward(self, inputs, img_metas=None, **kwargs):
  class ConvModule (line 299) | class ConvModule(nn.Module):
    method __init__ (line 352) | def __init__(
    method norm (line 453) | def norm(self):
    method init_weights (line 459) | def init_weights(self):
    method forward (line 486) | def forward(self, x, activate=True, norm=True):
  class Interpolate (line 499) | class Interpolate(nn.Module):
    method __init__ (line 500) | def __init__(self, scale_factor, mode, align_corners=False):
    method forward (line 507) | def forward(self, x):
  class HeadDepth (line 512) | class HeadDepth(nn.Module):
    method __init__ (line 513) | def __init__(self, features):
    method forward (line 523) | def forward(self, x):
  class ReassembleBlocks (line 528) | class ReassembleBlocks(nn.Module):
    method __init__ (line 539) | def __init__(self, in_channels=768, out_channels=[96, 192, 384, 768], ...
    method forward (line 577) | def forward(self, inputs):
  class PreActResidualConvUnit (line 600) | class PreActResidualConvUnit(nn.Module):
    method __init__ (line 610) | def __init__(self, in_channels, act_layer, norm_layer, stride=1, dilat...
    method forward (line 637) | def forward(self, inputs):
  class FeatureFusionBlock (line 644) | class FeatureFusionBlock(nn.Module):
    method __init__ (line 656) | def __init__(self, in_channels, act_layer, norm_layer, expand=False, a...
    method forward (line 676) | def forward(self, *inputs):
  class DPTHead (line 690) | class DPTHead(DepthBaseDecodeHead):
    method __init__ (line 704) | def __init__(
    method forward (line 737) | def forward(self, inputs, img_metas):

FILE: dinov2/hub/depth/encoder_decoder.py
  function add_prefix (line 15) | def add_prefix(inputs, prefix):
  class DepthEncoderDecoder (line 34) | class DepthEncoderDecoder(nn.Module):
    method __init__ (line 40) | def __init__(self, backbone, decode_head):
    method extract_feat (line 47) | def extract_feat(self, img):
    method encode_decode (line 51) | def encode_decode(self, img, img_metas, rescale=True, size=None):
    method _decode_head_forward_train (line 67) | def _decode_head_forward_train(self, img, x, img_metas, depth_gt, **kw...
    method _decode_head_forward_test (line 75) | def _decode_head_forward_test(self, x, img_metas):
    method forward_dummy (line 81) | def forward_dummy(self, img):
    method forward_train (line 87) | def forward_train(self, img, img_metas, depth_gt, **kwargs):
    method whole_inference (line 115) | def whole_inference(self, img, img_meta, rescale, size=None):
    method slide_inference (line 119) | def slide_inference(self, img, img_meta, rescale, stride, crop_size):
    method inference (line 153) | def inference(self, img, img_meta, rescale, size=None, mode="whole"):
    method simple_test (line 188) | def simple_test(self, img, img_meta, rescale=True):
    method aug_test (line 200) | def aug_test(self, imgs, img_metas, rescale=True):
    method forward_test (line 218) | def forward_test(self, imgs, img_metas, **kwargs):
    method forward (line 249) | def forward(self, img, img_metas, return_loss=True, **kwargs):
    method train_step (line 264) | def train_step(self, data_batch, optimizer, **kwargs):
    method val_step (line 307) | def val_step(self, data_batch, **kwargs):
    method _parse_losses (line 318) | def _parse_losses(losses):

FILE: dinov2/hub/depth/ops.py
  function resize (line 11) | def resize(input, size=None, scale_factor=None, mode="nearest", align_co...

FILE: dinov2/hub/depthers.py
  class Weights (line 17) | class Weights(Enum):
  function _get_depth_range (line 22) | def _get_depth_range(pretrained: bool, weights: Weights = Weights.NYU) -...
  function _make_dinov2_linear_depth_head (line 36) | def _make_dinov2_linear_depth_head(
  function _make_dinov2_linear_depther (line 70) | def _make_dinov2_linear_depther(
  function dinov2_vits14_ld (line 143) | def dinov2_vits14_ld(*, layers: int = 4, pretrained: bool = True, weight...
  function dinov2_vitb14_ld (line 149) | def dinov2_vitb14_ld(*, layers: int = 4, pretrained: bool = True, weight...
  function dinov2_vitl14_ld (line 155) | def dinov2_vitl14_ld(*, layers: int = 4, pretrained: bool = True, weight...
  function dinov2_vitg14_ld (line 161) | def dinov2_vitg14_ld(*, layers: int = 4, pretrained: bool = True, weight...
  function _make_dinov2_dpt_depth_head (line 167) | def _make_dinov2_dpt_depth_head(*, embed_dim: int, min_depth: float, max...
  function _make_dinov2_dpt_depther (line 180) | def _make_dinov2_dpt_depther(
  function dinov2_vits14_dd (line 231) | def dinov2_vits14_dd(*, pretrained: bool = True, weights: Union[Weights,...
  function dinov2_vitb14_dd (line 235) | def dinov2_vitb14_dd(*, pretrained: bool = True, weights: Union[Weights,...
  function dinov2_vitl14_dd (line 239) | def dinov2_vitl14_dd(*, pretrained: bool = True, weights: Union[Weights,...
  function dinov2_vitg14_dd (line 243) | def dinov2_vitg14_dd(*, pretrained: bool = True, weights: Union[Weights,...

FILE: dinov2/hub/dinotxt.py
  function dinov2_vitl14_reg4_dinotxt_tet1280d20h24l (line 13) | def dinov2_vitl14_reg4_dinotxt_tet1280d20h24l():
  function get_tokenizer (line 70) | def get_tokenizer():

FILE: dinov2/hub/text/dinotxt_model.py
  class DinoTxtConfig (line 19) | class DinoTxtConfig:
  class DinoTxt (line 42) | class DinoTxt(nn.Module):
    method __init__ (line 43) | def __init__(
    method init_weights (line 77) | def init_weights(self):
    method get_visual_class_and_patch_tokens (line 81) | def get_visual_class_and_patch_tokens(self, image: Tensor) -> Tuple[Te...
    method encode_image (line 84) | def encode_image(
    method encode_text (line 104) | def encode_text(self, text: Tensor, normalize: bool = False) -> Tensor:
    method get_logits (line 120) | def get_logits(self, image: Tensor, text: Tensor) -> Tuple[Tensor, Ten...
    method forward (line 127) | def forward(

FILE: dinov2/hub/text/dinov2_wrapper.py
  class DINOv2Wrapper (line 11) | class DINOv2Wrapper(torch.nn.Module):
    method __init__ (line 12) | def __init__(self, model):
    method forward (line 20) | def forward(self, img, is_training: bool):
    method get_intermediate_layers (line 31) | def get_intermediate_layers(

FILE: dinov2/hub/text/text_tower.py
  class TextHead (line 14) | class TextHead(nn.Module):
    method __init__ (line 15) | def __init__(
    method init_weights (line 45) | def init_weights(self):
    method forward (line 53) | def forward(self, text_tokens: Tensor) -> Tensor:
  class TextTower (line 60) | class TextTower(nn.Module):
    method __init__ (line 61) | def __init__(
    method init_weights (line 88) | def init_weights(self):
    method forward (line 92) | def forward(self, token_indices: Tensor) -> Tensor:

FILE: dinov2/hub/text/text_transformer.py
  class TextTransformer (line 15) | class TextTransformer(nn.Module):
    method __init__ (line 16) | def __init__(
    method init_weights (line 55) | def init_weights(self):
    method forward (line 65) | def forward(self, token_indices: Tensor) -> Tuple[torch.Tensor, torch....

FILE: dinov2/hub/text/tokenizer.py
  class Tokenizer (line 13) | class Tokenizer(SimpleTokenizer):
    method __init__ (line 14) | def __init__(self, vocab_path: str):
    method tokenize (line 17) | def tokenize(self, texts: Union[str, List[str]], context_length: int =...

FILE: dinov2/hub/text/vision_tower.py
  function init_weights_vit_timm (line 19) | def init_weights_vit_timm(module: nn.Module, name: str = ""):
  function named_apply (line 33) | def named_apply(fn: Callable, module: nn.Module, name="", depth_first=Tr...
  class VisionHead (line 50) | class VisionHead(nn.Module):
    method __init__ (line 51) | def __init__(
    method init_weights (line 85) | def init_weights(self):
    method forward (line 94) | def forward(self, image_tokens: Tensor) -> Tensor:
  class VisionTower (line 101) | class VisionTower(nn.Module):
    method __init__ (line 102) | def __init__(
    method init_weights (line 139) | def init_weights(self):
    method get_backbone_features (line 144) | def get_backbone_features(self, images: Tensor) -> Tuple[Tensor, Tenso...
    method get_class_and_patch_tokens (line 156) | def get_class_and_patch_tokens(self, images: Tensor) -> Tuple[Tensor, ...
    method forward (line 162) | def forward(self, images: Tensor) -> Tensor:

FILE: dinov2/hub/utils.py
  function _make_dinov2_model_name (line 17) | def _make_dinov2_model_name(arch_name: str, patch_size: int, num_registe...
  class CenterPadding (line 23) | class CenterPadding(nn.Module):
    method __init__ (line 24) | def __init__(self, multiple):
    method _get_pad (line 28) | def _get_pad(self, size):
    method forward (line 36) | def forward(self, x):

FILE: dinov2/hub/xray_dino/backbones.py
  function xray_dino_vitl16 (line 11) | def xray_dino_vitl16(*, pretrained: bool = True, weights: Union[Weights,...

FILE: dinov2/layers/attention.py
  class Attention (line 36) | class Attention(nn.Module):
    method __init__ (line 37) | def __init__(
    method init_weights (line 57) | def init_weights(
    method forward (line 69) | def forward(self, x: Tensor, is_causal: bool = False) -> Tensor:
  class MemEffAttention (line 82) | class MemEffAttention(Attention):
    method forward (line 83) | def forward(self, x: Tensor, attn_bias=None) -> Tensor:

FILE: dinov2/layers/block.py
  class Block (line 43) | class Block(nn.Module):
    method __init__ (line 44) | def __init__(
    method forward (line 89) | def forward(self, x: Tensor) -> Tensor:
  class CausalAttentionBlock (line 117) | class CausalAttentionBlock(nn.Module):
    method __init__ (line 118) | def __init__(
    method init_weights (line 148) | def init_weights(
    method forward (line 164) | def forward(
  function drop_add_residual_stochastic_depth (line 173) | def drop_add_residual_stochastic_depth(
  function get_branges_scales (line 197) | def get_branges_scales(x, sample_drop_ratio=0.0):
  function add_residual (line 205) | def add_residual(x, brange, residual, residual_scale_factor, scaling_vec...
  function get_attn_bias_and_cat (line 220) | def get_attn_bias_and_cat(x_list, branges=None):
  function drop_add_residual_stochastic_depth_list (line 244) | def drop_add_residual_stochastic_depth_list(
  class NestedTensorBlock (line 267) | class NestedTensorBlock(Block):
    method forward_nested (line 268) | def forward_nested(self, x_list: List[Tensor]) -> List[Tensor]:
    method forward (line 308) | def forward(self, x_or_x_list):

FILE: dinov2/layers/dino_head.py
  class DINOHead (line 12) | class DINOHead(nn.Module):
    method __init__ (line 13) | def __init__(
    method _init_weights (line 30) | def _init_weights(self, m):
    method forward (line 36) | def forward(self, x):
  function _build_mlp (line 44) | def _build_mlp(nlayers, in_dim, bottleneck_dim, hidden_dim=None, use_bn=...

FILE: dinov2/layers/drop_path.py
  function drop_path (line 14) | def drop_path(x, drop_prob: float = 0.0, training: bool = False):
  class DropPath (line 26) | class DropPath(nn.Module):
    method __init__ (line 29) | def __init__(self, drop_prob=None):
    method forward (line 33) | def forward(self, x):

FILE: dinov2/layers/layer_scale.py
  class LayerScale (line 15) | class LayerScale(nn.Module):
    method __init__ (line 16) | def __init__(
    method reset_parameters (line 30) | def reset_parameters(self):
    method forward (line 33) | def forward(self, x: Tensor) -> Tensor:

FILE: dinov2/layers/mlp.py
  class Mlp (line 16) | class Mlp(nn.Module):
    method __init__ (line 17) | def __init__(
    method forward (line 34) | def forward(self, x: Tensor) -> Tensor:

FILE: dinov2/layers/patch_embed.py
  function make_2tuple (line 16) | def make_2tuple(x):
  class PatchEmbed (line 25) | class PatchEmbed(nn.Module):
    method __init__ (line 37) | def __init__(
    method forward (line 68) | def forward(self, x: Tensor) -> Tensor:
    method flops (line 83) | def flops(self) -> float:

FILE: dinov2/layers/swiglu_ffn.py
  class SwiGLUFFN (line 14) | class SwiGLUFFN(nn.Module):
    method __init__ (line 15) | def __init__(
    method forward (line 30) | def forward(self, x: Tensor) -> Tensor:
  class SwiGLUFFNFused (line 54) | class SwiGLUFFNFused(SwiGLU):
    method __init__ (line 55) | def __init__(
  class SwiGLUFFNAligned (line 75) | class SwiGLUFFNAligned(nn.Module):
    method __init__ (line 76) | def __init__(
    method forward (line 96) | def forward(self, x: Tensor) -> Tensor:

FILE: dinov2/logging/__init__.py
  function _configure_logger (line 18) | def _configure_logger(
  function setup_logging (line 82) | def setup_logging(

FILE: dinov2/logging/helpers.py
  class MetricLogger (line 20) | class MetricLogger(object):
    method __init__ (line 21) | def __init__(self, delimiter="\t", output_file=None):
    method update (line 26) | def update(self, **kwargs):
    method __getattr__ (line 33) | def __getattr__(self, attr):
    method __str__ (line 40) | def __str__(self):
    method synchronize_between_processes (line 46) | def synchronize_between_processes(self):
    method add_meter (line 50) | def add_meter(self, name, meter):
    method dump_in_output_file (line 53) | def dump_in_output_file(self, iteration, iter_time, data_time):
    method log_every (line 66) | def log_every(self, iterable, print_freq, header=None, n_iterations=No...
  class SmoothedValue (line 133) | class SmoothedValue:
    method __init__ (line 138) | def __init__(self, window_size=20, fmt=None):
    method update (line 146) | def update(self, value, num=1):
    method synchronize_between_processes (line 151) | def synchronize_between_processes(self):
    method median (line 166) | def median(self):
    method avg (line 171) | def avg(self):
    method global_avg (line 176) | def global_avg(self):
    method max (line 180) | def max(self):
    method value (line 184) | def value(self):
    method __str__ (line 187) | def __str__(self):

FILE: dinov2/loss/dino_clstoken_loss.py
  class DINOLoss (line 12) | class DINOLoss(nn.Module):
    method __init__ (line 13) | def __init__(
    method softmax_center_teacher (line 29) | def softmax_center_teacher(self, teacher_output, teacher_temp):
    method sinkhorn_knopp_teacher (line 35) | def sinkhorn_knopp_teacher(self, teacher_output, teacher_temp, n_itera...
    method forward (line 63) | def forward(self, student_output_list, teacher_out_softmaxed_centered_...
    method update_center (line 77) | def update_center(self, teacher_output):
    method reduce_center_update (line 81) | def reduce_center_update(self, teacher_output):
    method apply_center_update (line 89) | def apply_center_update(self):

FILE: dinov2/loss/ibot_patch_loss.py
  function lossfunc (line 20) | def lossfunc(t, s, temp):
  function lossfunc (line 30) | def lossfunc(t, s, temp):
  class iBOTPatchLoss (line 34) | class iBOTPatchLoss(nn.Module):
    method __init__ (line 35) | def __init__(self, patch_out_dim, student_temp=0.1, center_momentum=0.9):
    method softmax_center_teacher (line 46) | def softmax_center_teacher(self, teacher_patch_tokens, teacher_temp):
    method sinkhorn_knopp_teacher (line 62) | def sinkhorn_knopp_teacher(self, teacher_output, teacher_temp, n_maske...
    method forward (line 92) | def forward(self, student_patch_tokens, teacher_patch_tokens, student_...
    method forward_masked (line 105) | def forward_masked(
    method update_center (line 129) | def update_center(self, teacher_patch_tokens):
    method reduce_center_update (line 133) | def reduce_center_update(self, teacher_patch_tokens):
    method apply_center_update (line 141) | def apply_center_update(self):

FILE: dinov2/loss/koleo_loss.py
  class KoLeoLoss (line 18) | class KoLeoLoss(nn.Module):
    method __init__ (line 21) | def __init__(self):
    method pairwise_NNs_inner (line 25) | def pairwise_NNs_inner(self, x):
    method forward (line 38) | def forward(self, student_output, eps=1e-8):

FILE: dinov2/models/__init__.py
  function build_model (line 14) | def build_model(args, only_teacher=False, img_size=224):
  function build_model_from_cfg (line 44) | def build_model_from_cfg(cfg, only_teacher=False):

FILE: dinov2/models/vision_transformer.py
  function named_apply (line 27) | def named_apply(fn: Callable, module: nn.Module, name="", depth_first=Tr...
  class BlockChunk (line 38) | class BlockChunk(nn.ModuleList):
    method forward (line 39) | def forward(self, x):
  class DinoVisionTransformer (line 45) | class DinoVisionTransformer(nn.Module):
    method __init__ (line 46) | def __init__(
    method init_weights (line 175) | def init_weights(self):
    method interpolate_pos_encoding (line 182) | def interpolate_pos_encoding(self, x, w, h):
    method prepare_tokens_with_masks (line 216) | def prepare_tokens_with_masks(self, x, masks=None):
    method forward_features_list (line 237) | def forward_features_list(self, x_list, masks_list):
    method forward_features (line 257) | def forward_features(self, x, masks=None):
    method _get_intermediate_layers_not_chunked (line 275) | def _get_intermediate_layers_not_chunked(self, x, n=1):
    method _get_intermediate_layers_chunked (line 287) | def _get_intermediate_layers_chunked(self, x, n=1):
    method get_intermediate_layers (line 301) | def get_intermediate_layers(
    method forward (line 348) | def forward(self, *args, is_training=False, **kwargs):
  function init_weights_vit_timm (line 356) | def init_weights_vit_timm(module: nn.Module, name: str = ""):
  function vit_small (line 364) | def vit_small(patch_size=16, num_register_tokens=0, in_chans=3, channel_...
  function vit_base (line 380) | def vit_base(patch_size=16, num_register_tokens=0, in_chans=3, channel_a...
  function vit_large (line 396) | def vit_large(patch_size=16, num_register_tokens=0, in_chans=3, channel_...
  function vit_giant2 (line 412) | def vit_giant2(patch_size=16, num_register_tokens=0, in_chans=3, channel...

FILE: dinov2/run/eval/cell_dino/knn.py
  class Evaluator (line 18) | class Evaluator:
    method __init__ (line 19) | def __init__(self, args):
    method __call__ (line 22) | def __call__(self):
    method checkpoint (line 28) | def checkpoint(self):
    method _setup_args (line 35) | def _setup_args(self):
  function main (line 44) | def main():

FILE: dinov2/run/eval/cell_dino/linear.py
  class Evaluator (line 18) | class Evaluator:
    method __init__ (line 19) | def __init__(self, args):
    method __call__ (line 22) | def __call__(self):
    method checkpoint (line 28) | def checkpoint(self):
    method _setup_args (line 35) | def _setup_args(self):
  function main (line 44) | def main():

FILE: dinov2/run/eval/knn.py
  class Evaluator (line 18) | class Evaluator:
    method __init__ (line 19) | def __init__(self, args):
    method __call__ (line 22) | def __call__(self):
    method checkpoint (line 28) | def checkpoint(self):
    method _setup_args (line 35) | def _setup_args(self):
  function main (line 44) | def main():

FILE: dinov2/run/eval/linear.py
  class Evaluator (line 18) | class Evaluator:
    method __init__ (line 19) | def __init__(self, args):
    method __call__ (line 22) | def __call__(self):
    method checkpoint (line 28) | def checkpoint(self):
    method _setup_args (line 35) | def _setup_args(self):
  function main (line 44) | def main():

FILE: dinov2/run/eval/log_regression.py
  class Evaluator (line 18) | class Evaluator:
    method __init__ (line 19) | def __init__(self, args):
    method __call__ (line 22) | def __call__(self):
    method checkpoint (line 28) | def checkpoint(self):
    method _setup_args (line 35) | def _setup_args(self):
  function main (line 44) | def main():

FILE: dinov2/run/submit.py
  function get_args_parser (line 24) | def get_args_parser(
  function get_shared_folder (line 83) | def get_shared_folder() -> Path:
  function submit_jobs (line 92) | def submit_jobs(task_class, args, name: str):

FILE: dinov2/run/train/train.py
  class Trainer (line 18) | class Trainer(object):
    method __init__ (line 19) | def __init__(self, args):
    method __call__ (line 22) | def __call__(self):
    method checkpoint (line 28) | def checkpoint(self):
    method _setup_args (line 35) | def _setup_args(self):
  function main (line 44) | def main():

FILE: dinov2/thirdparty/CLIP/clip/simple_tokenizer.py
  function default_bpe (line 16) | def default_bpe():
  function bytes_to_unicode (line 21) | def bytes_to_unicode():
  function get_pairs (line 43) | def get_pairs(word):
  function basic_clean (line 55) | def basic_clean(text):
  function whitespace_clean (line 61) | def whitespace_clean(text):
  class SimpleTokenizer (line 67) | class SimpleTokenizer(object):
    method __init__ (line 68) | def __init__(self, bpe_path: str = default_bpe()):
    method bpe (line 88) | def bpe(self, token):
    method encode (line 129) | def encode(self, text):
    method decode (line 137) | def decode(self, tokens):

FILE: dinov2/train/ssl_meta_arch.py
  class SSLMetaArch (line 31) | class SSLMetaArch(nn.Module):
    method __init__ (line 32) | def __init__(self, cfg):
    method forward (line 123) | def forward(self, inputs):
    method backprop_loss (line 126) | def backprop_loss(self, loss):
    method forward_backward (line 132) | def forward_backward(self, images, teacher_temp):
    method fsdp_synchronize_streams (line 348) | def fsdp_synchronize_streams(self):
    method update_teacher (line 356) | def update_teacher(self, m):
    method train (line 367) | def train(self):
    method get_maybe_fused_params_for_submodel (line 371) | def get_maybe_fused_params_for_submodel(self, m):
    method get_params_groups (line 384) | def get_params_groups(self):
    method prepare_for_distributed_training (line 390) | def prepare_for_distributed_training(self):

FILE: dinov2/train/train.py
  function get_args_parser (line 30) | def get_args_parser(add_help: bool = True):
  function build_optimizer (line 61) | def build_optimizer(cfg, params_groups):
  function build_schedulers (line 65) | def build_schedulers(cfg):
  function apply_optim_scheduler (line 113) | def apply_optim_scheduler(optimizer, lr, wd, last_layer_lr):
  function do_test (line 122) | def do_test(cfg, model, iteration):
  function do_train (line 134) | def do_train(cfg, model, resume=False):
  function main (line 306) | def main(args):

FILE: dinov2/utils/checkpoint.py
  class PeriodicCheckpointerWithCleanup (line 14) | class PeriodicCheckpointerWithCleanup(PeriodicCheckpointer):
    method does_write (line 16) | def does_write(self) -> bool:
    method save_best (line 20) | def save_best(self, **kwargs: Any) -> None:
    method has_checkpoint (line 24) | def has_checkpoint(self) -> bool:
    method get_checkpoint_file (line 27) | def get_checkpoint_file(self) -> str:  # returns "" if the file does n...
    method load (line 30) | def load(self, path: str, checkpointables=None) -> dict[str, Any]:
    method step (line 33) | def step(self, iteration: int, **kwargs: Any) -> None:
  function resume_or_load (line 39) | def resume_or_load(checkpointer: Checkpointer, path: str, *, resume: boo...
  function build_periodic_checkpointer (line 52) | def build_periodic_checkpointer(

FILE: dinov2/utils/cluster.py
  class ClusterType (line 12) | class ClusterType(Enum):
  function _guess_cluster_type (line 18) | def _guess_cluster_type() -> ClusterType:
  function get_cluster_type (line 31) | def get_cluster_type(cluster_type: Optional[ClusterType] = None) -> Opti...
  function get_checkpoint_path (line 38) | def get_checkpoint_path(cluster_type: Optional[ClusterType] = None) -> O...
  function get_user_checkpoint_path (line 51) | def get_user_checkpoint_path(cluster_type: Optional[ClusterType] = None)...
  function get_slurm_partition (line 61) | def get_slurm_partition(cluster_type: Optional[ClusterType] = None) -> O...
  function get_slurm_executor_parameters (line 74) | def get_slurm_executor_parameters(

FILE: dinov2/utils/config.py
  function apply_scaling_rules_to_cfg (line 21) | def apply_scaling_rules_to_cfg(cfg):  # to fix
  function write_config (line 32) | def write_config(cfg, output_dir, name="config.yaml"):
  function get_cfg_from_args (line 40) | def get_cfg_from_args(args):
  function default_setup (line 49) | def default_setup(args):
  function setup (line 63) | def setup(args):

FILE: dinov2/utils/dtype.py
  function as_torch_dtype (line 31) | def as_torch_dtype(dtype: TypeSpec) -> torch.dtype:

FILE: dinov2/utils/param_groups.py
  function get_vit_lr_decay_rate (line 13) | def get_vit_lr_decay_rate(name, lr_decay_rate=1.0, num_layers=12, force_...
  function get_params_groups_with_decay (line 51) | def get_params_groups_with_decay(model, lr_decay_rate=1.0, patch_embed_l...
  function fuse_params_groups (line 92) | def fuse_params_groups(all_params_groups, keys=("lr_multiplier", "wd_mul...

FILE: dinov2/utils/utils.py
  function load_pretrained_weights (line 20) | def load_pretrained_weights(model, pretrained_weights, checkpoint_key):
  function fix_random_seeds (line 36) | def fix_random_seeds(seed=31):
  function get_sha (line 46) | def get_sha():
  class CosineScheduler (line 67) | class CosineScheduler(object):
    method __init__ (line 68) | def __init__(self, base_value, final_value, total_iters, warmup_iters=...
    method __getitem__ (line 83) | def __getitem__(self, it):
  function has_batchnorms (line 90) | def has_batchnorms(model):

FILE: setup.py
  function get_requirements (line 29) | def get_requirements(path: str = HERE / "requirements.txt") -> Tuple[Lis...
  function get_package_version (line 42) | def get_package_version() -> str:
Condensed preview — 201 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (2,246K chars).
[
  {
    "path": ".github/workflows/lint.yaml",
    "chars": 796,
    "preview": "name: Lint\n\non:\n  push:\n    branches:\n      - main\n  pull_request:\n    branches:\n      - main\n\njobs:\n  run-linters:\n    "
  },
  {
    "path": ".gitignore",
    "chars": 106,
    "preview": "build/\ndist/\n*.egg-info/\n**/__pycache__/\n\n**/.ipynb_checkpoints\n**/.ipynb_checkpoints/**\n\n*.swp\n\n.vscode/\n"
  },
  {
    "path": "CODE_OF_CONDUCT.md",
    "chars": 3537,
    "preview": "# Code of Conduct\n\n## Our Pledge\n\nIn the interest of fostering an open and welcoming environment, we as\ncontributors and"
  },
  {
    "path": "CONTRIBUTING.md",
    "chars": 1239,
    "preview": "# Contributing to DINOv2\nWe want to make contributing to this project as easy and transparent as\npossible.\n\n## Pull Requ"
  },
  {
    "path": "LICENSE",
    "chars": 11359,
    "preview": "\n\n                                 Apache License\n                           Version 2.0, January 2004\n                 "
  },
  {
    "path": "LICENSE_CELL_DINO_CODE",
    "chars": 18651,
    "preview": "Attribution 4.0 International\n\n=======================================================================\n\nCreative Commons"
  },
  {
    "path": "LICENSE_CELL_DINO_MODELS",
    "chars": 11427,
    "preview": "FAIR Noncommercial Research License\nv1 Last Updated: August 18, 2025\n\n“Acceptable Use Policy” means the FAIR Acceptable "
  },
  {
    "path": "LICENSE_XRAY_DINO_MODEL",
    "chars": 9811,
    "preview": "X-Ray DINO Research License [2025/12/18]\n\nThis X-Ray DINO Research License (“Agreement”) contains the terms and conditio"
  },
  {
    "path": "MODEL_CARD.md",
    "chars": 9150,
    "preview": "# Model Card for DINOv2-S/B/L/g\n\nThese are Vision Transformer models trained following the method described in the paper"
  },
  {
    "path": "README.md",
    "chars": 32781,
    "preview": ":new: [2025-12-18] *Added support for loading XRay-DINO backbone following [Advancing human-centric AI for robust X-ray "
  },
  {
    "path": "conda-extras.yaml",
    "chars": 495,
    "preview": "name: dinov2-extras\nchannels:\n  - defaults\n  - pytorch\n  - nvidia\n  - xformers\n  - conda-forge\ndependencies:\n  - python="
  },
  {
    "path": "conda.yaml",
    "chars": 436,
    "preview": "name: dinov2\nchannels:\n  - defaults\n  - pytorch\n  - nvidia\n  - xformers\n  - conda-forge\ndependencies:\n  - python=3.9\n  -"
  },
  {
    "path": "dinov2/__init__.py",
    "chars": 218,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/configs/__init__.py",
    "chars": 681,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/configs/eval/cell_dino/vitl16_channel_adaptive_pretrain.yaml",
    "chars": 664,
    "preview": "train: \n  batch_size_per_gpu: 32\n  OFFICIAL_EPOCH_LENGTH: 450\n  cell_augmentation: true\n  channel_adaptive: true\nstudent"
  },
  {
    "path": "dinov2/configs/eval/cell_dino/vitl16_pretrain.yaml",
    "chars": 260,
    "preview": "student:\n  arch: vit_large\n  patch_size: 16\n  num_register_tokens: 0\n  interpolate_antialias: false\n  interpolate_offset"
  },
  {
    "path": "dinov2/configs/eval/vitb14_pretrain.yaml",
    "chars": 151,
    "preview": "student:\n  arch: vit_base\n  patch_size: 14\ncrops:\n  global_crops_size: 518  # this is to set up the position embeddings "
  },
  {
    "path": "dinov2/configs/eval/vitb14_reg4_pretrain.yaml",
    "chars": 232,
    "preview": "student:\n  arch: vit_base\n  patch_size: 14\n  num_register_tokens: 4\n  interpolate_antialias: true\n  interpolate_offset: "
  },
  {
    "path": "dinov2/configs/eval/vitg14_pretrain.yaml",
    "chars": 178,
    "preview": "student:\n  arch: vit_giant2\n  patch_size: 14\n  ffn_layer: swiglufused\ncrops:\n  global_crops_size: 518  # this is to set "
  },
  {
    "path": "dinov2/configs/eval/vitg14_reg4_pretrain.yaml",
    "chars": 259,
    "preview": "student:\n  arch: vit_giant2\n  patch_size: 14\n  ffn_layer: swiglufused\n  num_register_tokens: 4\n  interpolate_antialias: "
  },
  {
    "path": "dinov2/configs/eval/vitl14_pretrain.yaml",
    "chars": 152,
    "preview": "student:\n  arch: vit_large\n  patch_size: 14\ncrops:\n  global_crops_size: 518  # this is to set up the position embeddings"
  },
  {
    "path": "dinov2/configs/eval/vitl14_reg4_pretrain.yaml",
    "chars": 233,
    "preview": "student:\n  arch: vit_large\n  patch_size: 14\n  num_register_tokens: 4\n  interpolate_antialias: true\n  interpolate_offset:"
  },
  {
    "path": "dinov2/configs/eval/vits14_pretrain.yaml",
    "chars": 152,
    "preview": "student:\n  arch: vit_small\n  patch_size: 14\ncrops:\n  global_crops_size: 518  # this is to set up the position embeddings"
  },
  {
    "path": "dinov2/configs/eval/vits14_reg4_pretrain.yaml",
    "chars": 233,
    "preview": "student:\n  arch: vit_small\n  patch_size: 14\n  num_register_tokens: 4\n  interpolate_antialias: true\n  interpolate_offset:"
  },
  {
    "path": "dinov2/configs/ssl_default_config.yaml",
    "chars": 2757,
    "preview": "MODEL:\n  WEIGHTS: ''\ncompute_precision:\n  grad_scaler: true\n  teacher:\n    backbone:\n      sharding_strategy: SHARD_GRAD"
  },
  {
    "path": "dinov2/configs/train/cell_dino/vitl16_boc_hpafov.yaml",
    "chars": 538,
    "preview": "train: \n  batch_size_per_gpu: 16\n  OFFICIAL_EPOCH_LENGTH: 450\n  cell_augmentation: true\n  channel_adaptive: true\nstudent"
  },
  {
    "path": "dinov2/configs/train/cell_dino/vitl16_hpafov.yaml",
    "chars": 546,
    "preview": "train: \n  batch_size_per_gpu: 16\n  OFFICIAL_EPOCH_LENGTH: 450\n  cell_augmentation: true\nstudent: \n  arch: vit_large\n  pa"
  },
  {
    "path": "dinov2/configs/train/cell_dino/vitl16_hpaone.yaml",
    "chars": 540,
    "preview": "train: \n  batch_size_per_gpu: 16\n  OFFICIAL_EPOCH_LENGTH: 1756\n  cell_augmentation: true\nstudent: \n  arch: vit_large\n  p"
  },
  {
    "path": "dinov2/configs/train/vitg14.yaml",
    "chars": 528,
    "preview": "dino:\n  head_n_prototypes: 131072\n  head_bottleneck_dim: 384\nibot:\n  separate_head: true\n  head_n_prototypes: 131072\ntra"
  },
  {
    "path": "dinov2/configs/train/vitl14.yaml",
    "chars": 527,
    "preview": "dino:\n  head_n_prototypes: 131072\n  head_bottleneck_dim: 384\nibot:\n  separate_head: true\n  head_n_prototypes: 131072\ntra"
  },
  {
    "path": "dinov2/configs/train/vitl16_short.yaml",
    "chars": 137,
    "preview": "# this corresponds to the default config\ntrain:\n  dataset_path: ImageNet:split=TRAIN\n  batch_size_per_gpu: 64\nstudent:\n "
  },
  {
    "path": "dinov2/data/__init__.py",
    "chars": 561,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/data/accumulators.py",
    "chars": 5173,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/data/adapters.py",
    "chars": 2066,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/data/augmentations.py",
    "chars": 3977,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/data/cell_dino/augmentations.py",
    "chars": 3140,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the CC-by-NC licence,\n# foun"
  },
  {
    "path": "dinov2/data/cell_dino/transforms.py",
    "chars": 4786,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the CC-by-NC licence,\n# foun"
  },
  {
    "path": "dinov2/data/collate.py",
    "chars": 1998,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/data/datasets/__init__.py",
    "chars": 474,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/data/datasets/cell_dino/chammi_cp.py",
    "chars": 3099,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the CC-by-NC licence,\n# foun"
  },
  {
    "path": "dinov2/data/datasets/cell_dino/chammi_hpa.py",
    "chars": 3075,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the CC-by-NC licence,\n# foun"
  },
  {
    "path": "dinov2/data/datasets/cell_dino/chammi_wtc.py",
    "chars": 2900,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the CC-by-NC licence,\n# foun"
  },
  {
    "path": "dinov2/data/datasets/cell_dino/hpafov.py",
    "chars": 8719,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the CC-by-NC licence,\n# foun"
  },
  {
    "path": "dinov2/data/datasets/cell_dino/hpaone.py",
    "chars": 6388,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the CC-by-NC licence,\n# foun"
  },
  {
    "path": "dinov2/data/datasets/decoders.py",
    "chars": 2939,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/data/datasets/extended.py",
    "chars": 1561,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/data/datasets/image_net.py",
    "chars": 10831,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/data/datasets/image_net_22k.py",
    "chars": 10241,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/data/loaders.py",
    "chars": 7059,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/data/masking.py",
    "chars": 2945,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/data/samplers.py",
    "chars": 7645,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/data/transforms.py",
    "chars": 3056,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/distributed/__init__.py",
    "chars": 8576,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/__init__.py",
    "chars": 195,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/cell_dino/knn.py",
    "chars": 16788,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the CC-by-NC licence,\n# foun"
  },
  {
    "path": "dinov2/eval/cell_dino/linear.py",
    "chars": 37587,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the CC-by-NC licence,\n# foun"
  },
  {
    "path": "dinov2/eval/cell_dino/utils.py",
    "chars": 23142,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the CC-by-NC licence,\n# foun"
  },
  {
    "path": "dinov2/eval/depth/__init__.py",
    "chars": 195,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/models/__init__.py",
    "chars": 460,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/models/backbones/__init__.py",
    "chars": 250,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/models/backbones/vision_transformer.py",
    "chars": 435,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/models/builder.py",
    "chars": 1420,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/models/decode_heads/__init__.py",
    "chars": 258,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/models/decode_heads/decode_head.py",
    "chars": 8653,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/models/decode_heads/dpt_head.py",
    "chars": 10434,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/models/decode_heads/linear_head.py",
    "chars": 3233,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/models/depther/__init__.py",
    "chars": 275,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/models/depther/base.py",
    "chars": 7697,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/models/depther/encoder_decoder.py",
    "chars": 8925,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/models/losses/__init__.py",
    "chars": 264,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/models/losses/gradientloss.py",
    "chars": 2540,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/models/losses/sigloss.py",
    "chars": 2286,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/ops/__init__.py",
    "chars": 225,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/depth/ops/wrappers.py",
    "chars": 1229,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/knn.py",
    "chars": 14455,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/linear.py",
    "chars": 21426,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/log_regression.py",
    "chars": 15138,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/metrics.py",
    "chars": 4422,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation/__init__.py",
    "chars": 195,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation/hooks/__init__.py",
    "chars": 237,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation/hooks/optimizer.py",
    "chars": 1415,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation/models/__init__.py",
    "chars": 277,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation/models/backbones/__init__.py",
    "chars": 250,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation/models/backbones/vision_transformer.py",
    "chars": 476,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation/models/decode_heads/__init__.py",
    "chars": 228,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation/models/decode_heads/linear_head.py",
    "chars": 3292,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation/utils/__init__.py",
    "chars": 195,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation/utils/colormaps.py",
    "chars": 7685,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/__init__.py",
    "chars": 299,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/core/__init__.py",
    "chars": 394,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/core/anchor/__init__.py",
    "chars": 258,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/core/anchor/builder.py",
    "chars": 714,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/core/anchor/point_generator.py",
    "chars": 8814,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/core/box/__init__.py",
    "chars": 287,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/core/box/builder.py",
    "chars": 594,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/core/box/samplers/__init__.py",
    "chars": 261,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/core/box/samplers/base_sampler.py",
    "chars": 3819,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/core/box/samplers/mask_pseudo_sampler.py",
    "chars": 1647,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/core/box/samplers/mask_sampling_result.py",
    "chars": 2163,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/core/box/samplers/sampling_result.py",
    "chars": 5415,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/core/utils/__init__.py",
    "chars": 274,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/core/utils/dist_utils.py",
    "chars": 519,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/core/utils/misc.py",
    "chars": 1324,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/__init__.py",
    "chars": 485,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/backbones/__init__.py",
    "chars": 232,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/backbones/adapter_modules.py",
    "chars": 14983,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/backbones/drop_path.py",
    "chars": 1145,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/backbones/vit.py",
    "chars": 20135,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/backbones/vit_adapter.py",
    "chars": 7938,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/builder.py",
    "chars": 619,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/decode_heads/__init__.py",
    "chars": 242,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/decode_heads/mask2former_head.py",
    "chars": 25331,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/losses/__init__.py",
    "chars": 410,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/losses/cross_entropy_loss.py",
    "chars": 11292,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/losses/dice_loss.py",
    "chars": 6339,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/losses/match_costs.py",
    "chars": 5348,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/plugins/__init__.py",
    "chars": 261,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/plugins/msdeformattn_pixel_decoder.py",
    "chars": 10706,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/segmentors/__init__.py",
    "chars": 263,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/segmentors/encoder_decoder_mask2former.py",
    "chars": 10632,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/utils/__init__.py",
    "chars": 495,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/utils/assigner.py",
    "chars": 6368,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/utils/point_sample.py",
    "chars": 3889,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/utils/positional_encoding.py",
    "chars": 6424,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/models/utils/transformer.py",
    "chars": 41354,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/ops/modules/__init__.py",
    "chars": 425,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/segmentation_m2f/ops/modules/ms_deform_attn.py",
    "chars": 8296,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/setup.py",
    "chars": 2069,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/eval/utils.py",
    "chars": 5205,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/fsdp/__init__.py",
    "chars": 5115,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/__init__.py",
    "chars": 195,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/backbones.py",
    "chars": 5572,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/cell_dino/backbones.py",
    "chars": 5027,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the CC-by-NC licence,\n# foun"
  },
  {
    "path": "dinov2/hub/classifiers.py",
    "chars": 8195,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/depth/__init__.py",
    "chars": 287,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/depth/decode_heads.py",
    "chars": 29268,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/depth/encoder_decoder.py",
    "chars": 13909,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/depth/ops.py",
    "chars": 1229,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/depthers.py",
    "chars": 8149,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/dinotxt.py",
    "chars": 3004,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/text/dinotxt_model.py",
    "chars": 5657,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/text/dinov2_wrapper.py",
    "chars": 2600,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/text/text_tower.py",
    "chars": 3513,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/text/text_transformer.py",
    "chars": 2424,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/text/tokenizer.py",
    "chars": 1662,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/text/vision_tower.py",
    "chars": 6844,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/utils.py",
    "chars": 1260,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/hub/xray_dino/backbones.py",
    "chars": 838,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the licence\n# found in the L"
  },
  {
    "path": "dinov2/layers/__init__.py",
    "chars": 498,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/layers/attention.py",
    "chars": 3298,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/layers/block.py",
    "chars": 11609,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/layers/dino_head.py",
    "chars": 2007,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/layers/drop_path.py",
    "chars": 1157,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/layers/layer_scale.py",
    "chars": 1097,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/layers/mlp.py",
    "chars": 1269,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/layers/patch_embed.py",
    "chars": 2829,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/layers/swiglu_ffn.py",
    "chars": 3200,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/logging/__init__.py",
    "chars": 3284,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/logging/helpers.py",
    "chars": 6220,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/loss/__init__.py",
    "chars": 314,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/loss/dino_clstoken_loss.py",
    "chars": 3647,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/loss/ibot_patch_loss.py",
    "chars": 5718,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/loss/koleo_loss.py",
    "chars": 1608,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/models/__init__.py",
    "chars": 1574,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/models/vision_transformer.py",
    "chars": 16438,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/run/__init__.py",
    "chars": 195,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/run/eval/cell_dino/knn.py",
    "chars": 1724,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the CC-by-NC licence,\n# foun"
  },
  {
    "path": "dinov2/run/eval/cell_dino/linear.py",
    "chars": 1760,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the CC-by-NC licence,\n# foun"
  },
  {
    "path": "dinov2/run/eval/knn.py",
    "chars": 1660,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/run/eval/linear.py",
    "chars": 1689,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/run/eval/log_regression.py",
    "chars": 1755,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/run/submit.py",
    "chars": 3304,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/run/train/train.py",
    "chars": 1665,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/thirdparty/CLIP/LICENSE",
    "chars": 1063,
    "preview": "MIT License\n\nCopyright (c) 2021 OpenAI\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof "
  },
  {
    "path": "dinov2/thirdparty/CLIP/clip/simple_tokenizer.py",
    "chars": 4896,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/train/__init__.py",
    "chars": 276,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/train/ssl_meta_arch.py",
    "chars": 18616,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/train/train.py",
    "chars": 11075,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/utils/__init__.py",
    "chars": 195,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/utils/checkpoint.py",
    "chars": 2597,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the CC-by-NC licence,\n# foun"
  },
  {
    "path": "dinov2/utils/cluster.py",
    "chars": 3014,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/utils/config.py",
    "chars": 2211,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/utils/dtype.py",
    "chars": 1104,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/utils/param_groups.py",
    "chars": 3761,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "dinov2/utils/utils.py",
    "chars": 3240,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "docs/README_CELL_DINO.md",
    "chars": 6744,
    "preview": "\n# Cell-DINO: Self-Supervised Image-based Embeddings for Cell Fluorescent Microscopy\n\nThéo Moutakanni*, Camille Couprie*"
  },
  {
    "path": "docs/README_CHANNEL_ADAPTIVE_DINO.md",
    "chars": 6646,
    "preview": "\n# Scaling Channel-Adaptive Self-Supervised Learning\n\n [[`Paper `](https://openreview.net/forum?id=pT8sgtRVAf))] [[`BibT"
  },
  {
    "path": "hubconf.py",
    "chars": 1126,
    "preview": "# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache License, Version "
  },
  {
    "path": "notebooks/cell_dino/inference.ipynb",
    "chars": 6163,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": null,\n   \"id\": \"6c3f1fe9-af40-4a57-aff0-99313d722f34\",\n "
  },
  {
    "path": "notebooks/depth_estimation.ipynb",
    "chars": 671798,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 1,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n "
  },
  {
    "path": "notebooks/dinotxt.ipynb",
    "chars": 30329,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": null,\n   \"id\": \"f75733e2\",\n   \"metadata\": {},\n   \"output"
  },
  {
    "path": "notebooks/semantic_segmentation.ipynb",
    "chars": 598694,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 1,\n   \"id\": \"b470389d-a897-416e-9601-aeacb39cd694\",\n   \""
  },
  {
    "path": "pyproject.toml",
    "chars": 417,
    "preview": "[tool.black]\nline-length = 120\n\n[tool.pylint.master]\npersistent = false\nscore = false\n\n[tool.pylint.messages_control]\ndi"
  },
  {
    "path": "requirements-dev.txt",
    "chars": 43,
    "preview": "black==22.6.0\nflake8==5.0.4\npylint==2.15.0\n"
  },
  {
    "path": "requirements-extras.txt",
    "chars": 40,
    "preview": "mmcv-full==1.5.0\nmmsegmentation==0.27.0\n"
  },
  {
    "path": "requirements.txt",
    "chars": 213,
    "preview": "--extra-index-url https://download.pytorch.org/whl/cu117\ntorch==2.0.0\ntorchvision==0.15.0\nomegaconf\ntorchmetrics==0.10.3"
  },
  {
    "path": "scripts/cell_dino/launcher_knn_eval_on_chammi.sh",
    "chars": 1328,
    "preview": "#!/bin/bash\n# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache Licen"
  },
  {
    "path": "scripts/cell_dino/launcher_linear_eval_on_chammi.sh",
    "chars": 1430,
    "preview": "#!/bin/bash\n# Copyright (c) Meta Platforms, Inc. and affiliates.\n#\n# This source code is licensed under the Apache Licen"
  },
  {
    "path": "scripts/lint.sh",
    "chars": 303,
    "preview": "#!/bin/sh\n\nif [ -n \"$1\" ]; then\n  echo \"linting \\\"$1\\\"\"\nfi\n\necho \"running black\"\nif [ -n \"$1\" ]; then\n  black \"$1\"\nelse\n"
  },
  {
    "path": "setup.cfg",
    "chars": 130,
    "preview": "[flake8]\nmax-line-length = 120\nignore = E203,E501,W503\nper-file-ignores =\n  __init__.py:F401\n  hubconf.py:F401\nexclude ="
  }
]

// ... and 1 more files (download for full content)

About this extraction

This page contains the full source code of the facebookresearch/dinov2 GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 201 files (2.1 MB), approximately 557.7k tokens, and a symbol index with 1094 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!