autonomous019 commited on
Commit
d66d160
1 Parent(s): c4f0dda

adding code

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import ViTConfig, ViTForImageClassification
2
+
3
+ # option 1: load with randomly initialized weights (train from scratch)
4
+
5
+ config = ViTConfig(num_hidden_layers=12, hidden_size=768)
6
+ model = ViTForImageClassification(config)
7
+
8
+ print(config)
9
+
10
+ from transformers import ViTFeatureExtractor
11
+
12
+ feature_extractor = ViTFeatureExtractor()
13
+
14
+ # or, to load one that corresponds to a checkpoint on the hub:
15
+ feature_extractor = ViTFeatureExtractor.from_pretrained("google/vit-base-patch16-224")
16
+
17
+ from PIL import Image
18
+ import requests
19
+
20
+ url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
21
+ image = Image.open(requests.get(url, stream=True).raw)
22
+ image.save("cats.png")
23
+ image
24
+
25
+