resnet 50
OWGIntroduction
The ResNet-50 model is a deep learning model from the "Deep Residual Learning for Image Recognition" paper. It is available on Hugging Face, utilizing ONNX for optimized performance.
Architecture
ResNet-50 is a residual neural network architecture designed to facilitate the training of deeper networks through the use of shortcut connections. These connections help in mitigating the vanishing gradient problem, allowing for more efficient training of deeper architectures.
Training
The ResNet-50 model was originally implemented and trained as described in the "Deep Residual Learning for Image Recognition" paper. Details of the original implementation can be found on the Hugging Face model page.
Guide: Running Locally
To run the ResNet-50 model locally, follow these steps:
-
Install Required Libraries:
pip install transformers onnxruntime datasets
-
Load Image:
from datasets import load_dataset dataset = load_dataset("huggingface/cats-image") image = dataset["test"]["image"][0]
-
Load Model and Feature Extractor:
from transformers import AutoFeatureExtractor from onnxruntime import InferenceSession feature_extractor = AutoFeatureExtractor.from_pretrained("microsoft/resnet-50") session = InferenceSession("onnx/model.onnx")
-
Prepare Inputs and Run Inference:
inputs = feature_extractor(image, return_tensors="np") outputs = session.run(output_names=["last_hidden_state"], input_feed=dict(inputs))
-
Classification with Logits:
- Use
onnx/model_cls.onnx
for classification to get logits:session = InferenceSession("onnx/model_cls.onnx") outputs = session.run(output_names=["logits"], input_feed=dict(inputs))
- Use
For improved performance, consider using a cloud GPU service such as AWS EC2, Google Cloud Platform, or Azure.
License
The ResNet-50 model on Hugging Face is distributed under the Apache 2.0 License. This allows for both personal and commercial use, modification, and distribution, provided that the original license is included with any substantial portions of the software.