Update README.md

#2
by adirik - opened
Files changed (1) hide show
  1. README.md +27 -1
README.md CHANGED
@@ -59,7 +59,33 @@ This checkpoint of EfficientFormer-L1 was trained for 1000 epochs.
59
  Use the code below to get started with the model.
60
 
61
  ```python
62
- # A nice code snippet here that describes how to use the model...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  ```
64
  </how_to_start>
65
 
 
59
  Use the code below to get started with the model.
60
 
61
  ```python
62
+ import requests
63
+ import torch
64
+ from PIL import Image
65
+
66
+ from transformers import EfficientFormerImageProcessor, EfficientFormerForImageClassificationWithTeacher
67
+
68
+ # Load a COCO image of two cats to test the model
69
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg"
70
+ image = Image.open(requests.get(url, stream=True).raw)
71
+
72
+ # Load preprocessor and pretrained model
73
+ model_name = "huggingface/efficientformer-l1-300"
74
+ processor = EfficientFormerImageProcessor.from_pretrained(model_name)
75
+ model = EfficientFormerForImageClassificationWithTeacher.from_pretrained(model_name)
76
+
77
+ # Preprocess input image
78
+ inputs = processor(images=image, return_tensors="pt")
79
+
80
+ # Inference
81
+ with torch.no_grad():
82
+ outputs = model(**inputs)
83
+
84
+ # Print the top ImageNet1k class prediction
85
+ logits = outputs.logits
86
+ scores = torch.nn.functional.softmax(logits, dim=1)
87
+ top_pred_class = torch.argmax(scores, dim=1)
88
+ print(f"Predicted class: {top_pred_class}")
89
  ```
90
  </how_to_start>
91