Instructions to use SupremoUGH/image-classification-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use SupremoUGH/image-classification-model with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="SupremoUGH/image-classification-model") pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# Load model directly from transformers import AutoImageProcessor, AutoModelForImageClassification processor = AutoImageProcessor.from_pretrained("SupremoUGH/image-classification-model") model = AutoModelForImageClassification.from_pretrained("SupremoUGH/image-classification-model", device_map="auto") - Notebooks
- Google Colab
- Kaggle
| import torch | |
| from PIL import Image | |
| from .preprocess import preprocess_image | |
| from .utils import load_model | |
| def predict_with_model(model, inputs): | |
| """Runs inference and returns the predicted class.""" | |
| model.eval() # Ensure the model is in evaluation mode | |
| with torch.no_grad(): # Disable gradient calculation | |
| outputs = model(**inputs) | |
| logits = outputs.logits | |
| predicted_class = logits.argmax(dim=-1).item() # Get predicted class index | |
| return predicted_class | |
| def predict(image_path): | |
| """Loads an image, preprocesses it, runs the model, and returns the prediction.""" | |
| image = Image.open(image_path).convert("RGB") | |
| inputs = preprocess_image(image) | |
| # Load model | |
| model = load_model() | |
| # Ensure inputs are on the same device as the model | |
| device = model.device | |
| inputs = {key: tensor.to(device) for key, tensor in inputs.items()} | |
| return predict_with_model(model, inputs) | |