Skip to content

Commit a5ab889

Browse files
Add Hugging Face model downloader (#86)
* feat: add huggingface_hub dependency to environment files * Lock conda dependencies with huggingface hub package * feat: implement DownloaderHuggingFace class for downloading files from HuggingFace Hub * feat: use CustomJsonFormatter in LoggerJsonFile for enhanced logging * Refactor model downloader configurations to use Hugging Face repository - Updated multiple predictor configurations to switch from Google Drive downloader to Hugging Face downloader. - Added repository IDs and filenames for models hosted on Hugging Face. - Created new configuration files for models that were previously only available via Google Drive. * fix: simplify local directory handling in DownloaderHuggingFace * docs: update README to reflect model hosting transition from Google Drive to Hugging Face Hub * Update documentation and enhance code structure - Updated pdoc version from 0.11.1 to 0.11.6 in transforms.html and utils.html. - Added collapsible sections for long docstrings in both transforms and utils documentation. - Expanded source code sections for functions in transforms and utils, providing detailed docstrings. - Improved the description of the DownloaderHuggingFace class and its methods in index.js. * docs: update README to enhance visibility of Hugging Face Spaces demo * style: standardize string quotes in CustomJsonFormatter * style: improve code formatting and readability in DownloaderHuggingFace * docs: update CHANGELOG for version 0.6.0 with new features and changes * bump version to 0.6.0 * Update CHANGELOG.md Co-authored-by: Copilot <[email protected]> * Update CHANGELOG.md Co-authored-by: Copilot <[email protected]> * fix: update facetorch version requirement to 0.6.0 in notebook demo * fix: remove unnecessary comment from efficientnet_b7 configuration files * fix: update downloader to use HuggingFace for various predictors in merged.config.yaml * fix: update downloader to use HuggingFace for various predictors in gpu.merged.config.yaml * Update conf/analyzer/predictor/deepfake/efficientnet_b7_hf.yaml Co-authored-by: Copilot <[email protected]> * Update conf/analyzer/predictor/deepfake/efficientnet_b7_gdrive.yaml Co-authored-by: Copilot <[email protected]> * Update conf/analyzer/predictor/deepfake/efficientnet_b7_hf.yaml Co-authored-by: Copilot <[email protected]> * Update conf/analyzer/detector/retinaface_hf.yaml Co-authored-by: Copilot <[email protected]> * Update README.md Co-authored-by: Copilot <[email protected]> * Update conf/analyzer/predictor/deepfake/efficientnet_b7_gdrive.yaml Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 6377cec commit a5ab889

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+4915
-1660
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Change Log
22

3+
## 0.6.0
4+
5+
Released on May 24, 2025.
6+
7+
### Added
8+
* DownloaderHuggingFace for downloading models from Hugging Face Hub
9+
10+
### Changed
11+
* default model download source from Google Drive to Hugging Face Hub
12+
13+
314
## 0.5.1
415

516
Released on November 17, 2024.

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
[![PyPI - License](https://img.shields.io/pypi/l/facetorch)](https://raw.githubusercontent.com/tomas-gajarsky/facetorch/main/LICENSE)
77
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
88

9-
[Hugging Face Space demo app 🤗](https://huggingface.co/spaces/tomas-gajarsky/facetorch-app)
10-
11-
[Google Colab notebook demo](https://colab.research.google.com/github/tomas-gajarsky/facetorch/blob/main/notebooks/facetorch_notebook_demo.ipynb)
12-
<a target="_blank" href="https://colab.research.google.com/github/tomas-gajarsky/facetorch/blob/main/notebooks/facetorch_notebook_demo.ipynb">
9+
<a href="https://huggingface.co/spaces/tomas-gajarsky/facetorch-app">
10+
<img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue" alt="Hugging Face Spaces">
11+
</a> <a target="_blank" href="https://colab.research.google.com/github/tomas-gajarsky/facetorch/blob/main/notebooks/facetorch_notebook_demo.ipynb">
1312
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
1413
</a>
1514

@@ -26,7 +25,7 @@
2625

2726
3. **Accelerated Performance:** Enjoy enhanced performance on both CPU and GPU with [TorchScript](https://pytorch.org/docs/stable/jit.html) optimization.
2827

29-
4. **Simple Extensibility:** Extend the library by uploading your model file to Google Drive and adding a corresponding configuration YAML file to the repository.
28+
4. **Simple Extensibility:** Extend the library by uploading your model file to Hugging Face Hub (previously Google Drive) and adding a corresponding configuration YAML file to the repository.
3029

3130
Facetorch provides an efficient, scalable, and user-friendly solution for facial analysis tasks, catering to developers and researchers looking for flexibility and performance.
3231

@@ -208,8 +207,8 @@ for Identity-invariant Facial Expression Recognition](https://arxiv.org/abs/2209
208207

209208
### Model download
210209

211-
Models are downloaded during runtime automatically to the *models* directory.
212-
You can also download the models manually from a [public Google Drive folder](https://drive.google.com/drive/folders/19qlklR18wYfFsCChQ78it10XciuTzbDM?usp=sharing).
210+
Models are downloaded during runtime automatically to the *models* directory using Hugging Face Hub (the default downloader has been switched from Google Drive to Hugging Face Hub).
211+
Models are available on the [Hugging Face Hub](https://huggingface.co/tomas-gajarsky) and legacy models can also be accessed from the [original Google Drive folder](https://drive.google.com/drive/folders/19qlklR18wYfFsCChQ78it10XciuTzbDM?usp=sharing).
213212

214213

215214
### Execution time
@@ -245,14 +244,13 @@ Run the Docker container:
245244

246245
### Add predictor
247246
#### Prerequisites
248-
1. file of the TorchScript model
249-
2. ID of the Google Drive model file
247+
1. File of the TorchScript model
248+
2. Repository on Hugging Face Hub for hosting the model (or legacy ID of the Google Drive model file)
250249
3. facetorch [fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo)
251250

252251
Facetorch works with models that were exported from PyTorch to TorchScript. You can apply [torch.jit.trace](https://pytorch.org/docs/stable/generated/torch.jit.trace.html) function to compile a PyTorch model as a TorchScript module. Please verify that the output of the traced model equals the output of the original model.
253252

254-
The first models are hosted on my [public Google Drive folder](https://drive.google.com/drive/folders/19qlklR18wYfFsCChQ78it10XciuTzbDM?usp=sharing). You can either send the new model for upload to me, host the model on your
255-
Google Drive or host it somewhere else and add your own downloader object to the codebase.
253+
Models are now hosted on [Hugging Face Hub](https://huggingface.co/tomas-gajarsky) which is the default download source. You can host your model on your own Hugging Face account or use the legacy Google Drive hosting option by specifying the appropriate downloader in your configuration.
256254

257255
#### Configuration
258256
##### Create yaml file
@@ -264,10 +262,12 @@ Google Drive or host it somewhere else and add your own downloader object to the
264262
```/conf/analyzer/predictor/<predictor_name>/<model_name>.yaml```
265263

266264
##### Edit yaml file
267-
1. Change the Google Drive file ID to the ID of the model.
268-
2. Select the preprocessor (or implement a new one based on BasePredPreProcessor) and specify it's parameters e.g. image size and normalization in the yaml file
265+
1. Set up the downloader configuration:
266+
- For Hugging Face Hub (recommended): specify the `repo_id` and `filename` parameters
267+
- For legacy Google Drive: specify the Google Drive file ID
268+
2. Select the preprocessor (or implement a new one based on BasePredPreProcessor) and specify its parameters e.g. image size and normalization in the yaml file
269269
to match the requirements of the new model.
270-
3. Select the postprocessor (or implement a new one based on BasePredPostProcessor) and specify it's parameters e.g. labels in the yaml file to match
270+
3. Select the postprocessor (or implement a new one based on BasePredPostProcessor) and specify its parameters e.g. labels in the yaml file to match
271271
the requirements of the new model.
272272
4. (Optional) Add BaseUtilizer derivative that uses output of your model to perform some additional actions.
273273

0 commit comments

Comments
 (0)