Run this model with HF Jobs
Run alexionby/ainoai on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/alexionby/ainoai. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/alexionby/ainoai on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use alexionby/ainoai with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use alexionby/ainoai with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import ResNet50 model = ResNet50.from_pretrained("alexionby/ainoai", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 1,747 Bytes
a1374ed | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | from typing import Dict, List, Any
from transformers import AutoModelForImageClassification, AutoFeatureExtractor
import torch
from PIL import Image
import io
class EndpointHandler:
def __init__(self):
# Initialize model and feature extractor
model_id = "alexionby/ainoai"
self.model = AutoModelForImageClassification.from_pretrained(model_id)
self.feature_extractor = AutoFeatureExtractor.from_pretrained(model_id)
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
# Convert bytes to PIL Image
image = data.pop('image', data)
image = Image.open(io.BytesIO(image))
# Preprocess the image
inputs = self.feature_extractor(images=image, return_tensors="pt")
# Run the model
with torch.no_grad():
outputs = self.model(**inputs)
# Post-process the model outputs as needed
logits = outputs.logits
probabilities = torch.nn.functional.softmax(logits, dim=-1)
predictions = probabilities.argmax(-1)
# Convert predictions to JSON-serializable format
return {"label": str(predictions.item())}
# import torch
# from PIL import Image
# import io
# class EndpointHandler():
# def __init__(self, path=""):
# # Preload all the elements you are going to need at inference.
# # pseudo:
# self.model= load_model(path)
# def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
# """
# data args:
# inputs (:obj: `str` | `PIL.Image` | `np.array`)
# kwargs
# Return:
# A :obj:`list` | `dict`: will be serialized and returned
# """
# # pseudo
# # self.model(input) |