Instructions to use l45k/lenet with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use l45k/lenet with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="l45k/lenet", trust_remote_code=True) pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForImageClassification model = AutoModelForImageClassification.from_pretrained("l45k/lenet", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download preprocessor_resnet.py from l45k/lenet: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/l45k/lenet/resolve/main/preprocessor_resnet.py
- Command line
-
hf download hf://l45k/lenet/preprocessor_resnet.py
-
curl -L -o preprocessor_resnet.py https://huggingface.co/l45k/lenet/resolve/main/preprocessor_resnet.py
1.07 kB
| from transformers.image_utils import ImageInput | |
| from transformers import BaseImageProcessor, BatchFeature | |
| from torchvision.transforms import v2 | |
| import torch | |
| class ResNetProcessor(BaseImageProcessor): | |
| """ | |
| A custom processor for ResNet training | |
| """ | |
| model_input_names = ["pixel_values"] | |
| def __init__(self, **kwargs): | |
| super().__init__(**kwargs) | |
| def preprocess(self, images: ImageInput, return_tensors="pt", **kwargs) -> BatchFeature: | |
| """ | |
| Preprocess a batch of grayscale images. | |
| """ | |
| if not isinstance(images, list): | |
| images = [images] | |
| transform = v2.Compose([ | |
| v2.RandomResizedCrop(size=(224, 224), antialias=True), | |
| v2.RandomHorizontalFlip(p=0.5), | |
| v2.ToDtype(torch.float32, scale=True), | |
| v2.Normalize( | |
| mean=[0.485, 0.456, 0.406], | |
| std=[0.229, 0.224, 0.225] | |
| ), | |
| ]) | |
| data = {"pixel_values": transform(images)} | |
| return BatchFeature(data=data, tensor_type="pt") | |