Instructions to use prithivMLmods/Sketch-126-DomainNet with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use prithivMLmods/Sketch-126-DomainNet with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="prithivMLmods/Sketch-126-DomainNet") pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForImageClassification processor = AutoProcessor.from_pretrained("prithivMLmods/Sketch-126-DomainNet") model = AutoModelForImageClassification.from_pretrained("prithivMLmods/Sketch-126-DomainNet", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files289 unmodified lines2902912922932942952962974 unmodified lines30230330430530630730830931031131231331431523 unmodified lines339340341342343344345346347348349350351352353354355356357358289 unmodified lines```pythonimport gradio as grfrom transformers import AutoImageProcessorfrom transformers import SiglipForImageClassificationfrom transformers.image_utils import load_imagefrom PIL import Imageimport torch4 unmodified linesprocessor = AutoImageProcessor.from_pretrained(model_name)def sketch_classification(image):\"\"\"Predicts the sketch category for an input image.\"\"\n image = Image.fromarray(image).convert(\"RGB\")inputs = processor(images=image, return_tensors=\"pt\")with torch.no_grad():outputs = model(**inputs)logits = outputs.logitsprobs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()labels = {"0": "aircraft_carrier", "1": "alarm_clock", "2": "ant", "3": "anvil", "4": "asparagus","5": "axe", "6": "banana", "7": "basket", "8": "bathtub", "9": "bear",23 unmodified lines"122": "vase", "123": "watermelon", "124": "whale", "125": "zebra"}predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}return predictions# Create Gradio interfaceiface = gr.Interface(fn=sketch_classification,inputs=gr.Image(type=\"numpy\"),outputs=gr.Label(label=\"Prediction Scores\"),title=\"Sketch-126-DomainNet Classification\",description=\"Upload a sketch to classify it into one of 126 categories.\")# Launch the appif __name__ == \"__main__\":iface.launch()```289 unmodified lines2902912922932942952964 unmodified lines30130230330430530630730830931031131231331431531631731831932032123 unmodified lines345346347348349350351352353354355356357358359360361362363364365289 unmodified lines```pythonimport gradio as grfrom transformers import AutoImageProcessor, SiglipForImageClassificationfrom transformers.image_utils import load_imagefrom PIL import Imageimport torch4 unmodified linesprocessor = AutoImageProcessor.from_pretrained(model_name)def sketch_classification(image):"""Predicts the sketch category for an input image."""# Convert the input numpy array to a PIL Image and ensure it has 3 channels (RGB)image = Image.fromarray(image).convert("RGB")# Process the image and prepare it for the modelinputs = processor(images=image, return_tensors="pt")# Perform inference without gradient calculationwith torch.no_grad():outputs = model(**inputs)logits = outputs.logits# Convert logits to probabilities using softmaxprobs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()# Mapping from indices to corresponding sketch category labelslabels = {"0": "aircraft_carrier", "1": "alarm_clock", "2": "ant", "3": "anvil", "4": "asparagus","5": "axe", "6": "banana", "7": "basket", "8": "bathtub", "9": "bear",23 unmodified lines"122": "vase", "123": "watermelon", "124": "whale", "125": "zebra"}# Create a dictionary mapping each label to its predicted probability (rounded)predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}return predictions# Create Gradio interfaceiface = gr.Interface(fn=sketch_classification,inputs=gr.Image(type="numpy"),outputs=gr.Label(label="Prediction Scores"),title="Sketch-126-DomainNet Classification",description="Upload a sketch to classify it into one of 126 categories.")# Launch the appif __name__ == "__main__":iface.launch()```
README.md+16-9