Instructions to use leftthomas/resnet50 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use leftthomas/resnet50 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="leftthomas/resnet50", trust_remote_code=True) 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("leftthomas/resnet50", trust_remote_code=True) model = AutoModelForImageClassification.from_pretrained("leftthomas/resnet50", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
| from transformers import PreTrainedModel | |
| from torchvision.models.resnet import ResNet, Bottleneck, BasicBlock | |
| import torch.nn.functional as F | |
| from .configuration_resnet import ResnetConfig | |
| BLOCK_MAPPING = {'basic': BasicBlock, 'bottleneck': Bottleneck} | |
| class ResnetModelForImageClassification(PreTrainedModel): | |
| config_class = ResnetConfig | |
| def __init__(self, config): | |
| super().__init__(config) | |
| block_layer = BLOCK_MAPPING[config.block_type] | |
| self.model = ResNet(block_layer, config.layers, config.num_classes) | |
| def forward(self, tensor, labels=None): | |
| logits = self.model(tensor) | |
| if labels is not None: | |
| loss = F.cross_entropy(logits, labels) | |
| return {'loss': loss, 'logits': logits} | |
| return {'logits': logits} | |