Update README.md
This commit is contained in:
parent
f5104f67a0
commit
e8f8d2042c
|
@ -31,17 +31,17 @@ fine-tuned versions on a task that interests you.
|
||||||
Here is how to use this model to classify an image of the COCO 2017 dataset into one of the 1,000 ImageNet classes:
|
Here is how to use this model to classify an image of the COCO 2017 dataset into one of the 1,000 ImageNet classes:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from transformers import AutoFeatureExtractor, ResNetForImageClassification
|
from transformers import AutoImageProcessor, ResNetForImageClassification
|
||||||
import torch
|
import torch
|
||||||
from datasets import load_dataset
|
from datasets import load_dataset
|
||||||
|
|
||||||
dataset = load_dataset("huggingface/cats-image")
|
dataset = load_dataset("huggingface/cats-image")
|
||||||
image = dataset["test"]["image"][0]
|
image = dataset["test"]["image"][0]
|
||||||
|
|
||||||
feature_extractor = AutoFeatureExtractor.from_pretrained("microsoft/resnet-50")
|
processor = AutoImageProcessor.from_pretrained("microsoft/resnet-50")
|
||||||
model = ResNetForImageClassification.from_pretrained("microsoft/resnet-50")
|
model = ResNetForImageClassification.from_pretrained("microsoft/resnet-50")
|
||||||
|
|
||||||
inputs = feature_extractor(image, return_tensors="pt")
|
inputs = processor(image, return_tensors="pt")
|
||||||
|
|
||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
logits = model(**inputs).logits
|
logits = model(**inputs).logits
|
||||||
|
|
Loading…
Reference in New Issue