Views
No views yet
1import requests
2import base64
3
4# Load your image
5with open("test_image.png", "rb") as f:
6 image_data = base64.b64encode(f.read()).decode()
7
8# Send to inference endpoint
9response = requests.post(
10 "https://your-endpoint.com",
11 headers={"Authorization": "Bearer YOUR_TOKEN"},
12 json={"inputs": image_data}
13)
14
15results = response.json()
16print(f"Predicted font: {results[0]['label']} ({results[0]['score']:.2%})")1from transformers import pipeline
2
3# The model automatically handles preprocessing
4classifier = pipeline("image-classification", model="dchen0/font-classifier-v4")
5results = classifier("your_image.png")
6print(f"Predicted font: {results[0]['label']}")1from PIL import Image
2import torch
3from transformers import AutoImageProcessor
4from font_classifier_with_preprocessing import FontClassifierWithPreprocessing
5
6# Load model and processor
7model = FontClassifierWithPreprocessing.from_pretrained("dchen0/font-classifier-v4")
8processor = AutoImageProcessor.from_pretrained("dchen0/font-classifier-v4")
9
10# Process image (model handles pad_to_square automatically)
11image = Image.open("test.png")
12inputs = processor(images=image, return_tensors="pt")
13outputs = model(**inputs)font_classifier_with_preprocessing.py: Custom model class with built-in preprocessingDinov2ForImageClassification but overrides the forward pass to include:1def forward(self, pixel_values=None, labels=None, **kwargs):
2 # Automatic preprocessing happens here
3 processed_pixel_values = self.preprocess_images(pixel_values)
4 return super().forward(pixel_values=processed_pixel_values, labels=labels, **kwargs)