Make HiT-SR available on HF
Opened this issue ยท 7 comments
Hi @XiangZ-0,
Niels here from the open-source team at Hugging Face. I discovered your work through the paper page: https://huggingface.co/papers/2407.05878 (congrats on the ECCV Oral!). I work together with AK on improving the visibility of researchers' work on the hub.
It'd be great to make the models available on the ๐ค hub, we can add tags so that people find them when filtering https://huggingface.co/models.
For instance, I contributed the Swin2-SR model to HF here: https://huggingface.co/caidas/swin2SR-realworld-sr-x4-64-bsrgan-psnr. We can add tags like "image-to-image" and "image super-resolution" so that people will find your work.
Uploading models
See here for a guide: https://huggingface.co/docs/hub/models-uploading. In case the models are custom PyTorch model, we could probably leverage the PyTorchModelHubMixin class which adds from_pretrained
and push_to_hub
to each model. Alternatively, one can leverages the hf_hub_download one-liner to download a checkpoint from the hub.
We encourage researchers to push each model checkpoint to a separate model repository, so that things like download stats also work. We can then also link the checkpoints to the paper page.
Let me know if you need any help regarding this!
Cheers,
Niels
ML Engineer @ HF ๐ค
Hi Niels, thank you for your interest in our work! It would be very cool to have HiT-SR on Hugging Face ๐ค. I am pretty new to ๐ค hub but will try to upload HiT-SR next week. Please stay tuned!
Great, happy to send a PR if required
That would be very nice if it's convenient for you to send a PR :) In my understanding, we need to integrate PyTorchModelHubMixin class into the models and then run push_to_hub
. Is it right?
Yes that is right. Would it be possible for you to try this out?
Note that for the PyTorchModelHubMixin to work, your nn.Module class should only take arguments in its init which are JSON serializable (like integers, floats, lists, dicts,...). This way it will push a config.json (along with safetensors weights) to a model repo on the hub. Basically this:
from basicsr.models.hit_model import HITModel
# initialize model
model = HITModel(...)
# equip with weights
model.load_state_dict(...)
# push to the hub
model.push_to_hub("your-hf-org/hit-base")
# reload
model = HITModel.from_pretrained("your-hf-org/hit-base")
Hi,
What I did for Swin2SR is making the model Transformers compatible as explained here: https://huggingface.co/docs/transformers/custom_models.
Regarding the models on HF, what did you use to upload the models? Cause it seems there's no from_pretrained
method present in this code base. Update: I see you've pushed the code to a repo on the hub, great! Feel free to also include it in the Github repository :)
Looks like download numbers are working now, so we could perhaps update the README here so that people can find the HF models?
Hi Niels,
Thanks a lot for the suggestions and help! I have updated the Github codebase to make it compatible with Huggingface models, and README is also updated. Will try to make HiT-SR compatible with transformers later. :)