adamdad commited on
Commit
a157fe8
·
verified ·
1 Parent(s): 8a051b0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +34 -0
README.md CHANGED
@@ -6,3 +6,37 @@ library_name: timm
6
  license: apache-2.0
7
  ---
8
  # Model card for kat_tiny_patch16_224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  license: apache-2.0
7
  ---
8
  # Model card for kat_tiny_patch16_224
9
+
10
+ ## Usage
11
+
12
+ ```python
13
+ from urllib.request import urlopen
14
+ from PIL import Image
15
+ import timm
16
+ import torch
17
+ import katransformer
18
+
19
+ img = Image.open(urlopen(
20
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
21
+ ))
22
+
23
+ # Move model to CUDA
24
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
25
+
26
+ model = timm.create_model('hf_hub:adamdad/kat_tiny_patch16_224', pretrained=True)
27
+ model = model.to(device)
28
+ model = model.eval()
29
+
30
+
31
+
32
+ # get model specific transforms (normalization, resize)
33
+ data_config = timm.data.resolve_model_data_config(model)
34
+ transforms = timm.data.create_transform(**data_config, is_training=False)
35
+
36
+ output = model(transforms(img).unsqueeze(0).to(device)) # unsqueeze single image into batch of 1
37
+
38
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
39
+ print(top5_probabilities)
40
+ print(top5_class_indices)
41
+
42
+ ```