Instructions to use tmshag1/vitmodel2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tmshag1/vitmodel2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="tmshag1/vitmodel2", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoImageProcessor, AutoModel processor = AutoImageProcessor.from_pretrained("tmshag1/vitmodel2", trust_remote_code=True) model = AutoModel.from_pretrained("tmshag1/vitmodel2", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download handler.py from tmshag1/vitmodel2: direct link, hf CLI and curl.
- Browser
- Download file 747 Bytes
-
https://huggingface.co/tmshag1/vitmodel2/resolve/refs%2Fpr%2F1/handler.py
- Command line
-
hf download hf://tmshag1/vitmodel2@refs/pr/1/handler.py
-
curl -L -o handler.py https://huggingface.co/tmshag1/vitmodel2/resolve/refs%2Fpr%2F1/handler.py
747 Bytes
| import torch.nn.functional as F | |
| from torch import Tensor | |
| from transformers import AutoTokenizer, AutoModel, AutoProcessor | |
| from torch import cuda | |
| class EndpointHandler(): | |
| def __init__(self, path=""): | |
| #self.processor = AutoProcessor.from_pretrained(path) | |
| #self.model = AutoModel.from_pretrained(path, trust_remote_code=True) | |
| #self.device = "cuda" if cuda.is_available() else "cpu" | |
| #self.model.to(self.device) | |
| def __call__(self, data: Dict[str, Any]) -> List[List[int]]: | |
| #image = data.pop("inputs",data) | |
| #processed = self.processor(images=image, return_tensors="pt").to(self.device) | |
| #prediction = self.model(processed["pixel_values"]) | |
| return "OK"#prediction.item() |