Deferred imports for datasets libraries (torchvision, tensorflow-datasets, and HF datasets) - #121
Merged
Merged
Conversation
torchvision is only imported when a torchvision dataset is chosen in `load_dataset`, i.e. hub="torchvision". As torchvision is not a dependency for oodeel, this is required to avoid ImportError when using PyTorch backend even without a torchvision dataset.
Since tensorflow-datasets is not a dependency of oodeel, the import is deferred in the function that loads a TF dataset. The user can now use TFDataHandler without requiring tensorflow-datasets if not needed.
cofri
force-pushed
the
feat/torchvision_lazy_import
branch
3 times, most recently
from
January 20, 2026 11:24
8f5afdc to
5cc66f8
Compare
HuggingFace datasets package is removed from the dependencies. Imports in TorchDataHandler and TFDataHandler is now deferred in the corresponding functions: importing 'datasets' is only tested when a HF dataset is chosen by the user. Note that datasets version is set for some PyTorch versions because of incompatibilities with other package versions...
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
cofri
force-pushed
the
feat/torchvision_lazy_import
branch
from
January 20, 2026 12:35
b358331 to
ef7b3a1
Compare
cofri
marked this pull request as ready for review
February 16, 2026 10:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Torchvision and tensorflow-datasets (tfds) are not dependencies of oodeel. In DataHandlers, the imports for those packages are then deferred in the corresponding functions to avoid
ImportErrorif not installed. The error will only be raised if a torchvision or tfds dataset is requested by the user.For HuggingFace
datasetslibrary, same thing is done: the import is deferred in theload_from_huggingfacefunction. Moreover, to be consistent with torchvision and tfds, thedatasetsdependency is removed from setup.py.Solves issue #116