DepthAnything / Depth-Anything-V2

Depth Anything V2. A More Capable Foundation Model for Monocular Depth Estimation
https://depth-anything-v2.github.io
Apache License 2.0
3.39k stars 277 forks source link

Integrate with huggingface #20

Closed not-lain closed 2 months ago

not-lain commented 3 months ago

This pr mainly introduces a better way to push and load AI models from HuggingFace with ease using PyTorchModelHubMixin adding 3 methods to your model similar to how the transformers model operates which are :

perks of using PyTorchModelHubMixin :

you can also take a look at this colab notebook to set your huggingface repositories https://colab.research.google.com/drive/14jr-G280COi7YrFLtDp0J6VhBbTMgIZx?usp=sharing . Once this is all done all users can load your model using the following code :

# no more initializing the model nor downloading the weights 
# or injecting the weights manually as this is all done automatically

model = DepthAnythingV2.from_pretrained("not-lain/Depth-Anything-V2-Small") # or any other repo
NielsRogge commented 2 months ago

This was indeed the easiest way for integration, but we're going for https://github.com/huggingface/huggingface.js/pull/785 as alternative

not-lain commented 2 months ago

Nice work and thanks for the follow-up Niels ! I will proceed to closing this PR then.

Wauplin commented 2 months ago

@NielsRogge @not-lain PR https://github.com/huggingface/huggingface.js/pull/785 is nice to get at least code snippet + download count + "official library" but I think this PR is still relevant for long-term.

@LiheYoung @bingykang would you be up to have such an integration added to Depth-Anything-V2? As @not-lain explained, it would add a few nice features for end users (.from_pretrained to directly load from the hub, .push_to_hub for users finetuning/retraining the model, correct metadata on pushed models, etc). If you have any question, feel free to ask :hugs: