Feature Extraction
Transformers
Safetensors
bat
audio
self-supervised-learning
masked-modeling
audioset
BAT
custom_code
Instructions to use lrauch/BAT-vit-b16-pretrainedAS2M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lrauch/BAT-vit-b16-pretrainedAS2M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="lrauch/BAT-vit-b16-pretrainedAS2M", trust_remote_code=True, device_map="auto")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("lrauch/BAT-vit-b16-pretrainedAS2M", trust_remote_code=True, dtype="auto", device_map="auto") - Notebooks
- Google Colab
- Kaggle
| from pathlib import Path | |
| from typing import Optional, Union | |
| def _default_model_path() -> str: | |
| return str(Path(__file__).resolve().parent) | |
| def load_pretrained_encoder( | |
| model_id_or_path: Optional[Union[str, Path]] = None, | |
| device: str = "cpu", | |
| dtype=None, | |
| ): | |
| from transformers import AutoModel | |
| kwargs = {"trust_remote_code": True} | |
| if dtype is not None: | |
| kwargs["torch_dtype"] = dtype | |
| model = AutoModel.from_pretrained(str(model_id_or_path or _default_model_path()), **kwargs) | |
| return model.to(device).eval() | |
| def load_audio_processor(model_id_or_path: Optional[Union[str, Path]] = None, device: str = "cpu", **kwargs): | |
| try: | |
| from .processing_bat import BatAudioProcessor | |
| except ImportError: | |
| from processing_bat import BatAudioProcessor | |
| processor = BatAudioProcessor.from_pretrained(model_id_or_path or _default_model_path(), **kwargs) | |
| return processor.to(device) | |