resnet 50
microsoftIntroduction
ResNet-50 v1.5 is a convolutional neural network model pre-trained on the ImageNet-1k dataset for image classification tasks. It was introduced by He et al. in the paper "Deep Residual Learning for Image Recognition." This version of ResNet differs slightly from the original architecture to improve accuracy and performance.
Architecture
The ResNet model utilizes residual learning and skip connections, allowing for the training of deeper networks. ResNet-50 v1.5 includes modifications in its bottleneck blocks where downsampling occurs. Specifically, the stride of 2 is applied in the 3x3 convolution instead of the 1x1 convolution. This change enhances its accuracy by approximately 0.5% in top-1 classification but slightly reduces the processing speed by 5% in images per second.
Training
The ResNet-50 model is trained on the ImageNet-1k dataset, which consists of images at a resolution of 224x224. This extensive training enables the model to classify images into 1,000 different classes.
Guide: Running Locally
- Environment Setup: Ensure you have Python and PyTorch installed. Use a virtual environment to manage dependencies.
- Installation: Install the
transformers
anddatasets
libraries:pip install transformers datasets torch
- Load Dataset: Use the Hugging Face
datasets
library to load an image dataset. - Model and Processor: Initialize the model and image processor:
from transformers import AutoImageProcessor, ResNetForImageClassification import torch from datasets import load_dataset dataset = load_dataset("huggingface/cats-image") image = dataset["test"]["image"][0] processor = AutoImageProcessor.from_pretrained("microsoft/resnet-50") model = ResNetForImageClassification.from_pretrained("microsoft/resnet-50")
- Inference: Process the image and perform inference:
inputs = processor(image, return_tensors="pt") with torch.no_grad(): logits = model(**inputs).logits predicted_label = logits.argmax(-1).item() print(model.config.id2label[predicted_label])
- Cloud GPUs: For enhanced performance, consider using cloud GPUs from providers like AWS, GCP, or Azure.
License
The ResNet-50 model is released under the Apache 2.0 License, allowing for both personal and commercial use with proper attribution.